aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath9k/beacon.c
Commit message (Collapse)AuthorAge
* atheros: put atheros wireless drivers into ath/Luis R. Rodriguez2009-04-22
| | | | | Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Avoid unneeded castsSujith2009-04-22
| | | | | | | | Change the void pointer to struct sk_buff and access bf_mpdu directly, removing all casts in the process. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Cleanup debug messagesSujith2009-04-22
| | | | | | | | Clean debug messages to use appropriate levels, remove useless messages, and trim the number of debug levels. Signed-off-by: John W. Linville <linville@tuxdriver.com>
* Add mesh point functionality to ath9kPat Erley2009-03-27
| | | | | | | | This patch enables mesh point operation for ath9k. Tested with b43, ath9k, rt2500usb, and ath5k as peers. Signed-off-by: Pat Erley <pat-lkml@erley.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Update copyright in all the filesSujith2009-03-27
| | | | | | | How time flies. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Add support for multiple virtual AP interfacesJouni Malinen2009-03-27
| | | | | | | | | This patch fixes the TSF offset calculation for staggered Beacon frames and sets ATH_BCBUF back to the earlier value 4 to enable multi-BSS configurations of up to four BSSes. Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Virtual wiphy pause/unpause functionalityJouni Malinen2009-03-05
| | | | | | | | | | Allow virtual wiphys to be paused/unpaused to allow off-channel operations. Pause will stop all TX queues for the wiphy and move the STA into power save mode if in managed mode. Unpause wakes up the TX queues and notifies the AP that the STA woke up if in managed mode. Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Add support for multiple secondary virtual wiphysJouni Malinen2009-03-05
| | | | | | | | | | The new struct ath_softc::sec_wiphy array is used to store information about virtual wiphys and select which wiphy is used in calls to mac80211. Each virtual wiphy will be assigned a different MAC address based on the virtual wiphy index. Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Cleanup multiple VIF processingJouni Malinen2009-03-05
| | | | | | | | | | | Replace the internal sc_vaps array and index values by using vif pointer from mac80211. Allow multiple VIPs to be registered. Though, number of beaconing VIFs is still limited by ATH_BCBUF (currently 1). Multiple virtual STAs support is not yet complete, but at least the data structures should now be able to handle this. Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Handle TSF properly for AP modeSujith2009-03-05
| | | | | | | | | | | | The TSF has to be reset only once, upon bringing the interface up in AP mode. For any beacon reconfigure calls after that, resetting the TSF results in incorrect beacon generation. The only exception is a change in the beacon interval, which is indicated to the driver by mac80211 through IEEE80211_CONF_CHANGE_BEACON_INTERVAL, handle this properly. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Split beacon configuration into mode specific routinesSujith2009-03-05
| | | | | | | This makes the code easier to understand. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Cleanup beacon stuck processingSujith2009-03-05
| | | | | | | | | We never use SC_OP_NO_RESET, it is not configurable at all. Remove all code that deals with this flag and make beacon stuck processing simple. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Scrub beacon.cSujith2009-03-05
| | | | | | | | Remove useless comments, fix indentation. Also, remove all occurrences of ASSERT(vif) which are not needed. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Don't reset TSF after scanning automaticallyAlina Friedrichsen2009-02-27
| | | | | | | | | | | | | Reset automatically the TSF on re-enabling beaconing after scanning in IBSS mode causes several problems. For example a new created IBSS network can't age before an other node has joined, because scans are done automatically in that case. And several other strange bugs more... The TSF reset is done manually in the higher level mac80211 code in the cases were it's needed, so we don't need to do it here. Signed-off-by: Alina Friedrichsen <x-alina@gmx.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Enable TSF Out of Range InterruptSujith2009-02-27
| | | | | | | | This patch lays the groundwork for handling TSF Out of Range interrupt, which will be used for power save later on. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Remove all the useless ah_ variable prefixesSujith2009-02-13
| | | | | Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Merge ath_hal and ath_hal_5416 structuresSujith2009-02-13
| | | | | | | | Finally, merge these structures and have a single HW specific data structure. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Remove all the sc_ prefixesSujith2009-02-13
| | | | | | | | This patch removes the useless sc_ prefixes for all variables. Also, refer to interfaces as VIFs and not as VAPs anymore. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Header file cleanupSujith2009-02-13
| | | | | | | Split the core header files into manageable pieces. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Merge queue draining functionsSujith2009-01-29
| | | | | | | | | The TX queue draining routines have confusing names, rename them approprately and merge ath_drain_txdataq() with ath_drain_all_txq(). Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: convert to use bus-agnostic DMA routinesGabor Juhos2009-01-29
| | | | | | | | | | | Convert to use bus-agnostic DMA routines to make it usable on AHB bus as well. Changes-licensed-under: ISC Signed-off-by: Gabor Juhos <juhosg@openwrt.org> Signed-off-by: Imre Kaloz <kaloz@openwrt.org> Tested-by: Pavel Roskin <proski@gnu.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: convert to struct deviceGabor Juhos2009-01-29
| | | | | | | | | | | | Convert 'struct pci_dev' to 'struct device' to make it usable on the AHB bus as well. Changes-licensed-under: ISC Signed-off-by: Gabor Juhos <juhosg@openwrt.org> Signed-off-by: Imre Kaloz <kaloz@openwrt.org> Tested-by: Pavel Roskin <proski@gnu.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Refactor struct ath_softcSujith2008-12-12
| | | | | | | | Split ath_softc into smaller structures for rx, tx and beacon handling. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Maintain rate table choice after associationSujith2008-12-12
| | | | | | | | | | A scan run after association would change sc_curmode which is used to get the current rate table. This patch fixes it by removing sc_curmode and setting the rate table in usage in cur_rate_table on association. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Free Beacon skbs in AP modeJouni Malinen2008-12-12
| | | | | | | | | Fix a memory leak where AP mode did not free transmitted Beacon frame skbs. Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Acked-by: Pat Erley <pat-lkml@erley.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Check for pci_map_single() errorsLuis R. Rodriguez2008-12-05
| | | | | | | | pci_map_single() can fail so detect those errors with pci_dma_mapping_error() and deal with them accordingly. Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Replace ath9k_opmode with nl80211_iftypeColin McCabe2008-12-05
| | | | | | | | This patch kills ath9k's ath9k_opmode enum by replacing it with nl80211_iftype. Signed-off-by: Colin McCabe <colin@cozybit.com> Signed-off-by: Andrey Yurovsky <andrey@cozybit.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Add a debugfs file for dumping DMA statusSujith2008-12-05
| | | | | | | | Debugfs file location: ath9k/<wiphy>/dma Contains values in DMA debug registers. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Use cleaner debug masksSujith2008-12-05
| | | | | | | | Remove all the useless __func__ prefixes in debug messages, and replace the DPRINTF macro with a function. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* Merge branch 'master' of ↵David S. Miller2008-11-27
|\ | | | | | | | | | | | | | | | | | | | | master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6 Conflicts: drivers/net/hp-plus.c drivers/net/wireless/ath5k/base.c drivers/net/wireless/ath9k/recv.c net/wireless/reg.c
| * ath9k: Fix SW-IOMMU bounce buffer starvationLuis R. Rodriguez2008-11-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This should fix the SW-IOMMU bounce buffer starvation seen ok kernel.org bugzilla 11811: http://bugzilla.kernel.org/show_bug.cgi?id=11811 Users on MacBook Pro 3.1/MacBook v2 would see something like: DMA: Out of SW-IOMMU space for 4224 bytes at device 0000:0b:00.0 Unfortunately its only easy to trigger on MacBook Pro 3.1/MacBook v2 so far so its difficult to debug (even with swiotlb=force). We were pci_unmap_single()'ing less bytes than what we called for with pci_map_single() and as such we were starving the swiotlb from its 64MB amount of bounce buffers. We remain consistent and now always use sc->rxbufsize for RX. While at it we update the beacon DMA maps as well to only use the data portion of the skb, previous to this we were pci_map_single()'ing more data for beaconing than what we tell the hardware it can use, therefore pushing more iotlb abuse. Still not sure why this is so easily triggerable on MacBook Pro 3.1, it may be the hardware configuration tends to use more memory > 3GB mark for DMA. Signed-off-by: Maciej Zenczykowski <zenczykowski@gmail.com> Signed-off-by: Bennyam Malavazi <Bennyam.Malavazi@atheros.com> Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* | ath9k: Code scrubSujith2008-11-26
| | | | | | | | | | | | | | | | | | | | Merge core.c and base.c Remove Antenna Diversity (unused now). Remove unused chainmask handling code. Comment, indentation scrub. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* | ath9k: Remove ath9k_rate_tableSujith2008-11-26
| | | | | | | | | | | | | | | | Maintaining two sets of rate tables is redundant, remove one and use struct ath_rate_table exclusively. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* | ath9k: Revamp VAP managementSujith2008-11-10
| | | | | | | | | | | | | | | | | | Remove the internal VAP management routines and embed ath_vap in mac80211's driver private area provided in ieee80211_vif. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* | ath9k: Revamp transmit control blockSujith2008-11-10
|/ | | | | | | | Use the ath_buf instance associated with each tx frame directly and remove all redundant information in ath_tx_control. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: kill ath9k's memzero() and use memset() insteadLuis R. Rodriguez2008-10-06
| | | | | | | | Part of the cleanup on ath9k -- this was also causing some annoying compile time warnings. Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Fix nexttbtt calculationSujith2008-09-24
| | | | | | | | | nexttbtt has to be obtained from the timestamp of the beacon obtained from mac80211. Fix this. And <asm/unaligned.h> is not needed anymore. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Whitespace cleanupSujith2008-09-24
| | | | | | | Also, remove comments that are not relevant anymore. Signed-off-by: Sujith <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Remove more dead codeSujith2008-08-29
| | | | | Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Use mac80211 for multicast power save bufferingJouni Malinen2008-08-29
| | | | | | | | | | Replace the internal ath9k implementation of multicast/broadcast frame power save buffering (AP mode) in ath9k with use of mac80211 ieee80211_get_buffered_bc() mechanism. This removes quite a bit of duplicated functionality and simplifies the driver part. Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Add IEEE80211_HW_RX_INCLUDES_FCS to hw flagsSujith2008-08-29
| | | | | | | | Don't trim the FCS before passing the frame to mac80211, move TSF_TO_TU to core.h and delete more unused macros. Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Miscellaneous fixesSujith2008-08-29
| | | | | | | | This patch removes ath_vap_listen() and dma wrapper macros. Also, Inline abuse is cleaned up and a few typos are fixed. Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Assign seq# when mac80211 requests thisJouni Malinen2008-08-29
| | | | | | | | | | | Use TX control flag IEEE80211_TX_CTL_ASSIGN_SEQ as a request to update the seq# for the frames. This will likely require some further cleanup to get seq# correctly for Beacons vs. other frames and also potentially for multiple BSSes. Anyway, this is better than ending up sending out most frames with seq# 0. Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Updated Beacon generation to use mac80211-styleJouni Malinen2008-08-29
| | | | | | | | | | | | | This change moves ath9k to use mac80211-generated Beacon frames instead of trying to allocate a single Beacon frame and then update it. In addition, the remaining ath_skb_{map,unmap}_single() wrapper calls are replaced with direct pci_{map,unmap}_single() calls in beacon.c. Power save buffering for multicast/broadcast frames is not yet converted to use mac80211-style (frames to be buffered inside mac80211, not in driver). Signed-off-by: Jouni Malinen <jouni.malinen@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Trim struct ath_softcSujith2008-08-29
| | | | | | | | Add sc_rxflush and sc_noreset as bitfields to sc_flags. Remove a few variables and function prototypes that are unused. Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Use bitfields for sc operationsSujith2008-08-29
| | | | | Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Use a single opmode variableSujith2008-08-29
| | | | | | | | ah_opmode and sc_opmode are redundant. This patch removes sc_opmode. Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Merge reset functionsSujith2008-08-29
| | | | | Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Revamp wireless mode usageSujith2008-08-07
| | | | | | | | | Use a single enum for managing modes, store supported modes by the HW in a bitmask. Register legacy rates with mac80211 only at init. Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
* ath9k: Remove redundant data structure ath9k_txq_infoSujith2008-08-07
| | | | | | | | | Use ath9k_tx_queue_info which contains the same elements, and merge get/set functions of tx queue properties. Also, fix whitespace damage in struct ath_softc. Signed-off-by: Sujith Manoharan <Sujith.Manoharan@atheros.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
kwd">snd_sb_csp_stop(struct snd_sb_csp * p); static int snd_sb_csp_pause(struct snd_sb_csp * p); static int snd_sb_csp_restart(struct snd_sb_csp * p); static int snd_sb_qsound_build(struct snd_sb_csp * p); static void snd_sb_qsound_destroy(struct snd_sb_csp * p); static int snd_sb_csp_qsound_transfer(struct snd_sb_csp * p); static int init_proc_entry(struct snd_sb_csp * p, int device); static void info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer); /* * Detect CSP chip and create a new instance */ int snd_sb_csp_new(struct snd_sb *chip, int device, struct snd_hwdep ** rhwdep) { struct snd_sb_csp *p; int uninitialized_var(version); int err; struct snd_hwdep *hw; if (rhwdep) *rhwdep = NULL; if (csp_detect(chip, &version)) return -ENODEV; if ((err = snd_hwdep_new(chip->card, "SB16-CSP", device, &hw)) < 0) return err; if ((p = kzalloc(sizeof(*p), GFP_KERNEL)) == NULL) { snd_device_free(chip->card, hw); return -ENOMEM; } p->chip = chip; p->version = version; /* CSP operators */ p->ops.csp_use = snd_sb_csp_use; p->ops.csp_unuse = snd_sb_csp_unuse; p->ops.csp_autoload = snd_sb_csp_autoload; p->ops.csp_start = snd_sb_csp_start; p->ops.csp_stop = snd_sb_csp_stop; p->ops.csp_qsound_transfer = snd_sb_csp_qsound_transfer; mutex_init(&p->access_mutex); sprintf(hw->name, "CSP v%d.%d", (version >> 4), (version & 0x0f)); hw->iface = SNDRV_HWDEP_IFACE_SB16CSP; hw->private_data = p; hw->private_free = snd_sb_csp_free; /* operators - only write/ioctl */ hw->ops.open = snd_sb_csp_open; hw->ops.ioctl = snd_sb_csp_ioctl; hw->ops.release = snd_sb_csp_release; /* create a proc entry */ init_proc_entry(p, device); if (rhwdep) *rhwdep = hw; return 0; } /* * free_private for hwdep instance */ static void snd_sb_csp_free(struct snd_hwdep *hwdep) { int i; struct snd_sb_csp *p = hwdep->private_data; if (p) { if (p->running & SNDRV_SB_CSP_ST_RUNNING) snd_sb_csp_stop(p); for (i = 0; i < ARRAY_SIZE(p->csp_programs); ++i) release_firmware(p->csp_programs[i]); kfree(p); } } /* ------------------------------ */ /* * open the device exclusively */ static int snd_sb_csp_open(struct snd_hwdep * hw, struct file *file) { struct snd_sb_csp *p = hw->private_data; return (snd_sb_csp_use(p)); } /* * ioctl for hwdep device: */ static int snd_sb_csp_ioctl(struct snd_hwdep * hw, struct file *file, unsigned int cmd, unsigned long arg) { struct snd_sb_csp *p = hw->private_data; struct snd_sb_csp_info info; struct snd_sb_csp_start start_info; int err; if (snd_BUG_ON(!p)) return -EINVAL; if (snd_sb_csp_check_version(p)) return -ENODEV; switch (cmd) { /* get information */ case SNDRV_SB_CSP_IOCTL_INFO: *info.codec_name = *p->codec_name; info.func_nr = p->func_nr; info.acc_format = p->acc_format; info.acc_channels = p->acc_channels; info.acc_width = p->acc_width; info.acc_rates = p->acc_rates; info.csp_mode = p->mode; info.run_channels = p->run_channels; info.run_width = p->run_width; info.version = p->version; info.state = p->running; if (copy_to_user((void __user *)arg, &info, sizeof(info))) err = -EFAULT; else err = 0; break; /* load CSP microcode */ case SNDRV_SB_CSP_IOCTL_LOAD_CODE: err = (p->running & SNDRV_SB_CSP_ST_RUNNING ? -EBUSY : snd_sb_csp_riff_load(p, (struct snd_sb_csp_microcode __user *) arg)); break; case SNDRV_SB_CSP_IOCTL_UNLOAD_CODE: err = (p->running & SNDRV_SB_CSP_ST_RUNNING ? -EBUSY : snd_sb_csp_unload(p)); break; /* change CSP running state */ case SNDRV_SB_CSP_IOCTL_START: if (copy_from_user(&start_info, (void __user *) arg, sizeof(start_info))) err = -EFAULT; else err = snd_sb_csp_start(p, start_info.sample_width, start_info.channels); break; case SNDRV_SB_CSP_IOCTL_STOP: err = snd_sb_csp_stop(p); break; case SNDRV_SB_CSP_IOCTL_PAUSE: err = snd_sb_csp_pause(p); break; case SNDRV_SB_CSP_IOCTL_RESTART: err = snd_sb_csp_restart(p); break; default: err = -ENOTTY; break; } return err; } /* * close the device */ static int snd_sb_csp_release(struct snd_hwdep * hw, struct file *file) { struct snd_sb_csp *p = hw->private_data; return (snd_sb_csp_unuse(p)); } /* ------------------------------ */ /* * acquire device */ static int snd_sb_csp_use(struct snd_sb_csp * p) { mutex_lock(&p->access_mutex); if (p->used) { mutex_unlock(&p->access_mutex); return -EAGAIN; } p->used++; mutex_unlock(&p->access_mutex); return 0; } /* * release device */ static int snd_sb_csp_unuse(struct snd_sb_csp * p) { mutex_lock(&p->access_mutex); p->used--; mutex_unlock(&p->access_mutex); return 0; } /* * load microcode via ioctl: * code is user-space pointer */ static int snd_sb_csp_riff_load(struct snd_sb_csp * p, struct snd_sb_csp_microcode __user * mcode) { struct snd_sb_csp_mc_header info; unsigned char __user *data_ptr; unsigned char __user *data_end; unsigned short func_nr = 0; struct riff_header file_h, item_h, code_h; __u32 item_type; struct desc_header funcdesc_h; unsigned long flags; int err; if (copy_from_user(&info, mcode, sizeof(info))) return -EFAULT; data_ptr = mcode->data; if (copy_from_user(&file_h, data_ptr, sizeof(file_h))) return -EFAULT; if ((file_h.name != RIFF_HEADER) || (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) { snd_printd("%s: Invalid RIFF header\n", __func__); return -EINVAL; } data_ptr += sizeof(file_h); data_end = data_ptr + le32_to_cpu(file_h.len); if (copy_from_user(&item_type, data_ptr, sizeof(item_type))) return -EFAULT; if (item_type != CSP__HEADER) { snd_printd("%s: Invalid RIFF file type\n", __func__); return -EINVAL; } data_ptr += sizeof (item_type); for (; data_ptr < data_end; data_ptr += le32_to_cpu(item_h.len)) { if (copy_from_user(&item_h, data_ptr, sizeof(item_h))) return -EFAULT; data_ptr += sizeof(item_h); if (item_h.name != LIST_HEADER) continue; if (copy_from_user(&item_type, data_ptr, sizeof(item_type))) return -EFAULT; switch (item_type) { case FUNC_HEADER: if (copy_from_user(&funcdesc_h, data_ptr + sizeof(item_type), sizeof(funcdesc_h))) return -EFAULT; func_nr = le16_to_cpu(funcdesc_h.func_nr); break; case CODE_HEADER: if (func_nr != info.func_req) break; /* not required function, try next */ data_ptr += sizeof(item_type); /* destroy QSound mixer element */ if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) { snd_sb_qsound_destroy(p); } /* Clear all flags */ p->running = 0; p->mode = 0; /* load microcode blocks */ for (;;) { if (data_ptr >= data_end) return -EINVAL; if (copy_from_user(&code_h, data_ptr, sizeof(code_h))) return -EFAULT; /* init microcode blocks */ if (code_h.name != INIT_HEADER) break; data_ptr += sizeof(code_h); err = snd_sb_csp_load_user(p, data_ptr, le32_to_cpu(code_h.len), SNDRV_SB_CSP_LOAD_INITBLOCK); if (err) return err; data_ptr += le32_to_cpu(code_h.len); } /* main microcode block */ if (copy_from_user(&code_h, data_ptr, sizeof(code_h))) return -EFAULT; if (code_h.name != MAIN_HEADER) { snd_printd("%s: Missing 'main' microcode\n", __func__); return -EINVAL; } data_ptr += sizeof(code_h); err = snd_sb_csp_load_user(p, data_ptr, le32_to_cpu(code_h.len), 0); if (err) return err; /* fill in codec header */ strlcpy(p->codec_name, info.codec_name, sizeof(p->codec_name)); p->func_nr = func_nr; p->mode = le16_to_cpu(funcdesc_h.flags_play_rec); switch (le16_to_cpu(funcdesc_h.VOC_type)) { case 0x0001: /* QSound decoder */ if (le16_to_cpu(funcdesc_h.flags_play_rec) == SNDRV_SB_CSP_MODE_DSP_WRITE) { if (snd_sb_qsound_build(p) == 0) /* set QSound flag and clear all other mode flags */ p->mode = SNDRV_SB_CSP_MODE_QSOUND; } p->acc_format = 0; break; case 0x0006: /* A Law codec */ p->acc_format = SNDRV_PCM_FMTBIT_A_LAW; break; case 0x0007: /* Mu Law codec */ p->acc_format = SNDRV_PCM_FMTBIT_MU_LAW; break; case 0x0011: /* what Creative thinks is IMA ADPCM codec */ case 0x0200: /* Creative ADPCM codec */ p->acc_format = SNDRV_PCM_FMTBIT_IMA_ADPCM; break; case 201: /* Text 2 Speech decoder */ /* TODO: Text2Speech handling routines */ p->acc_format = 0; break; case 0x0202: /* Fast Speech 8 codec */ case 0x0203: /* Fast Speech 10 codec */ p->acc_format = SNDRV_PCM_FMTBIT_SPECIAL; break; default: /* other codecs are unsupported */ p->acc_format = p->acc_width = p->acc_rates = 0; p->mode = 0; snd_printd("%s: Unsupported CSP codec type: 0x%04x\n", __func__, le16_to_cpu(funcdesc_h.VOC_type)); return -EINVAL; } p->acc_channels = le16_to_cpu(funcdesc_h.flags_stereo_mono); p->acc_width = le16_to_cpu(funcdesc_h.flags_16bit_8bit); p->acc_rates = le16_to_cpu(funcdesc_h.flags_rates); /* Decouple CSP from IRQ and DMAREQ lines */ spin_lock_irqsave(&p->chip->reg_lock, flags); set_mode_register(p->chip, 0xfc); set_mode_register(p->chip, 0x00); spin_unlock_irqrestore(&p->chip->reg_lock, flags); /* finished loading successfully */ p->running = SNDRV_SB_CSP_ST_LOADED; /* set LOADED flag */ return 0; } } snd_printd("%s: Function #%d not found\n", __func__, info.func_req); return -EINVAL; } /* * unload CSP microcode */ static int snd_sb_csp_unload(struct snd_sb_csp * p) { if (p->running & SNDRV_SB_CSP_ST_RUNNING) return -EBUSY; if (!(p->running & SNDRV_SB_CSP_ST_LOADED)) return -ENXIO; /* clear supported formats */ p->acc_format = 0; p->acc_channels = p->acc_width = p->acc_rates = 0; /* destroy QSound mixer element */ if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) { snd_sb_qsound_destroy(p); } /* clear all flags */ p->running = 0; p->mode = 0; return 0; } /* * send command sequence to DSP */ static inline int command_seq(struct snd_sb *chip, const unsigned char *seq, int size) { int i; for (i = 0; i < size; i++) { if (!snd_sbdsp_command(chip, seq[i])) return -EIO; } return 0; } /* * set CSP codec parameter */ static int set_codec_parameter(struct snd_sb *chip, unsigned char par, unsigned char val) { unsigned char dsp_cmd[3]; dsp_cmd[0] = 0x05; /* CSP set codec parameter */ dsp_cmd[1] = val; /* Parameter value */ dsp_cmd[2] = par; /* Parameter */ command_seq(chip, dsp_cmd, 3); snd_sbdsp_command(chip, 0x03); /* DSP read? */ if (snd_sbdsp_get_byte(chip) != par) return -EIO; return 0; } /* * set CSP register */ static int set_register(struct snd_sb *chip, unsigned char reg, unsigned char val) { unsigned char dsp_cmd[3]; dsp_cmd[0] = 0x0e; /* CSP set register */ dsp_cmd[1] = reg; /* CSP Register */ dsp_cmd[2] = val; /* value */ return command_seq(chip, dsp_cmd, 3); } /* * read CSP register * return < 0 -> error */ static int read_register(struct snd_sb *chip, unsigned char reg) { unsigned char dsp_cmd[2]; dsp_cmd[0] = 0x0f; /* CSP read register */ dsp_cmd[1] = reg; /* CSP Register */ command_seq(chip, dsp_cmd, 2); return snd_sbdsp_get_byte(chip); /* Read DSP value */ } /* * set CSP mode register */ static int set_mode_register(struct snd_sb *chip, unsigned char mode) { unsigned char dsp_cmd[2]; dsp_cmd[0] = 0x04; /* CSP set mode register */ dsp_cmd[1] = mode; /* mode */ return command_seq(chip, dsp_cmd, 2); } /* * Detect CSP * return 0 if CSP exists. */ static int csp_detect(struct snd_sb *chip, int *version) { unsigned char csp_test1, csp_test2; unsigned long flags; int result = -ENODEV; spin_lock_irqsave(&chip->reg_lock, flags); set_codec_parameter(chip, 0x00, 0x00); set_mode_register(chip, 0xfc); /* 0xfc = ?? */ csp_test1 = read_register(chip, 0x83); set_register(chip, 0x83, ~csp_test1); csp_test2 = read_register(chip, 0x83); if (csp_test2 != (csp_test1 ^ 0xff)) goto __fail; set_register(chip, 0x83, csp_test1); csp_test2 = read_register(chip, 0x83); if (csp_test2 != csp_test1) goto __fail; set_mode_register(chip, 0x00); /* 0x00 = ? */ *version = get_version(chip); snd_sbdsp_reset(chip); /* reset DSP after getversion! */ if (*version >= 0x10 && *version <= 0x1f) result = 0; /* valid version id */ __fail: spin_unlock_irqrestore(&chip->reg_lock, flags); return result; } /* * get CSP version number */ static int get_version(struct snd_sb *chip) { unsigned char dsp_cmd[2]; dsp_cmd[0] = 0x08; /* SB_DSP_!something! */ dsp_cmd[1] = 0x03; /* get chip version id? */ command_seq(chip, dsp_cmd, 2); return (snd_sbdsp_get_byte(chip)); } /* * check if the CSP version is valid */ static int snd_sb_csp_check_version(struct snd_sb_csp * p) { if (p->version < 0x10 || p->version > 0x1f) { snd_printd("%s: Invalid CSP version: 0x%x\n", __func__, p->version); return 1; } return 0; } /* * download microcode to CSP (microcode should have one "main" block). */ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int size, int load_flags) { int status, i; int err; int result = -EIO; unsigned long flags; spin_lock_irqsave(&p->chip->reg_lock, flags); snd_sbdsp_command(p->chip, 0x01); /* CSP download command */ if (snd_sbdsp_get_byte(p->chip)) { snd_printd("%s: Download command failed\n", __func__); goto __fail; } /* Send CSP low byte (size - 1) */ snd_sbdsp_command(p->chip, (unsigned char)(size - 1)); /* Send high byte */ snd_sbdsp_command(p->chip, (unsigned char)((size - 1) >> 8)); /* send microcode sequence */ /* load from kernel space */ while (size--) { if (!snd_sbdsp_command(p->chip, *buf++)) goto __fail; } if (snd_sbdsp_get_byte(p->chip)) goto __fail; if (load_flags & SNDRV_SB_CSP_LOAD_INITBLOCK) { i = 0; /* some codecs (FastSpeech) take some time to initialize */ while (1) { snd_sbdsp_command(p->chip, 0x03); status = snd_sbdsp_get_byte(p->chip); if (status == 0x55 || ++i >= 10) break; udelay (10); } if (status != 0x55) { snd_printd("%s: Microcode initialization failed\n", __func__); goto __fail; } } else { /* * Read mixer register SB_DSP4_DMASETUP after loading 'main' code. * Start CSP chip if no 16bit DMA channel is set - some kind * of autorun or perhaps a bugfix? */ spin_lock(&p->chip->mixer_lock); status = snd_sbmixer_read(p->chip, SB_DSP4_DMASETUP); spin_unlock(&p->chip->mixer_lock); if (!(status & (SB_DMASETUP_DMA7 | SB_DMASETUP_DMA6 | SB_DMASETUP_DMA5))) { err = (set_codec_parameter(p->chip, 0xaa, 0x00) || set_codec_parameter(p->chip, 0xff, 0x00)); snd_sbdsp_reset(p->chip); /* really! */ if (err) goto __fail; set_mode_register(p->chip, 0xc0); /* c0 = STOP */ set_mode_register(p->chip, 0x70); /* 70 = RUN */ } } result = 0; __fail: spin_unlock_irqrestore(&p->chip->reg_lock, flags); return result; } static int snd_sb_csp_load_user(struct snd_sb_csp * p, const unsigned char __user *buf, int size, int load_flags) { int err; unsigned char *kbuf; kbuf = memdup_user(buf, size); if (IS_ERR(kbuf)) return PTR_ERR(kbuf); err = snd_sb_csp_load(p, kbuf, size, load_flags); kfree(kbuf); return err; } static int snd_sb_csp_firmware_load(struct snd_sb_csp *p, int index, int flags) { static const char *const names[] = { "sb16/mulaw_main.csp", "sb16/alaw_main.csp", "sb16/ima_adpcm_init.csp", "sb16/ima_adpcm_playback.csp", "sb16/ima_adpcm_capture.csp", }; const struct firmware *program; BUILD_BUG_ON(ARRAY_SIZE(names) != CSP_PROGRAM_COUNT); program = p->csp_programs[index]; if (!program) { int err = request_firmware(&program, names[index], p->chip->card->dev); if (err < 0) return err; p->csp_programs[index] = program; } return snd_sb_csp_load(p, program->data, program->size, flags); } /* * autoload hardware codec if necessary * return 0 if CSP is loaded and ready to run (p->running != 0) */ static int snd_sb_csp_autoload(struct snd_sb_csp * p, int pcm_sfmt, int play_rec_mode) { unsigned long flags; int err = 0; /* if CSP is running or manually loaded then exit */ if (p->running & (SNDRV_SB_CSP_ST_RUNNING | SNDRV_SB_CSP_ST_LOADED)) return -EBUSY; /* autoload microcode only if requested hardware codec is not already loaded */ if (((1 << pcm_sfmt) & p->acc_format) && (play_rec_mode & p->mode)) { p->running = SNDRV_SB_CSP_ST_AUTO; } else { switch (pcm_sfmt) { case SNDRV_PCM_FORMAT_MU_LAW: err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_MULAW, 0); p->acc_format = SNDRV_PCM_FMTBIT_MU_LAW; p->mode = SNDRV_SB_CSP_MODE_DSP_READ | SNDRV_SB_CSP_MODE_DSP_WRITE; break; case SNDRV_PCM_FORMAT_A_LAW: err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_ALAW, 0); p->acc_format = SNDRV_PCM_FMTBIT_A_LAW; p->mode = SNDRV_SB_CSP_MODE_DSP_READ | SNDRV_SB_CSP_MODE_DSP_WRITE; break; case SNDRV_PCM_FORMAT_IMA_ADPCM: err = snd_sb_csp_firmware_load(p, CSP_PROGRAM_ADPCM_INIT, SNDRV_SB_CSP_LOAD_INITBLOCK); if (err) break; if (play_rec_mode == SNDRV_SB_CSP_MODE_DSP_WRITE) { err = snd_sb_csp_firmware_load (p, CSP_PROGRAM_ADPCM_PLAYBACK, 0); p->mode = SNDRV_SB_CSP_MODE_DSP_WRITE; } else { err = snd_sb_csp_firmware_load (p, CSP_PROGRAM_ADPCM_CAPTURE, 0); p->mode = SNDRV_SB_CSP_MODE_DSP_READ; } p->acc_format = SNDRV_PCM_FMTBIT_IMA_ADPCM; break; default: /* Decouple CSP from IRQ and DMAREQ lines */ if (p->running & SNDRV_SB_CSP_ST_AUTO) { spin_lock_irqsave(&p->chip->reg_lock, flags); set_mode_register(p->chip, 0xfc); set_mode_register(p->chip, 0x00); spin_unlock_irqrestore(&p->chip->reg_lock, flags); p->running = 0; /* clear autoloaded flag */ } return -EINVAL; } if (err) { p->acc_format = 0; p->acc_channels = p->acc_width = p->acc_rates = 0; p->running = 0; /* clear autoloaded flag */ p->mode = 0; return (err); } else { p->running = SNDRV_SB_CSP_ST_AUTO; /* set autoloaded flag */ p->acc_width = SNDRV_SB_CSP_SAMPLE_16BIT; /* only 16 bit data */ p->acc_channels = SNDRV_SB_CSP_MONO | SNDRV_SB_CSP_STEREO; p->acc_rates = SNDRV_SB_CSP_RATE_ALL; /* HW codecs accept all rates */ } } return (p->running & SNDRV_SB_CSP_ST_AUTO) ? 0 : -ENXIO; } /* * start CSP */ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channels) { unsigned char s_type; /* sample type */ unsigned char mixL, mixR; int result = -EIO; unsigned long flags; if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) { snd_printd("%s: Microcode not loaded\n", __func__); return -ENXIO; } if (p->running & SNDRV_SB_CSP_ST_RUNNING) { snd_printd("%s: CSP already running\n", __func__); return -EBUSY; } if (!(sample_width & p->acc_width)) { snd_printd("%s: Unsupported PCM sample width\n", __func__); return -EINVAL; } if (!(channels & p->acc_channels)) { snd_printd("%s: Invalid number of channels\n", __func__); return -EINVAL; } /* Mute PCM volume */ spin_lock_irqsave(&p->chip->mixer_lock, flags); mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV); mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7); spin_lock(&p->chip->reg_lock); set_mode_register(p->chip, 0xc0); /* c0 = STOP */ set_mode_register(p->chip, 0x70); /* 70 = RUN */ s_type = 0x00; if (channels == SNDRV_SB_CSP_MONO) s_type = 0x11; /* 000n 000n (n = 1 if mono) */ if (sample_width == SNDRV_SB_CSP_SAMPLE_8BIT) s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */ if (set_codec_parameter(p->chip, 0x81, s_type)) { snd_printd("%s: Set sample type command failed\n", __func__); goto __fail; } if (set_codec_parameter(p->chip, 0x80, 0x00)) { snd_printd("%s: Codec start command failed\n", __func__); goto __fail; } p->run_width = sample_width; p->run_channels = channels; p->running |= SNDRV_SB_CSP_ST_RUNNING; if (p->mode & SNDRV_SB_CSP_MODE_QSOUND) { set_codec_parameter(p->chip, 0xe0, 0x01); /* enable QSound decoder */ set_codec_parameter(p->chip, 0x00, 0xff); set_codec_parameter(p->chip, 0x01, 0xff); p->running |= SNDRV_SB_CSP_ST_QSOUND; /* set QSound startup value */ snd_sb_csp_qsound_transfer(p); } result = 0; __fail: spin_unlock(&p->chip->reg_lock); /* restore PCM volume */ snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR); spin_unlock_irqrestore(&p->chip->mixer_lock, flags); return result; } /* * stop CSP */ static int snd_sb_csp_stop(struct snd_sb_csp * p) { int result; unsigned char mixL, mixR; unsigned long flags; if (!(p->running & SNDRV_SB_CSP_ST_RUNNING)) return 0; /* Mute PCM volume */ spin_lock_irqsave(&p->chip->mixer_lock, flags); mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV); mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7); spin_lock(&p->chip->reg_lock); if (p->running & SNDRV_SB_CSP_ST_QSOUND) { set_codec_parameter(p->chip, 0xe0, 0x01); /* disable QSound decoder */ set_codec_parameter(p->chip, 0x00, 0x00); set_codec_parameter(p->chip, 0x01, 0x00); p->running &= ~SNDRV_SB_CSP_ST_QSOUND; } result = set_mode_register(p->chip, 0xc0); /* c0 = STOP */ spin_unlock(&p->chip->reg_lock); /* restore PCM volume */ snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL); snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR); spin_unlock_irqrestore(&p->chip->mixer_lock, flags); if (!(result)) p->running &= ~(SNDRV_SB_CSP_ST_PAUSED | SNDRV_SB_CSP_ST_RUNNING); return result; } /* * pause CSP codec and hold DMA transfer */ static int snd_sb_csp_pause(struct snd_sb_csp * p) { int result; unsigned long flags; if (!(p->running & SNDRV_SB_CSP_ST_RUNNING)) return -EBUSY; spin_lock_irqsave(&p->chip->reg_lock, flags); result = set_codec_parameter(p->chip, 0x80, 0xff); spin_unlock_irqrestore(&p->chip->reg_lock, flags); if (!(result)) p->running |= SNDRV_SB_CSP_ST_PAUSED; return result; } /* * restart CSP codec and resume DMA transfer */ static int snd_sb_csp_restart(struct snd_sb_csp * p) { int result; unsigned long flags; if (!(p->running & SNDRV_SB_CSP_ST_PAUSED)) return -EBUSY; spin_lock_irqsave(&p->chip->reg_lock, flags); result = set_codec_parameter(p->chip, 0x80, 0x00); spin_unlock_irqrestore(&p->chip->reg_lock, flags); if (!(result)) p->running &= ~SNDRV_SB_CSP_ST_PAUSED; return result; } /* ------------------------------ */ /* * QSound mixer control for PCM */ #define snd_sb_qsound_switch_info snd_ctl_boolean_mono_info static int snd_sb_qsound_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol); ucontrol->value.integer.value[0] = p->q_enabled ? 1 : 0; return 0; } static int snd_sb_qsound_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol); unsigned long flags; int change; unsigned char nval; nval = ucontrol->value.integer.value[0] & 0x01; spin_lock_irqsave(&p->q_lock, flags); change = p->q_enabled != nval; p->q_enabled = nval; spin_unlock_irqrestore(&p->q_lock, flags); return change; } static int snd_sb_qsound_space_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; uinfo->value.integer.min = 0; uinfo->value.integer.max = SNDRV_SB_CSP_QSOUND_MAX_RIGHT; return 0; } static int snd_sb_qsound_space_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol); unsigned long flags; spin_lock_irqsave(&p->q_lock, flags); ucontrol->value.integer.value[0] = p->qpos_left; ucontrol->value.integer.value[1] = p->qpos_right; spin_unlock_irqrestore(&p->q_lock, flags); return 0; } static int snd_sb_qsound_space_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol); unsigned long flags; int change; unsigned char nval1, nval2; nval1 = ucontrol->value.integer.value[0]; if (nval1 > SNDRV_SB_CSP_QSOUND_MAX_RIGHT) nval1 = SNDRV_SB_CSP_QSOUND_MAX_RIGHT; nval2 = ucontrol->value.integer.value[1]; if (nval2 > SNDRV_SB_CSP_QSOUND_MAX_RIGHT) nval2 = SNDRV_SB_CSP_QSOUND_MAX_RIGHT; spin_lock_irqsave(&p->q_lock, flags); change = p->qpos_left != nval1 || p->qpos_right != nval2; p->qpos_left = nval1; p->qpos_right = nval2; p->qpos_changed = change; spin_unlock_irqrestore(&p->q_lock, flags); return change; } static struct snd_kcontrol_new snd_sb_qsound_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "3D Control - Switch", .info = snd_sb_qsound_switch_info, .get = snd_sb_qsound_switch_get, .put = snd_sb_qsound_switch_put }; static struct snd_kcontrol_new snd_sb_qsound_space = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "3D Control - Space", .info = snd_sb_qsound_space_info, .get = snd_sb_qsound_space_get, .put = snd_sb_qsound_space_put }; static int snd_sb_qsound_build(struct snd_sb_csp * p) { struct snd_card *card; int err; if (snd_BUG_ON(!p)) return -EINVAL; card = p->chip->card; p->qpos_left = p->qpos_right = SNDRV_SB_CSP_QSOUND_MAX_RIGHT / 2; p->qpos_changed = 0; spin_lock_init(&p->q_lock); if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0) goto __error; if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0) goto __error; return 0; __error: snd_sb_qsound_destroy(p); return err; } static void snd_sb_qsound_destroy(struct snd_sb_csp * p) { struct snd_card *card; unsigned long flags; if (snd_BUG_ON(!p)) return; card = p->chip->card; down_write(&card->controls_rwsem); if (p->qsound_switch) snd_ctl_remove(card, p->qsound_switch); if (p->qsound_space) snd_ctl_remove(card, p->qsound_space); up_write(&card->controls_rwsem); /* cancel pending transfer of QSound parameters */ spin_lock_irqsave (&p->q_lock, flags); p->qpos_changed = 0; spin_unlock_irqrestore (&p->q_lock, flags); } /* * Transfer qsound parameters to CSP, * function should be called from interrupt routine */ static int snd_sb_csp_qsound_transfer(struct snd_sb_csp * p) { int err = -ENXIO; spin_lock(&p->q_lock); if (p->running & SNDRV_SB_CSP_ST_QSOUND) { set_codec_parameter(p->chip, 0xe0, 0x01); /* left channel */ set_codec_parameter(p->chip, 0x00, p->qpos_left); set_codec_parameter(p->chip, 0x02, 0x00); /* right channel */ set_codec_parameter(p->chip, 0x00, p->qpos_right); set_codec_parameter(p->chip, 0x03, 0x00); err = 0; } p->qpos_changed = 0; spin_unlock(&p->q_lock); return err; } /* ------------------------------ */ /* * proc interface */ static int init_proc_entry(struct snd_sb_csp * p, int device) { char name[16]; struct snd_info_entry *entry; sprintf(name, "cspD%d", device); if (! snd_card_proc_new(p->chip->card, name, &entry)) snd_info_set_text_ops(entry, p, info_read); return 0; } static void info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct snd_sb_csp *p = entry->private_data; snd_iprintf(buffer, "Creative Signal Processor [v%d.%d]\n", (p->version >> 4), (p->version & 0x0f)); snd_iprintf(buffer, "State: %cx%c%c%c\n", ((p->running & SNDRV_SB_CSP_ST_QSOUND) ? 'Q' : '-'), ((p->running & SNDRV_SB_CSP_ST_PAUSED) ? 'P' : '-'), ((p->running & SNDRV_SB_CSP_ST_RUNNING) ? 'R' : '-'), ((p->running & SNDRV_SB_CSP_ST_LOADED) ? 'L' : '-')); if (p->running & SNDRV_SB_CSP_ST_LOADED) { snd_iprintf(buffer, "Codec: %s [func #%d]\n", p->codec_name, p->func_nr); snd_iprintf(buffer, "Sample rates: "); if (p->acc_rates == SNDRV_SB_CSP_RATE_ALL) { snd_iprintf(buffer, "All\n"); } else { snd_iprintf(buffer, "%s%s%s%s\n", ((p->acc_rates & SNDRV_SB_CSP_RATE_8000) ? "8000Hz " : ""), ((p->acc_rates & SNDRV_SB_CSP_RATE_11025) ? "11025Hz " : ""), ((p->acc_rates & SNDRV_SB_CSP_RATE_22050) ? "22050Hz " : ""), ((p->acc_rates & SNDRV_SB_CSP_RATE_44100) ? "44100Hz" : "")); } if (p->mode == SNDRV_SB_CSP_MODE_QSOUND) { snd_iprintf(buffer, "QSound decoder %sabled\n", p->q_enabled ? "en" : "dis"); } else { snd_iprintf(buffer, "PCM format ID: 0x%x (%s/%s) [%s/%s] [%s/%s]\n", p->acc_format, ((p->acc_width & SNDRV_SB_CSP_SAMPLE_16BIT) ? "16bit" : "-"), ((p->acc_width & SNDRV_SB_CSP_SAMPLE_8BIT) ? "8bit" : "-"), ((p->acc_channels & SNDRV_SB_CSP_MONO) ? "mono" : "-"), ((p->acc_channels & SNDRV_SB_CSP_STEREO) ? "stereo" : "-"), ((p->mode & SNDRV_SB_CSP_MODE_DSP_WRITE) ? "playback" : "-"), ((p->mode & SNDRV_SB_CSP_MODE_DSP_READ) ? "capture" : "-")); } } if (p->running & SNDRV_SB_CSP_ST_AUTO) { snd_iprintf(buffer, "Autoloaded Mu-Law, A-Law or Ima-ADPCM hardware codec\n"); } if (p->running & SNDRV_SB_CSP_ST_RUNNING) { snd_iprintf(buffer, "Processing %dbit %s PCM samples\n", ((p->run_width & SNDRV_SB_CSP_SAMPLE_16BIT) ? 16 : 8), ((p->run_channels & SNDRV_SB_CSP_MONO) ? "mono" : "stereo")); } if (p->running & SNDRV_SB_CSP_ST_QSOUND) { snd_iprintf(buffer, "Qsound position: left = 0x%x, right = 0x%x\n", p->qpos_left, p->qpos_right); } } /* */ EXPORT_SYMBOL(snd_sb_csp_new); /* * INIT part */ static int __init alsa_sb_csp_init(void) { return 0; } static void __exit alsa_sb_csp_exit(void) { } module_init(alsa_sb_csp_init) module_exit(alsa_sb_csp_exit)