From 31f86bacfc9c8f6a3f25fa991c1f373374a9f25b Mon Sep 17 00:00:00 2001
From: Clemens Ladisch <clemens@ladisch.de>
Date: Tue, 2 Nov 2010 17:18:23 +0100
Subject: [PATCH] ALSA: oxygen: add Kuroutoshikou CMI8787-HG2PCI support

Add support for the Kuroutoshikou CMI8787-HG2PCI sound card.

[replaced non-latin letters in the patch by tiwai]

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 .../sound/alsa/ALSA-Configuration.txt         |  1 +
 sound/pci/Kconfig                             |  1 +
 sound/pci/oxygen/oxygen.c                     | 19 +++++++++++++++----
 sound/pci/oxygen/oxygen_lib.c                 |  2 +-
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index f1a1787e71e5..fdd388ded62a 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -1531,6 +1531,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
     * Club3D Theatron DTS
     * HT-Omega Claro (plus)
     * HT-Omega Claro halo (XT)
+    * Kuroutoshikou CMI8787-HG2PCI
     * Razer Barracuda AC-1
     * Sondigo Inferno
     * TempoTec HiFier Fantasia
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index dfe406de9935..f7139d09cbbe 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -222,6 +222,7 @@ config SND_OXYGEN
 	   * Club3D Theatron DTS
 	   * HT-Omega Claro (plus)
 	   * HT-Omega Claro halo (XT)
+	   * Kuroutoshikou CMI8787-HG2PCI
 	   * Razer Barracuda AC-1
 	   * Sondigo Inferno
 	   * TempoTec/MediaTek HiFier Fantasia
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 5e258b26f044..dd0f3f478999 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -71,6 +71,7 @@ enum {
 	MODEL_CLARO,		/* HT-Omega Claro */
 	MODEL_CLARO_HALO,	/* HT-Omega Claro halo */
 	MODEL_HIFIER,		/* TempoTec HiFier Fantasia */
+	MODEL_HG2PCI,		/* Kuroutoshikou CMI8787-HG2PCI */
 };
 
 static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
@@ -80,7 +81,7 @@ static DEFINE_PCI_DEVICE_TABLE(oxygen_ids) = {
 	{ OXYGEN_PCI_SUBID(0x13f6, 0x0001), .driver_data = MODEL_CMEDIA_REF },
 	{ OXYGEN_PCI_SUBID(0x13f6, 0x0010), .driver_data = MODEL_CMEDIA_REF },
 	{ OXYGEN_PCI_SUBID(0x13f6, 0x8788), .driver_data = MODEL_CMEDIA_REF },
-	{ OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data = MODEL_CMEDIA_REF },
+	{ OXYGEN_PCI_SUBID(0x13f6, 0xffff), .driver_data = MODEL_HG2PCI },
 	{ OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF },
 	{ OXYGEN_PCI_SUBID(0x14c3, 0x1710), .driver_data = MODEL_HIFIER },
 	{ OXYGEN_PCI_SUBID(0x14c3, 0x1711), .driver_data = MODEL_HIFIER },
@@ -243,6 +244,11 @@ static void hifier_init(struct oxygen *chip)
 	snd_component_add(chip->card, "CS5340");
 }
 
+static void hg2pci_init(struct oxygen *chip)
+{
+	ak4396_init(chip);
+}
+
 static void generic_cleanup(struct oxygen *chip)
 {
 }
@@ -572,15 +578,20 @@ static int __devinit get_oxygen_model(struct oxygen *chip,
 					    CAPTURE_1_FROM_SPDIF;
 		break;
 	case MODEL_HIFIER:
+	case MODEL_HG2PCI:
 		chip->model.shortname = "C-Media CMI8787";
 		chip->model.chip = "CMI8787";
-		chip->model.init = hifier_init;
+		if (id->driver_data == MODEL_HIFIER)
+			chip->model.init = hifier_init;
+		else
+			chip->model.init = hg2pci_init;
 		chip->model.resume = stereo_resume;
 		chip->model.mixer_init = generic_mixer_init;
 		chip->model.set_adc_params = set_no_params;
 		chip->model.device_config = PLAYBACK_0_TO_I2S |
-					    PLAYBACK_1_TO_SPDIF |
-					    CAPTURE_0_FROM_I2S_1;
+					    PLAYBACK_1_TO_SPDIF;
+		if (id->driver_data == MODEL_HIFIER)
+			chip->model.device_config |= CAPTURE_0_FROM_I2S_1;
 		chip->model.dac_channels = 2;
 		break;
 	}
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index e5ebe56fb0c5..2e6579962217 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -262,7 +262,7 @@ oxygen_search_pci_id(struct oxygen *chip, const struct pci_device_id ids[])
 	 */
 	subdevice = oxygen_read_eeprom(chip, 2);
 	/* use default ID if EEPROM is missing */
-	if (subdevice == 0xffff)
+	if (subdevice == 0xffff && oxygen_read_eeprom(chip, 1) == 0xffff)
 		subdevice = 0x8788;
 	/*
 	 * We use only the subsystem device ID for searching because it is
-- 
GitLab