📄 tumbler.c
字号:
msleep(10); check_mute(chip, &mix->hp_mute, 1, mix->auto_mute_notify, chip->master_sw_ctl); if (mix->line_mute.addr != 0) check_mute(chip, &mix->line_mute, 1, mix->auto_mute_notify, chip->lineout_sw_ctl); } if (mix->auto_mute_notify) snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hp_detect_ctl->id);#ifdef CONFIG_SND_POWERMAC_AUTO_DRC mix->drc_enable = ! (headphone || lineout); if (mix->auto_mute_notify) snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->drc_sw_ctl->id); if (chip->model == PMAC_TUMBLER) tumbler_set_drc(mix); else snapper_set_drc(mix);#endif /* reset the master volume so the correct amplification is applied */ tumbler_set_master_volume(mix);}static void tumbler_update_automute(struct snd_pmac *chip, int do_notify){ if (chip->auto_mute) { struct pmac_tumbler *mix; mix = chip->mixer_data; snd_assert(mix, return); mix->auto_mute_notify = do_notify; schedule_work(&device_change); }}#endif /* PMAC_SUPPORT_AUTOMUTE *//* interrupt - headphone plug changed */static irqreturn_t headphone_intr(int irq, void *devid){ struct snd_pmac *chip = devid; if (chip->update_automute && chip->initialized) { chip->update_automute(chip, 1); return IRQ_HANDLED; } return IRQ_NONE;}/* look for audio-gpio device */static struct device_node *find_audio_device(const char *name){ struct device_node *gpiop; struct device_node *np; gpiop = of_find_node_by_name(NULL, "gpio"); if (! gpiop) return NULL; for (np = of_get_next_child(gpiop, NULL); np; np = of_get_next_child(gpiop, np)) { const char *property = of_get_property(np, "audio-gpio", NULL); if (property && strcmp(property, name) == 0) break; } of_node_put(gpiop); return np;}/* look for audio-gpio device */static struct device_node *find_compatible_audio_device(const char *name){ struct device_node *gpiop; struct device_node *np; gpiop = of_find_node_by_name(NULL, "gpio"); if (!gpiop) return NULL; for (np = of_get_next_child(gpiop, NULL); np; np = of_get_next_child(gpiop, np)) { if (of_device_is_compatible(np, name)) break; } of_node_put(gpiop); return np;}/* find an audio device and get its address */static long tumbler_find_device(const char *device, const char *platform, struct pmac_gpio *gp, int is_compatible){ struct device_node *node; const u32 *base; u32 addr; long ret; if (is_compatible) node = find_compatible_audio_device(device); else node = find_audio_device(device); if (! node) { DBG("(W) cannot find audio device %s !\n", device); snd_printdd("cannot find device %s\n", device); return -ENODEV; } base = of_get_property(node, "AAPL,address", NULL); if (! base) { base = of_get_property(node, "reg", NULL); if (!base) { DBG("(E) cannot find address for device %s !\n", device); snd_printd("cannot find address for device %s\n", device); of_node_put(node); return -ENODEV; } addr = *base; if (addr < 0x50) addr += 0x50; } else addr = *base; gp->addr = addr & 0x0000ffff; /* Try to find the active state, default to 0 ! */ base = of_get_property(node, "audio-gpio-active-state", NULL); if (base) { gp->active_state = *base; gp->active_val = (*base) ? 0x5 : 0x4; gp->inactive_val = (*base) ? 0x4 : 0x5; } else { const u32 *prop = NULL; gp->active_state = 0; gp->active_val = 0x4; gp->inactive_val = 0x5; /* Here are some crude hacks to extract the GPIO polarity and * open collector informations out of the do-platform script * as we don't yet have an interpreter for these things */ if (platform) prop = of_get_property(node, platform, NULL); if (prop) { if (prop[3] == 0x9 && prop[4] == 0x9) { gp->active_val = 0xd; gp->inactive_val = 0xc; } if (prop[3] == 0x1 && prop[4] == 0x1) { gp->active_val = 0x5; gp->inactive_val = 0x4; } } } DBG("(I) GPIO device %s found, offset: %x, active state: %d !\n", device, gp->addr, gp->active_state); ret = irq_of_parse_and_map(node, 0); of_node_put(node); return ret;}/* reset audio */static void tumbler_reset_audio(struct snd_pmac *chip){ struct pmac_tumbler *mix = chip->mixer_data; if (mix->anded_reset) { DBG("(I) codec anded reset !\n"); write_audio_gpio(&mix->hp_mute, 0); write_audio_gpio(&mix->amp_mute, 0); msleep(200); write_audio_gpio(&mix->hp_mute, 1); write_audio_gpio(&mix->amp_mute, 1); msleep(100); write_audio_gpio(&mix->hp_mute, 0); write_audio_gpio(&mix->amp_mute, 0); msleep(100); } else { DBG("(I) codec normal reset !\n"); write_audio_gpio(&mix->audio_reset, 0); msleep(200); write_audio_gpio(&mix->audio_reset, 1); msleep(100); write_audio_gpio(&mix->audio_reset, 0); msleep(100); }}#ifdef CONFIG_PM/* suspend mixer */static void tumbler_suspend(struct snd_pmac *chip){ struct pmac_tumbler *mix = chip->mixer_data; if (mix->headphone_irq >= 0) disable_irq(mix->headphone_irq); if (mix->lineout_irq >= 0) disable_irq(mix->lineout_irq); mix->save_master_switch[0] = mix->master_switch[0]; mix->save_master_switch[1] = mix->master_switch[1]; mix->save_master_vol[0] = mix->master_vol[0]; mix->save_master_vol[1] = mix->master_vol[1]; mix->master_switch[0] = mix->master_switch[1] = 0; tumbler_set_master_volume(mix); if (!mix->anded_reset) { write_audio_gpio(&mix->amp_mute, 1); write_audio_gpio(&mix->hp_mute, 1); } if (chip->model == PMAC_SNAPPER) { mix->acs |= 1; i2c_smbus_write_byte_data(mix->i2c.client, TAS_REG_ACS, mix->acs); } if (mix->anded_reset) { write_audio_gpio(&mix->amp_mute, 1); write_audio_gpio(&mix->hp_mute, 1); } else write_audio_gpio(&mix->audio_reset, 1);}/* resume mixer */static void tumbler_resume(struct snd_pmac *chip){ struct pmac_tumbler *mix = chip->mixer_data; snd_assert(mix, return); mix->acs &= ~1; mix->master_switch[0] = mix->save_master_switch[0]; mix->master_switch[1] = mix->save_master_switch[1]; mix->master_vol[0] = mix->save_master_vol[0]; mix->master_vol[1] = mix->save_master_vol[1]; tumbler_reset_audio(chip); if (mix->i2c.client && mix->i2c.init_client) { if (mix->i2c.init_client(&mix->i2c) < 0) printk(KERN_ERR "tumbler_init_client error\n"); } else printk(KERN_ERR "tumbler: i2c is not initialized\n"); if (chip->model == PMAC_TUMBLER) { tumbler_set_mono_volume(mix, &tumbler_pcm_vol_info); tumbler_set_mono_volume(mix, &tumbler_bass_vol_info); tumbler_set_mono_volume(mix, &tumbler_treble_vol_info); tumbler_set_drc(mix); } else { snapper_set_mix_vol(mix, VOL_IDX_PCM); snapper_set_mix_vol(mix, VOL_IDX_PCM2); snapper_set_mix_vol(mix, VOL_IDX_ADC); tumbler_set_mono_volume(mix, &snapper_bass_vol_info); tumbler_set_mono_volume(mix, &snapper_treble_vol_info); snapper_set_drc(mix); snapper_set_capture_source(mix); } tumbler_set_master_volume(mix); if (chip->update_automute) chip->update_automute(chip, 0); if (mix->headphone_irq >= 0) { unsigned char val; enable_irq(mix->headphone_irq); /* activate headphone status interrupts */ val = do_gpio_read(&mix->hp_detect); do_gpio_write(&mix->hp_detect, val | 0x80); } if (mix->lineout_irq >= 0) enable_irq(mix->lineout_irq);}#endif/* initialize tumbler */static int __init tumbler_init(struct snd_pmac *chip){ int irq; struct pmac_tumbler *mix = chip->mixer_data; snd_assert(mix, return -EINVAL); if (tumbler_find_device("audio-hw-reset", "platform-do-hw-reset", &mix->audio_reset, 0) < 0) tumbler_find_device("hw-reset", "platform-do-hw-reset", &mix->audio_reset, 1); if (tumbler_find_device("amp-mute", "platform-do-amp-mute", &mix->amp_mute, 0) < 0) tumbler_find_device("amp-mute", "platform-do-amp-mute", &mix->amp_mute, 1); if (tumbler_find_device("headphone-mute", "platform-do-headphone-mute", &mix->hp_mute, 0) < 0) tumbler_find_device("headphone-mute", "platform-do-headphone-mute", &mix->hp_mute, 1); if (tumbler_find_device("line-output-mute", "platform-do-lineout-mute", &mix->line_mute, 0) < 0) tumbler_find_device("line-output-mute", "platform-do-lineout-mute", &mix->line_mute, 1); irq = tumbler_find_device("headphone-detect", NULL, &mix->hp_detect, 0); if (irq <= NO_IRQ) irq = tumbler_find_device("headphone-detect", NULL, &mix->hp_detect, 1); if (irq <= NO_IRQ) irq = tumbler_find_device("keywest-gpio15", NULL, &mix->hp_detect, 1); mix->headphone_irq = irq; irq = tumbler_find_device("line-output-detect", NULL, &mix->line_detect, 0); if (irq <= NO_IRQ) irq = tumbler_find_device("line-output-detect", NULL, &mix->line_detect, 1); mix->lineout_irq = irq; tumbler_reset_audio(chip); return 0;}static void tumbler_cleanup(struct snd_pmac *chip){ struct pmac_tumbler *mix = chip->mixer_data; if (! mix) return; if (mix->headphone_irq >= 0) free_irq(mix->headphone_irq, chip); if (mix->lineout_irq >= 0) free_irq(mix->lineout_irq, chip); tumbler_gpio_free(&mix->audio_reset); tumbler_gpio_free(&mix->amp_mute); tumbler_gpio_free(&mix->hp_mute); tumbler_gpio_free(&mix->hp_detect); snd_pmac_keywest_cleanup(&mix->i2c); kfree(mix); chip->mixer_data = NULL;}/* exported */int __init snd_pmac_tumbler_init(struct snd_pmac *chip){ int i, err; struct pmac_tumbler *mix; const u32 *paddr; struct device_node *tas_node, *np; char *chipname;#ifdef CONFIG_KMOD if (current->fs->root) request_module("i2c-powermac");#endif /* CONFIG_KMOD */ mix = kzalloc(sizeof(*mix), GFP_KERNEL); if (! mix) return -ENOMEM; mix->headphone_irq = -1; chip->mixer_data = mix; chip->mixer_free = tumbler_cleanup; mix->anded_reset = 0; mix->reset_on_sleep = 1; for (np = chip->node->child; np; np = np->sibling) { if (!strcmp(np->name, "sound")) { if (of_get_property(np, "has-anded-reset", NULL)) mix->anded_reset = 1; if (of_get_property(np, "layout-id", NULL)) mix->reset_on_sleep = 0; break; } } if ((err = tumbler_init(chip)) < 0) return err; /* set up TAS */ tas_node = of_find_node_by_name(NULL, "deq"); if (tas_node == NULL) tas_node = of_find_node_by_name(NULL, "codec"); if (tas_node == NULL) return -ENODEV; paddr = of_get_property(tas_node, "i2c-address", NULL); if (paddr == NULL) paddr = of_get_property(tas_node, "reg", NULL); if (paddr) mix->i2c.addr = (*paddr) >> 1; else mix->i2c.addr = TAS_I2C_ADDR; of_node_put(tas_node); DBG("(I) TAS i2c address is: %x\n", mix->i2c.addr); if (chip->model == PMAC_TUMBLER) { mix->i2c.init_client = tumbler_init_client; mix->i2c.name = "TAS3001c"; chipname = "Tumbler"; } else { mix->i2c.init_client = snapper_init_client; mix->i2c.name = "TAS3004"; chipname = "Snapper"; } if ((err = snd_pmac_keywest_init(&mix->i2c)) < 0) return err; /* * build mixers */ sprintf(chip->card->mixername, "PowerMac %s", chipname); if (chip->model == PMAC_TUMBLER) { for (i = 0; i < ARRAY_SIZE(tumbler_mixers); i++) { if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&tumbler_mixers[i], chip))) < 0) return err; } } else { for (i = 0; i < ARRAY_SIZE(snapper_mixers); i++) { if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snapper_mixers[i], chip))) < 0) return err; } } chip->master_sw_ctl = snd_ctl_new1(&tumbler_hp_sw, chip); if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) return err; chip->speaker_sw_ctl = snd_ctl_new1(&tumbler_speaker_sw, chip); if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) return err; if (mix->line_mute.addr != 0) { chip->lineout_sw_ctl = snd_ctl_new1(&tumbler_lineout_sw, chip); if ((err = snd_ctl_add(chip->card, chip->lineout_sw_ctl)) < 0) return err; } chip->drc_sw_ctl = snd_ctl_new1(&tumbler_drc_sw, chip); if ((err = snd_ctl_add(chip->card, chip->drc_sw_ctl)) < 0) return err; /* set initial DRC range to 60% */ if (chip->model == PMAC_TUMBLER) mix->drc_range = (TAS3001_DRC_MAX * 6) / 10; else mix->drc_range = (TAS3004_DRC_MAX * 6) / 10; mix->drc_enable = 1; /* will be changed later if AUTO_DRC is set */ if (chip->model == PMAC_TUMBLER) tumbler_set_drc(mix); else snapper_set_drc(mix);#ifdef CONFIG_PM chip->suspend = tumbler_suspend; chip->resume = tumbler_resume;#endif INIT_WORK(&device_change, device_change_handler); device_change_chip = chip;#ifdef PMAC_SUPPORT_AUTOMUTE if ((mix->headphone_irq >=0 || mix->lineout_irq >= 0) && (err = snd_pmac_add_automute(chip)) < 0) return err; chip->detect_headphone = tumbler_detect_headphone; chip->update_automute = tumbler_update_automute; tumbler_update_automute(chip, 0); /* update the status only */ /* activate headphone status interrupts */ if (mix->headphone_irq >= 0) { unsigned char val; if ((err = request_irq(mix->headphone_irq, headphone_intr, 0, "Sound Headphone Detection", chip)) < 0) return 0; /* activate headphone status interrupts */ val = do_gpio_read(&mix->hp_detect); do_gpio_write(&mix->hp_detect, val | 0x80); } if (mix->lineout_irq >= 0) { unsigned char val; if ((err = request_irq(mix->lineout_irq, headphone_intr, 0, "Sound Lineout Detection", chip)) < 0) return 0; /* activate headphone status interrupts */ val = do_gpio_read(&mix->line_detect); do_gpio_write(&mix->line_detect, val | 0x80); }#endif return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -