Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9470195a authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: ctxfi - Clean up probe routines



Clean up probe routines and model detection routines so that the driver
won't call and check the PCI subsystem id at each time.

Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent d362af62
Loading
Loading
Loading
Loading
+59 −73
Original line number Diff line number Diff line
@@ -39,31 +39,42 @@
			    | (0x10 << 16) \
			    | ((IEC958_AES3_CON_FS_48000) << 24))

static const struct ct_atc_chip_sub_details atc_sub_details[NUM_CTCARDS] = {
	[CTSB0760] = {.subsys = PCI_SUBDEVICE_ID_CREATIVE_SB0760,
		      .nm_model = "SB076x"},
	[CTHENDRIX] = {.subsys = PCI_SUBDEVICE_ID_CREATIVE_HENDRIX,
		      .nm_model = "Hendrix"},
	[CTSB08801] = {.subsys = PCI_SUBDEVICE_ID_CREATIVE_SB08801,
		      .nm_model = "SB0880"},
	[CTSB08802] = {.subsys = PCI_SUBDEVICE_ID_CREATIVE_SB08802,
		      .nm_model = "SB0880"},
	[CTSB08803] = {.subsys = PCI_SUBDEVICE_ID_CREATIVE_SB08803,
		      .nm_model = "SB0880"}
static struct snd_pci_quirk __devinitdata subsys_20k1_list[] = {
	SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0022, "SB055x", CTSB055X),
	SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x002f, "SB055x", CTSB055X),
	SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0029, "SB073x", CTSB073X),
	SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0031, "SB073x", CTSB073X),
	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE, 0x6000,
			   PCI_SUBDEVICE_ID_CREATIVE_HENDRIX, "UAA", CTUAA),
	SND_PCI_QUIRK_VENDOR(PCI_VENDOR_ID_CREATIVE,
			     "Unknown", CT20K1_UNKNOWN),
	{ } /* terminator */
};

static struct ct_atc_chip_details atc_chip_details[] = {
	{.vendor = PCI_VENDOR_ID_CREATIVE,
	 .device = PCI_DEVICE_ID_CREATIVE_20K1,
	 .sub_details = NULL,
	 .nm_card = "X-Fi 20k1"},
	{.vendor = PCI_VENDOR_ID_CREATIVE,
	 .device = PCI_DEVICE_ID_CREATIVE_20K2,
	 .sub_details = atc_sub_details,
	 .nm_card = "X-Fi 20k2"},
static struct snd_pci_quirk __devinitdata subsys_20k2_list[] = {
	SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB0760,
		      "SB0760", CTSB0760),
	SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08801,
		      "SB0880", CTSB0880),
	SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08802,
		      "SB0880", CTSB0880),
	SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08803,
		      "SB0880", CTSB0880),
	SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE, 0x6000,
			   PCI_SUBDEVICE_ID_CREATIVE_HENDRIX, "UAA", CTHENDRIX),
	{ } /* terminator */
};

static const char *ct_subsys_name[NUM_CTCARDS] = {
	[CTSB055X]	= "SB055x",
	[CTSB073X]	= "SB073x",
	[CTSB0760]	= "SB076x",
	[CTUAA]		= "UAA",
	[CT20K1_UNKNOWN] = "Unknown",
	[CTHENDRIX]	= "Hendrix",
	[CTSB0880]	= "SB0880",
};

static struct {
	int (*create)(struct ct_atc *atc,
			enum CTALSADEVS device, const char *device_name);
@@ -1208,62 +1219,39 @@ static int atc_dev_free(struct snd_device *dev)

static int __devinit atc_identify_card(struct ct_atc *atc)
{
	u16 subsys;
	u8 revision;
	struct pci_dev *pci = atc->pci;
	const struct ct_atc_chip_details *d;
	enum CTCARDS i;

	subsys = pci->subsystem_device;
	revision = pci->revision;
	atc->chip_details = NULL;
	atc->model = NUM_CTCARDS;
	for (d = atc_chip_details; d->vendor; d++) {
		if (d->vendor != pci->vendor || d->device != pci->device)
			continue;
	const struct snd_pci_quirk *p;
	const struct snd_pci_quirk *list;

		if (NULL == d->sub_details) {
			atc->chip_details = d;
			break;
		}
		for (i = 0; i < NUM_CTCARDS; i++) {
			if ((d->sub_details[i].subsys == subsys) ||
			    (((subsys & 0x6000) == 0x6000) &&
			    ((d->sub_details[i].subsys & 0x6000) == 0x6000))) {
				atc->model = i;
	switch (atc->chip_type) {
	case ATC20K1:
		atc->chip_name = "20K1";
		list = subsys_20k1_list;
		break;
			}
		}
		if (i >= NUM_CTCARDS)
			continue;

		atc->chip_details = d;
	case ATC20K2:
		atc->chip_name = "20K2";
		list = subsys_20k2_list;
		break;
		/* not take revision into consideration now */
	default:
		return -ENOENT;
	}
	if (!d->vendor)
	p = snd_pci_quirk_lookup(atc->pci, list);
	if (!p)
		return -ENOENT;

	atc->model = p->value;
	atc->model_name = ct_subsys_name[atc->model];
	snd_printd("ctxfi: chip %s model %s (%04x:%04x) is found\n",
		   atc->chip_name, atc->model_name,
		   atc->pci->subsystem_vendor,
		   atc->pci->subsystem_device);
	return 0;
}

int __devinit ct_atc_create_alsa_devs(struct ct_atc *atc)
{
	enum CTALSADEVS i;
	struct hw *hw = atc->hw;
	int err;

	switch (hw->get_chip_type(hw)) {
	case ATC20K1:
		alsa_dev_funcs[MIXER].public_name = "20K1";
		break;
	case ATC20K2:
		alsa_dev_funcs[MIXER].public_name = "20K2";
		break;
	default:
		alsa_dev_funcs[MIXER].public_name = "Unknown";
		break;
	}
	alsa_dev_funcs[MIXER].public_name = atc->chip_name;

	for (i = 0; i < NUM_CTALSADEVS; i++) {
		if (NULL == alsa_dev_funcs[i].create)
@@ -1287,7 +1275,7 @@ static int __devinit atc_create_hw_devs(struct ct_atc *atc)
	struct card_conf info = {0};
	int i, err;

	err = create_hw_obj(atc->pci, &hw);
	err = create_hw_obj(atc->pci, atc->chip_type, atc->model, &hw);
	if (err) {
		printk(KERN_ERR "Failed to create hw obj!!!\n");
		return err;
@@ -1328,7 +1316,6 @@ static int __devinit atc_get_resources(struct ct_atc *atc)
	struct sum_desc sum_dsc = {0};
	struct sum_mgr *sum_mgr;
	int err, i;
	unsigned short subsys_id;

	atc->daios = kzalloc(sizeof(void *)*(DAIONUM), GFP_KERNEL);
	if (NULL == atc->daios)
@@ -1359,13 +1346,10 @@ static int __devinit atc_get_resources(struct ct_atc *atc)
		}
		atc->n_daio++;
	}
	subsys_id = atc->pci->subsystem_device;
	if ((subsys_id == 0x0029) || (subsys_id == 0x0031)) {
		/* SB073x cards */
	if (atc->model == CTSB073X)
		da_desc.type = SPDIFI1;
	} else {
	else
		da_desc.type = SPDIFIO;
	}
	err = daio_mgr->get_daio(daio_mgr, &da_desc,
				(struct daio **)&atc->daios[i]);
	if (err) {
@@ -1555,7 +1539,8 @@ static struct ct_atc atc_preset __devinitdata = {
 */

int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
		  unsigned int rsr, unsigned int msr, struct ct_atc **ratc)
			    unsigned int rsr, unsigned int msr,
			    int chip_type, struct ct_atc **ratc)
{
	struct ct_atc *atc;
	static struct snd_device_ops ops = {
@@ -1576,6 +1561,7 @@ int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
	atc->pci = pci;
	atc->rsr = rsr;
	atc->msr = msr;
	atc->chip_type = chip_type;

	spin_lock_init(&atc->atc_lock);

+5 −12
Original line number Diff line number Diff line
@@ -37,15 +37,6 @@ enum CTALSADEVS { /* Types of alsa devices */
	NUM_CTALSADEVS		/* This should always be the last */
};

enum CTCARDS {
	CTSB0760,
	CTHENDRIX,
	CTSB08801,
	CTSB08802,
	CTSB08803,
	NUM_CTCARDS		/* This should always be the last */
};

struct ct_atc_chip_sub_details {
	u16 subsys;
	const char *nm_model;
@@ -89,8 +80,10 @@ struct ct_atc {
	unsigned int msr; /* master sample rate in rsr */
	unsigned int pll_rate; /* current rate of Phase Lock Loop */

	const struct ct_atc_chip_details *chip_details;
	enum CTCARDS model;
	int chip_type;
	int model;
	const char *chip_name;
	const char *model_name;

	struct ct_vm *vm; /* device virtual memory manager for this card */
	int (*map_audio_buffer)(struct ct_atc *atc, struct ct_atc_pcm *apcm);
@@ -147,7 +140,7 @@ struct ct_atc {


int __devinit ct_atc_create(struct snd_card *card, struct pci_dev *pci,
			    unsigned int rsr, unsigned int msr,
			    unsigned int rsr, unsigned int msr, int chip_type,
			    struct ct_atc **ratc);
int __devinit ct_atc_create_alsa_devs(struct ct_atc *atc);

+3 −3
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ static struct rsc_ops daio_in_rsc_ops_20k2 = {

static unsigned int daio_device_index(enum DAIOTYP type, struct hw *hw)
{
	switch (hw->get_chip_type(hw)) {
	switch (hw->chip_type) {
	case ATC20K1:
		switch (type) {
		case SPDIFOO:	return 0;
@@ -343,7 +343,7 @@ static int daio_rsc_init(struct daio *daio,
	int err;
	unsigned int idx_l, idx_r;

	switch (((struct hw *)hw)->get_chip_type(hw)) {
	switch (((struct hw *)hw)->chip_type) {
	case ATC20K1:
		idx_l = idx_20k1[desc->type].left;
		idx_r = idx_20k1[desc->type].right;
@@ -367,7 +367,7 @@ static int daio_rsc_init(struct daio *daio,
	if (desc->type <= DAIO_OUT_MAX) {
		daio->rscl.ops = daio->rscr.ops = &daio_out_rsc_ops;
	} else {
		switch (((struct hw *)hw)->get_chip_type(hw)) {
		switch (((struct hw *)hw)->chip_type) {
		case ATC20K1:
			daio->rscl.ops = daio->rscr.ops = &daio_in_rsc_ops_20k1;
			break;
+7 −24
Original line number Diff line number Diff line
@@ -20,34 +20,16 @@
#include "cthw20k2.h"
#include <linux/bug.h>

static enum CHIPTYP __devinitdata get_chip_type(struct hw *hw)
{
	enum CHIPTYP type;

	switch (hw->pci->device) {
	case 0x0005:	/* 20k1 device */
		type = ATC20K1;
		break;
	case 0x000B:	/* 20k2 device */
		type = ATC20K2;
		break;
	default:
		type = ATCNONE;
		break;
	}

	return type;
}

int __devinit create_hw_obj(struct pci_dev *pci, struct hw **rhw)
int __devinit create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
			    enum CTCARDS model, struct hw **rhw)
{
	int err;

	switch (pci->device) {
	case 0x0005:	/* 20k1 device */
	switch (chip_type) {
	case ATC20K1:
		err = create_20k1_hw_obj(rhw);
		break;
	case 0x000B:	/* 20k2 device */
	case ATC20K2:
		err = create_20k2_hw_obj(rhw);
		break;
	default:
@@ -58,7 +40,8 @@ int __devinit create_hw_obj(struct pci_dev *pci, struct hw **rhw)
		return err;

	(*rhw)->pci = pci;
	(*rhw)->get_chip_type = get_chip_type;
	(*rhw)->chip_type = chip_type;
	(*rhw)->model = model;

	return 0;
}
+18 −2
Original line number Diff line number Diff line
@@ -27,6 +27,19 @@ enum CHIPTYP {
	ATCNONE
};

enum CTCARDS {
	/* 20k1 models */
	CTSB055X,
	CTSB073X,
	CTUAA,
	CT20K1_UNKNOWN,
	/* 20k2 models */
	CTSB0760,
	CTHENDRIX,
	CTSB0880,
	NUM_CTCARDS		/* This should always be the last */
};

/* Type of input source for ADC */
enum ADCSRC{
	ADC_MICIN,
@@ -48,7 +61,6 @@ struct hw {
	int (*card_init)(struct hw *hw, struct card_conf *info);
	int (*card_stop)(struct hw *hw);
	int (*pll_init)(struct hw *hw, unsigned int rsr);
	enum CHIPTYP (*get_chip_type)(struct hw *hw);
	int (*is_adc_source_selected)(struct hw *hw, enum ADCSRC source);
	int (*select_adc_source)(struct hw *hw, enum ADCSRC source);
	int (*have_digit_io_switch)(struct hw *hw);
@@ -156,9 +168,13 @@ struct hw {
	int irq;
	unsigned long io_base;
	unsigned long mem_base;

	enum CHIPTYP chip_type;
	enum CTCARDS model;
};

int create_hw_obj(struct pci_dev *pci, struct hw **rhw);
int create_hw_obj(struct pci_dev *pci, enum CHIPTYP chip_type,
		  enum CTCARDS model, struct hw **rhw);
int destroy_hw_obj(struct hw *hw);

unsigned int get_field(unsigned int data, unsigned int field);
Loading