intel声卡驱动probe分析--hda_intel.c alsa
生活随笔
收集整理的這篇文章主要介紹了
intel声卡驱动probe分析--hda_intel.c alsa
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1. 關鍵代碼及注釋:
1. intel聲卡初始化流程: /sound/pci/hda/hda_intel.cazx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) {snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, 0, &card); {//創建snd_card的一個實例card->dev = parent; card->number = idx; card->module = module; INIT_LIST_HEAD(&card->devices); //初始化聲卡設備列表#define INIT_LIST_HEAD(ptr) do { \(ptr)->next = (ptr); (ptr)->prev = (ptr); \} while (0)init_rwsem(&card->controls_rwsem); //初始化讀寫鎖rwlock_init(&card->ctl_files_rwlock); //初始化讀寫鎖mutex_init(&card->user_ctl_lock); //初始化鎖INIT_LIST_HEAD(&card->controls); //初始化controls列表INIT_LIST_HEAD(&card->ctl_files); //初始化ctl_files列表spin_lock_init(&card->files_lock); //初始化自旋鎖INIT_LIST_HEAD(&card->files_list); //初始化files_list列表device_initialize(&card->card_dev); //初始化聲卡設備err = kobject_set_name(&card->card_dev.kobj, "card%d", idx);//the control interface cannot be accessed from the user space until snd_cards_bitmask and snd_cards are set with snd_card_registererr = snd_ctl_create(card);{ snd_device_initialize(&card->ctl_dev, card); //初始化control設備 dev_set_name(&card->ctl_dev, "controlC%d", card->number);err = snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops); //create an ALSA device component} err = snd_info_card_create(card);{sprintf(str, "card%i", card->number);entry = create_subdir(card->module, str); {entry = snd_info_create_module_entry(mod, name, NULL); {//Creates a new info entry and assigns it to the given module.struct snd_info_entry *entry = snd_info_create_entry(name, parent);}snd_info_register(entry){if (S_ISDIR(entry->mode)) { //判斷是否是目錄p = proc_mkdir_mode(entry->name, entry->mode, root);if (!p) {mutex_unlock(&info_mutex);return -ENOMEM;}} else {const struct file_operations *ops;if (entry->content == SNDRV_INFO_CONTENT_DATA) //判斷entry內容是SNDRV_INFO_CONTENT_DATA 1還是SNDRV_INFO_CONTENT_TEXT 0ops = &snd_info_entry_operations;elseops = &snd_info_text_entry_ops;p = proc_create_data(entry->name, entry->mode, root,ops, entry);if (!p) {mutex_unlock(&info_mutex);return -ENOMEM;}proc_set_size(p, entry->size);}}}}} azx_create(card, pci, dev, pci_id->driver_data, &chip){INIT_LIST_HEAD(&chip->pcm_list);INIT_WORK(&hda->irq_pending_work, azx_irq_pending_work);INIT_LIST_HEAD(&hda->list);init_vga_switcheroo(chip);init_completion(&hda->probe_wait);azx_bus_init(chip, model[dev]);{ //HD-audio bus initializationsnd_hdac_bus_init(&bus->core, chip->card->dev, &bus_core_ops, io_ops); {//初始化chip->bus結構體bus->io_ops = io_ops;INIT_LIST_HEAD(&bus->stream_list); //初始化stream_listINIT_LIST_HEAD(&bus->codec_list); //初始化codec_listINIT_WORK(&bus->unsol_work, process_unsol_events);spin_lock_init(&bus->reg_lock);mutex_init(&bus->cmd_mutex);}}snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);{ //create an ALSA device component,把芯片的專有數據注冊為聲卡的一個低階設備:struct snd_device *pdev = list_entry(p, struct snd_device, list);//insert the entry in an incrementally sorted list }INIT_WORK(&hda->probe_work, azx_probe_work){azx_probe_continue(&hda->chip){azx_first_init(chip){err = pci_request_regions(chip->pci, "LS HD audio"); //bus->addr = pci_resource_start(chip->pci, 0);bus->remap_addr = pci_ioremap_bar(chip->pci, 0);azx_acquire_irq(chip, 0) {//請求中斷request_irq(chip->pci->irq, azx_interrupt, chip->msi ? 0 : IRQF_SHARED, KBUILD_MODNAME, chip)}gcap = azx_readw(chip, GCAP); dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);/* allow 64bit DMA address if supported by H/W */if ((gcap & AZX_GCAP_64OK) && !dma_set_mask(chip->card->dev, DMA_BIT_MASK(64)))dma_set_coherent_mask(chip->card->dev, DMA_BIT_MASK(64));else { dma_set_mask(chip->card->dev, DMA_BIT_MASK(32));dma_set_coherent_mask(chip->card->dev, DMA_BIT_MASK(32));} /* read number of streams from GCAP register instead of using* hardcoded value*/chip->capture_streams = (gcap >> 8) & 0x0f;chip->playback_streams = (gcap >> 12) & 0x0f;if (!chip->playback_streams && !chip->capture_streams) {/* gcap didn't give any info, switching to old method */chip->playback_streams = ICH6_NUM_PLAYBACK;chip->capture_streams = ICH6_NUM_CAPTURE;} /* initialize streams */err = azx_init_streams(chip);{ //initialize each stream (aka device) assign the starting bdl address to each stream (device) and initializedir = stream_direction(chip, i);snd_hdac_stream_init(azx_bus(chip), azx_stream(azx_dev), i, dir, tag);{azx_dev->bus = bus;/* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */azx_dev->sd_addr = bus->remap_addr + (0x20 * idx + 0x80);/* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */azx_dev->sd_int_sta_mask = 1 << idx;azx_dev->index = idx;azx_dev->direction = direction;azx_dev->stream_tag = tag;snd_hdac_dsp_lock_init(azx_dev); list_add_tail(&azx_dev->list, &bus->stream_list);} }azx_alloc_stream_pages(chip);{snd_hdac_bus_alloc_stream_pages(azx_bus(chip)){ //snd_hdac_bus_alloc_stream_pages - allocate BDL and other bufferserr = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, BDL_SIZE, &s->bdl); //allocate memory for the BDL for each stream err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, num_streams * 8, &bus->posbuf); //allocate memory for the position bufferlist_for_each_entry(s, &bus->stream_list, list)s->posbuf = (__le32 *)(bus->posbuf.area + s->index * 8);err = bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, PAGE_SIZE, &bus->rb); //single page (at least 4096 bytes) must suffice for both ringbuffes } }azx_init_chip(chip, (probe_only[dev] & 2) == 0); { //初始化pci設備,reset and start the controller registerssnd_hdac_bus_init_chip(azx_bus(chip), full_reset){ //snd_hdac_bus_init_chip - reset and start the controller registersif (bus->chip_init)return false;/* reset controller */azx_reset(bus, full_reset);/* initialize interrupts */azx_int_clear(bus);azx_int_enable(bus);/* initialize the codec command I/O */snd_hdac_bus_init_cmd_io(bus);{spin_lock_irq(&bus->reg_lock);/* disable ringbuffer DMAs */snd_hdac_chip_writeb(bus, RIRBCTL, 0);snd_hdac_chip_writeb(bus, CORBCTL, 0);hdac_wait_for_cmd_dmas(bus);/* disable unsolicited responses */ snd_hdac_chip_updatel(bus, GCTL, AZX_GCTL_UNSOL, 0);spin_unlock_irq(&bus->reg_lock);}/* program the position buffer */if (bus->use_posbuf && bus->posbuf.addr) {snd_hdac_chip_writel(bus, DPLBASE, (u32)bus->posbuf.addr);snd_hdac_chip_writel(bus, DPUBASE, upper_32_bits(bus->posbuf.addr));}bus->chip_init = true;}azx_writew(chip, RINTCNT, 0xc0);}snd_hdac_i915_set_bclk(bus);strcpy(card->driver, "HDA-Intel"); //設置Driver的ID和名字strlcpy(card->shortname, driver_short_names[chip->driver_type], sizeof(card->shortname));snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx irq %i", card->shortname, bus->addr, bus->irq);}/* create codec instances */if (bus->codec_mask) {err = azx_probe_codecs(chip, azx_max_codecs[chip->driver_type]);{robe_codec(chip, c){snd_hdac_bus_send_cmd(bus, cmd); snd_hdac_bus_get_response(bus, addr, &res);snd_hdac_ext_bus_device_init(ebus, addr); {//initialize the HDA extended codec base devicesnd_hdac_device_init(hdev, bus, name, addr); {snd_hdac_bus_add_device(bus, codec);{ //Add a codec to bus list_add_tail(&codec->list, &bus->codec_list); }codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, AC_PAR_VENDOR_ID);codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, AC_PAR_SUBSYSTEM_ID);err = snd_hdac_refresh_widgets(codec);codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE);err = get_codec_vendor_name(codec);}ret = snd_hdac_device_register(hdev); {err = device_add(&card->card_dev);err = snd_device_register_all(card)) snd_info_card_register(card); {/* register pending info register the card proc file*/proc_symlink(card->id, snd_proc_root->p, card->proc_root->name);}init_info_for_card(card);{entry = snd_info_create_card_entry(card, "id", card->proc_root);}}}}azx_stop_chip(chip);azx_init_chip(chip, true);}if (err < 0)goto out_free;}err = snd_card_register(chip->card); //注冊聲卡azx_add_card_list(chip);}}}schedule_work(&hda->probe_work);}總結
以上是生活随笔為你收集整理的intel声卡驱动probe分析--hda_intel.c alsa的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据结构-ADT
- 下一篇: windows系统自备垃圾清理工具