Skip to contentSkip to conversation

ALSA: hda/tas2781: Add tas2781 hda SPI driver

PATCH Superseded Baojun Xu 2 participants 2 messages Jul 21, 2024

Subsystems (4)

v10 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

Baojun Xu

author
#0 lore raw

PATCH v10 1/1 ALSA: hda/tas2781: Add tas2781 hda SPI driver

This patch was used to add TAS2781 devices on SPI support in sound/pci/hda. It use ACPI node descript about parameters of TAS2781 on SPI, it like:

    Scope (_SB.PC00.SPI0)
    {
        Device (GSPK)
        {
            Name (_HID, "TXNW2781")  // _HID: Hardware ID
            Method (_CRS, 0, NotSerialized)
            {
                Name (RBUF, ResourceTemplate ()
                {
                    SpiSerialBusV2 (...)
                    SpiSerialBusV2 (...)
                }
            }
        }
    }

And in platform/x86/serial-multi-instantiate.c, those spi devices will be added into system as a single SPI device, so TAS2781 SPI driver will probe twice for every single SPI device. And driver will also parser mono DSP firmware binary and RCA binary for itself.
The code support Realtek as the primary codec.
In patch version-10, add multi devices firmware binary support, to compatble with windows driver, they can share same firmware binary.

---
v10:
- Remove project id 103c8b93 in Patch_realtek.c, as it was used for test only, offcial project id is 103c8daa (Gemtree).
- Add TAS2781_REG_CLK_CONFIG for check if AMP has been reset.
- Add table for pre-reset and post-reset.
- Perform pre-reset config before reset AMP.
- Perform post-reset config after reset AMP.
- Fix wrong offset in calibration data issue.
- Remove tuning switch after firmware download.
- Force stop play in runtime suspend.
- Apply patch for component change in bind & unbind.
- Remove program download and calibration data apply,
switch tuning only in runtime resume.
- Check if AMP has reseted in system resume,
and do firmware download and calibration data apply.
- Change flag 0xCx to 0x8x for coeff data force download.
- Add device index for multi device firmware binary file compatible.
- Check device index before registers write during firmware download.
- Force config data download after program download.
- Remove config download in tuning switch.
v9:
- Add parentheses for variables in micro define.
- Add define for calibration registers address identify.
- Change variable name from calibration_data to cali_data.
- Add variable for calibration registers address in struct tasdevice_priv.
- Change format for alignment to parentheses.
- Remove tas2781_reg_defaults as it will be over write in firmware download.
- Remove RESET for second device in tas2781_spi_reset(),
as it will cause no sound on second device.
- Add calibration registers address initial in tasdevice_spi_init().
- Remove unnecessary parentheses.
- Remove exception in tas2781_hda_playback_hook().
- Remove hard code for calibration registers address.
- Add support for calibration data format V3 for registers address identify, as new firmware tool will define calibration registers address dynamic, so can't hard code it, need read it from BIOS with calibration data.
- Remove some debug print.
- Change hard code value (3) to ARRAY_SIZE(tas2781_snd_controls)/2.
- New patch apply for change position of component_del().
- Change label from out, out1 to config_err and block_err.
- Remove unnecessary parentheses in tas2781_spi_fwlib.c.
- Remove tasdevice_spi_prmg_calibdata_load().
v8:
- Move *-y position in sound/pci/hda/Makefile.
- Change + to | for bit operation in macro define.
- Change TASDEVICE_Checksum to TASDEVICE_CHECKSUM.
v7:
- Add new project Gemtree (0x103c8daa) support for tas2781 spi driver.
v6:
- Remove client in tasdevice_priv struct as it was not used.
- Change format for tasdevice_spi_dev_write() in tas2781_hda_spi.c.
- Change update bits function to read & write mode, as tas2781 use last bit to mask read & write, it cause regmap_update_bits work not as our expected.
- Add element in tas2781_snd_controls, tas2781_prof_ctrl, tas2781_dsp_conf_ctrl, to support second device.
Previous version add sound card for first index only.
- Change calibration registers address declaire to TASDEVICE_REG() mode.
- Add snd_ctl_new1() for second device.
- Change format for tas2781_hda_unbind() to fit 79 chars in one line.
- Remove client for spi as it was not used.
- Remove unused variables.
- Remove cur_prog clean in runtime_suspend().
- Remove unused variables.
- Add tasdevice_spi_tuning_switch() in runtime_resume.
- Remove cur_prog clean in system_resume().
- Add tuning switch if playback started in system_resume().
- Change TASDEVICE_PAGE_REG to TASDEVICE_REG_ID in tas2781_spi_fwlib.c.
- Remove calibration binary load functions as data will be loaded from EFI.
v5:
- Combined all modification into one patch for pass the compile.
- Remove old hardware id "TIAS2781" as no production on market.
- Change max page size to 256 in tas2781-spi.h.
- Change book reg from 127 to GENMASK(7, 1), as one bit shift is needed.
- Change register address define as one bit shift needed for offset.
- Change block check sum comments to Firmware block from I2C.
- Change define of (page + reg) to TASDEVICE_PAGE_REG from TASDEVICE_PGRG.
- Change to lower case in defined value.
- Add registers default value table in tas2781_hda_spi.c
- Change rang_max to 256 * 256.
- Add zero_flag_mask in regmap_config.
- Change max_register to 256 * 256.
- Add registers default table into structure regmap_config.
- Change parameter from book number to whole register address.
- Remove page 0 switch as SPI driver will do it.
- Add bit(0) for read function as tas2781 will check last bit of address, to determine operation mode is read (1) or write (0).
- Change switch case to if check in tas2781_hda_playback_hook(), as it may cause compile problem in clang-19 building.
- Change variable declaration position.
- Change order in if check.
- Remove old hardware id ("TIAS2781") support.
- Remove debug message in runtime suspend and resume.
- Remove regmap.h include in tas2781_spi_fwlib.c.
- Remove MODULE_ in fwlib as this file will work with tas2781_hda_spi.c only.
v4:
- Add old hardware id "TIAS2781" for compatible with old production
- Add 2 devices in struct smi_node tas2781_hda, to compatible with 4 AMPs
v4:
- Add old hardware id "TIAS2781" for compatible with old production
- Add 2 devices in struct smi_node tas2781_hda, to compatible with 4 AMPs
- Move include of sound/tas2781-dsp.h to c source file tas2781_hda_spi.c, tas2781_spi_fwlib.c, as it's not needed in header file tas2781-spi.h
- Use page and book number define in other micro define
- Change 4000000 to (4 * HZ_PER_MHZ)
- Add define for calibration variable name and size in UEFI.
- Remove structure tasdevice & tasdevice_irqinfo, and move variables in to structure tasdevice_priv
- Remove some unused variables in sttructure tasdevice_priv
- Remove function declare of tascodec_init(), use tascodec_spi_init()
- Remove function declare of tasdevice_remove()
- Add array_size.h included in tas2781_hda_spi.c
- Add cleanup.h included for change mutex to guard
- Add units.h included
- Include tas2781-dsp.h
- Remove unused variables in tas2781_hda structure
- Change 0xff to GENMASK(7, 0)
- Change 128 to define of max page size
- Change code as all variables was moved to tasdevice_priv structure
- Change comments for error in book write, or page write
- Remove initial of ret, and return 0 directly
- Change comments for wrong typo, add space in front and end
- Add check for bulk read, max size should be a page size
- Change usleep_rang() to fsleep()
- Change mutex_lock to guard(mutex), and remove mutex_unlock()
- Change tasdevice_spi_init() to void from int as no value return required
- Change second parameter to sizeof
- Remove tasdevice_clamp(), use clamp()
- Add compatible with old hardware id "TIAS2781"
- Remove cs_gpio and spi device in tas2781_read_acpi() as use default CS
- Change dev-index check, return -EINVAL if it's <= 0
- Change 0xFF to U8_MAX
- Remove GPIO get for chip-select, use default from SPI device
- Perform RESET in first AMP only as all AMPs share same RESET pin
- return 0 directly in some simple routine to avoid variable initial
- Change comments for function which was used by system
- Change "ON" "OFF" to function str_on_off(...)
- Change format of GUID
- Add temp buffer for first efi.get_variable()
- Free data if it was allocated
- Change format of debug message of calibration date time print
- Remove total_sz = 0, as it's not needed
- Move save_calibration to after tuning_switch to avoid calibration data overwrite
- Remove dev from structure tasdevice_hda, use dev in tasdevice_priv
- Remove 0 from { "tas2781-hda", 0}, & {"TXNW2781", 0},
- Add old hardware id "TIAS2781" for compatible with old production
- Add 2 devices in struct smi_node tas2781_hda, to compatible with 4 AMPs
v3:
- Move HID up to above /* Non-conforming _HID ... */ in scan.c, for avoid misunderstanding.
- Move HID up to above /* Non-conforming _HID ... */ in serial-multi-instantiate.c, for avoid misunderstanding.
- Change objs to y for snd-hda-scodec-tas2781-spi- in Makefile.
- Change format for some define in tas2781-spi.h.
- Add define for TASDEVICE_MAX_BOOK_NUM, TASDEVICE_MAX_PAGE.
- Move declare of "enum calib_data {" to header file from source file.
- Remove "enum device_catlog_id {" as only one platform was supported now.
- Remove "struct calidata", as we will save pure calibration data only.
- Remove "struct calidata", "enum device_catlog_id" in tasdevice_priv.
- Add calibration_data in tasdevice_priv to save pure calibration data.
- Remove declare of tasdevice_save_calibration() and tasdevice_apply_calibration(), as it will be used within same c file.
- Add below header files included in tas2781_hda_spi.c:
bits.h, mutex.h, property.h, time.h, types.h.
- Move two micro define to header file tas2781-spi.h.
- Change format of some micro define.
- Change format of some structure.
- Remove irq in tas2781_hda, as have it already in tasdevice_priv.
- Remove some local functions declare as not necessarily.
- Return error if regmap_write() failed.
- Change fixed value 2 to sizeof(data).
- Remove all of EXPORT_SYMBOL_GPL,
as all of function was called within same module.
- Remove empty line after last return in some functions.
- Remove some variable initialyzation.
- Remove variable sub, store acpi_subsystem_id directly.
- Remove wrong comments for device index, it's must, can't be NULL.
- Remove some local variables, use elements in structure directly.
- Append commas in last element of an array.
- Change calibration data process, didn't save all of calibration data in EFI, get in local, and save pure calibration data in tasdevice_priv.
- Call tasdevice_save_calibration() from function pointer in tasdevice_priv;
- Remove subid as one platform was supported only, needn't check.
- Add initialyzation for local variable.
- Move regmap initialyzation to before acpi read.
- Call tasdevice_apply_calibration() from function pointer in tasdevice_priv;
- Remove MODULE_IMPORT_NS(SND_SOC_TAS2781_FMWLIB), as all functions was performed within same module.
- Update format and variables declare order.
- Change format of multi conditions for if.
- Remove casting which is not needed.
- Change variables type to avoid casting.
- Remove Unneeded parentheses.
- Change if check to avoid goto.
- Add {} for keep same style.
- Remove some local variables, use elements in structure directly.
v2:
- Change depends on SPI to SPI_MASTER in sound/pci/hda/Kconfig
- Add select SND_HDA_SCODEC_COMPONENT in sound/pci/hda/Kconfig
- Change comp_generic_fixup() 5th parameter from "-%s:00" to "-%s:00-tas2781-hda.%d" in sound/pci/hda/patch_realtek.c
- Change chain_id from ALC285_FIXUP_THINKPAD_HEADSET_JACK to ALC285_FIXUP_HP_GPIO_LED in sound/pci/hda/patch_realtek.c
- Remove project name "Gemtree"
- Update information in file header of tas2781-spi.h.
- Remove useless micro define.
- Change TASDEVICE_I2CChecksum to TASDEVICE_Checksum
- Remove enum control_bus as current code support SPI only.
- Remove device define as current code support TAS2781 only.
- Remove spi_device **spi_devs in structure tasdevice_priv.
- Remove cal_binaryname in structure tasdevice_priv.
- Remove ndev in structure tasdevice_priv.
- Change isacpi and isspi, replace by control_bus(I2C or SPI).
- Remove void tasdevice_spi_dsp_remove(void *context).
- Add acpi_device and irq in structure tas2781_hda in tas2781_hda_spi.c.
- Remove parameter chn in all of registers access functions.
- Add tascodec_spi_init().
- Add chip select gpio set for SPI device.
- Change tasdevice_tuning_switch() to tasdevice_spi_tuning_switch().
- Change device offset from tas_priv->ndev to tas_priv->index.
- Change tasdevice_dsp_remove() to tasdevice_spi_dsp_remove().
- tasdevice_prmg_load() to tasdevice_spi_prmg_load().
- Change tasdevice_config_info_remove() to tasdevice_spi_config_info_remove().
- Add one dummy byte shift when read from page 2~127, or not book 0.
- Change tasdevice_spi_change_chn_book() to tasdevice_spi_switch_book()
- Perform put_device(physdev) before error return.
- Change calibration data id to 2781 from 2783 in EFI
- Change calibration data structure name in comments.
- Remove file name in tas2781_spi_fwlib.c.
- Remove #include <linux/i2c.h> as it not needed in SPI mode.
- Change TAB to speace in micro define in tas2781_spi_fwlib.c.
- Change to up-case for DSP.
- Change all of multi-line comments format, empty first line.
- Change all of sizeof(struct xx) to sizeof(*xx).
- Remove Explicit casting for variables compare to avoid possible fault.
- Return directly without goto.
- Change 1 << xx to BIT(xx).
- Remove deviceNumber[] as current SPI device will support one device only.
- Add memory free before return error.
- Change "buf[offset]; offset += 1" to buf[offset++].
- Remove some debug information print.
- Change firmware binary to single device mode.
- Change all bexx_to_cpup() to get_unaligned_bexx().
- Remove ndev process as current SPI device support single device only.
- Remove chn and chnend for single device support only.
- Change all of registers read/write function, remove parameter chn.
- Create new function for single write, burst write, delay, field write in tasdevice_process_block().

---
 drivers/acpi/scan.c                           |    1 +
 .../platform/x86/serial-multi-instantiate.c   |   12 +
 sound/pci/hda/Kconfig                         |   14 +
 sound/pci/hda/Makefile                        |    2 +
 sound/pci/hda/patch_realtek.c                 |   13 +
 sound/pci/hda/tas2781-spi.h                   |  158 ++
 sound/pci/hda/tas2781_hda_spi.c               | 1317 ++++++++++
 sound/pci/hda/tas2781_spi_fwlib.c             | 2115 +++++++++++++++++
 8 files changed, 3632 insertions(+)
 create mode 100644 sound/pci/hda/tas2781-spi.h
 create mode 100644 sound/pci/hda/tas2781_hda_spi.c
 create mode 100644 sound/pci/hda/tas2781_spi_fwlib.c
drivers/acpi/scan.c +1 -0
index 59771412686b..b1a8bf1043da 100644
@@ -1769,6 +1769,7 @@ static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
 		{"CSC3557", },
 		{"INT33FE", },
 		{"INT3515", },
+		{"TXNW2781", },
 		/* Non-conforming _HID for Cirrus Logic already released */
 		{"CLSA0100", },
 		{"CLSA0101", },
drivers/platform/x86/serial-multi-instantiate.c +12 -0
index 3be016cfe601..b15c819023d0 100644
@@ -368,6 +368,17 @@ static const struct smi_node cs35l57_hda = {
 	.bus_type = SMI_AUTO_DETECT,
 };
 
+static const struct smi_node tas2781_hda = {
+	.instances = {
+		{ "tas2781-hda", IRQ_RESOURCE_AUTO, 0 },
+		{ "tas2781-hda", IRQ_RESOURCE_AUTO, 0 },
+		{ "tas2781-hda", IRQ_RESOURCE_AUTO, 0 },
+		{ "tas2781-hda", IRQ_RESOURCE_AUTO, 0 },
+		{}
+	},
+	.bus_type = SMI_AUTO_DETECT,
+};
+
 /*
  * Note new device-ids must also be added to ignore_serial_bus_ids in
  * drivers/acpi/scan.c: acpi_device_enumeration_by_parent().
@@ -380,6 +391,7 @@ static const struct acpi_device_id smi_acpi_ids[] = {
 	{ "CSC3556", (unsigned long)&cs35l56_hda },
 	{ "CSC3557", (unsigned long)&cs35l57_hda },
 	{ "INT3515", (unsigned long)&int3515_data },
+	{ "TXNW2781", (unsigned long)&tas2781_hda },
 	/* Non-conforming _HID for Cirrus Logic already released */
 	{ "CLSA0100", (unsigned long)&cs35l41_hda },
 	{ "CLSA0101", (unsigned long)&cs35l41_hda },
sound/pci/hda/Kconfig +14 -0
index bb15a0248250..62cd9ba408e2 100644
@@ -206,6 +206,20 @@ config SND_HDA_SCODEC_TAS2781_I2C
 comment "Set to Y if you want auto-loading the side codec driver"
 	depends on SND_HDA=y && SND_HDA_SCODEC_TAS2781_I2C=m
 
+config SND_HDA_SCODEC_TAS2781_SPI
+	tristate "Build TAS2781 HD-audio side codec support for SPI Bus"
+	depends on SPI_MASTER
+	depends on ACPI
+	depends on EFI
+	depends on SND_SOC
+	select CRC32_SARWATE
+	help
+	  Say Y or M here to include TAS2781 SPI HD-audio side codec support
+	  in snd-hda-intel driver, such as ALC287.
+
+comment "Set to Y if you want auto-loading the side codec driver"
+	depends on SND_HDA=y && SND_HDA_SCODEC_TAS2781_SPI=m
+
 config SND_HDA_CODEC_REALTEK
 	tristate "Build Realtek HD-audio codec support"
 	select SND_HDA_GENERIC
sound/pci/hda/Makefile +2 -0
index 80210f845df2..210c406dfbc5 100644
@@ -40,6 +40,7 @@ snd-hda-scodec-cs35l56-spi-y :=	cs35l56_hda_spi.o
 snd-hda-cs-dsp-ctls-y :=	hda_cs_dsp_ctl.o
 snd-hda-scodec-component-y :=	hda_component.o
 snd-hda-scodec-tas2781-i2c-y :=	tas2781_hda_i2c.o
+snd-hda-scodec-tas2781-spi-y :=	tas2781_hda_spi.o tas2781_spi_fwlib.o
 
 # common driver
 obj-$(CONFIG_SND_HDA) := snd-hda-codec.o
@@ -72,6 +73,7 @@ obj-$(CONFIG_SND_HDA_SCODEC_CS35L56_SPI) += snd-hda-scodec-cs35l56-spi.o
 obj-$(CONFIG_SND_HDA_CS_DSP_CONTROLS) += snd-hda-cs-dsp-ctls.o
 obj-$(CONFIG_SND_HDA_SCODEC_COMPONENT) += snd-hda-scodec-component.o
 obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_I2C) += snd-hda-scodec-tas2781-i2c.o
+obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_SPI) += snd-hda-scodec-tas2781-spi.o
 
 # this must be the last entry after codec drivers;
 # otherwise the codec patches won't be hooked before the PCI probe
sound/pci/hda/patch_realtek.c +13 -0
index c3a86a99f8c6..51707270943a 100644
@@ -6924,6 +6924,11 @@ static void tas2781_fixup_i2c(struct hda_codec *cdc,
 	comp_generic_fixup(cdc, action, "i2c", "TIAS2781", "-%s:00", 1);
 }
 
+static void tas2781_fixup_spi(struct hda_codec *cdc, const struct hda_fixup *fix, int action)
+{
+	comp_generic_fixup(cdc, action, "spi", "TXNW2781", "-%s:00-tas2781-hda.%d", 2);
+}
+
 static void yoga7_14arb7_fixup_i2c(struct hda_codec *cdc,
 	const struct hda_fixup *fix, int action)
 {
@@ -7501,6 +7506,7 @@ enum {
 	ALC236_FIXUP_DELL_DUAL_CODECS,
 	ALC287_FIXUP_CS35L41_I2C_2_THINKPAD_ACPI,
 	ALC287_FIXUP_TAS2781_I2C,
+	ALC245_FIXUP_TAS2781_SPI_2,
 	ALC287_FIXUP_YOGA7_14ARB7_I2C,
 	ALC245_FIXUP_HP_MUTE_LED_COEFBIT,
 	ALC245_FIXUP_HP_X360_MUTE_LEDS,
@@ -9726,6 +9732,12 @@ static const struct hda_fixup alc269_fixups[] = {
 		.chained = true,
 		.chain_id = ALC285_FIXUP_THINKPAD_HEADSET_JACK,
 	},
+	[ALC245_FIXUP_TAS2781_SPI_2] = {
+		.type = HDA_FIXUP_FUNC,
+		.v.func = tas2781_fixup_spi,
+		.chained = true,
+		.chain_id = ALC285_FIXUP_HP_GPIO_LED,
+	},
 	[ALC287_FIXUP_YOGA7_14ARB7_I2C] = {
 		.type = HDA_FIXUP_FUNC,
 		.v.func = yoga7_14arb7_fixup_i2c,
@@ -10263,6 +10275,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
 	SND_PCI_QUIRK(0x103c, 0x8cdf, "HP SnowWhite", ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED),
 	SND_PCI_QUIRK(0x103c, 0x8ce0, "HP SnowWhite", ALC287_FIXUP_CS35L41_I2C_2_HP_GPIO_LED),
 	SND_PCI_QUIRK(0x103c, 0x8cf5, "HP ZBook Studio 16", ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED),
+	SND_PCI_QUIRK(0x103c, 0x8daa, "HP Gemtree", ALC245_FIXUP_TAS2781_SPI_2),
 	SND_PCI_QUIRK(0x1043, 0x103e, "ASUS X540SA", ALC256_FIXUP_ASUS_MIC),
 	SND_PCI_QUIRK(0x1043, 0x103f, "ASUS TX300", ALC282_FIXUP_ASUS_TX300),
 	SND_PCI_QUIRK(0x1043, 0x106d, "Asus K53BE", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
sound/pci/hda/tas2781-spi.h new file +158 -0

158 lines not on this page · raw message

sound/pci/hda/tas2781_hda_spi.c new file +1317 -0

1,317 lines not on this page · raw message

sound/pci/hda/tas2781_spi_fwlib.c new file +2114 -0

1,423 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.40.1

Part of the diff is not shown here. View the raw message.

#1 lore raw

Le 21/07/2024 à 16:22, Baojun Xu a écrit :

Quoted 26 lines

This patch was used to add TAS2781 devices on SPI support in sound/pci/hda. It use ACPI node descript about parameters of TAS2781 on SPI, it like:

     Scope (_SB.PC00.SPI0)
     {
         Device (GSPK)
         {
             Name (_HID, "TXNW2781")  // _HID: Hardware ID
             Method (_CRS, 0, NotSerialized)
             {
                 Name (RBUF, ResourceTemplate ()
                 {
                     SpiSerialBusV2 (...)
                     SpiSerialBusV2 (...)
                 }
             }
         }
     }

And in platform/x86/serial-multi-instantiate.c, those spi devices will be added into system as a single SPI device, so TAS2781 SPI driver will probe twice for every single SPI device. And driver will also parser mono DSP firmware binary and RCA binary for itself.
The code support Realtek as the primary codec.
In patch version-10, add multi devices firmware binary support, to compatble with windows driver, they can share same firmware binary.

Quoted 3 lines

---

Hi, a few nitpicks below, should they make sense and a v11 be sent.

Only one true question in tasdevice_load_block_kernel() about error handling.

CJ

...

Quoted 18 lines
sound/pci/hda/tas2781-spi.h new file +18 -0
+struct tasdevice_priv {
+	struct tasdevice_fw *cali_data_fmw;
+	struct tasdevice_rca rcabin;
+	struct tasdevice_fw *fmw;
+	struct gpio_desc *reset;
+	struct mutex codec_lock;
+	struct regmap *regmap;
+	struct device *dev;
+	struct tm tm;
+
+	const char *acpi_subsystem_id;
+	unsigned char crc8_lkp_tbl[CRC8_TABLE_SIZE];
+	unsigned char coef_binaryname[64];
+	unsigned char rca_binaryname[64];
+	unsigned char dev_name[32];
+
+	unsigned int err_code;
+	bool is_loading;

sound/pci/hda/tas2781-spi.h line 109

Quoted 10 lines
sound/pci/hda/tas2781-spi.h new file +10 -0
+	bool is_loaderr;
+	int cur_book;
+	int cur_prog;
+	int cur_conf;
+	int fw_state;
+	int index;
+	int irq;
+	void *codec;
+	bool force_fwload_status;
+	bool playback_started;

If these bool were moved with the other ones, it could avoid some holes in the structure.

Quoted 19 lines
sound/pci/hda/tas2781-spi.h new file +19 -0
+	unsigned int cali_data[CALIB_MAX];
+	unsigned int cali_reg_array[CALIB_MAX];
+
+	int (*fw_parse_variable_header)(struct tasdevice_priv *tas_priv,
+					const struct firmware *fmw,
+					int offset);
+	int (*fw_parse_program_data)(struct tasdevice_priv *tas_priv,
+				     struct tasdevice_fw *tas_fmw,
+				     const struct firmware *fmw, int offset);
+	int (*fw_parse_configuration_data)(struct tasdevice_priv *tas_priv,
+					   struct tasdevice_fw *tas_fmw,
+					   const struct firmware *fmw,
+					   int offset);
+	int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,
+				    struct tasdev_blk *block);
+
+	int (*save_calibration)(struct tasdevice_priv *tas_priv);
+	void (*apply_calibration)(struct tasdevice_priv *tas_priv);
+};

...

sound/pci/hda/tas2781_hda_spi.c line 110

Quoted 6 lines
sound/pci/hda/tas2781_hda_spi.c new file +6 -0
+struct tasdevice_table {
+	int reg;
+	unsigned char data[8];
+};
+
+static struct tasdevice_table tas2781_pre_reset_table[] = {

Nitpick: const? (I think that the compiler can guess it by its own)

sound/pci/hda/tas2781_hda_spi.c line 111

Quoted 1 line
sound/pci/hda/tas2781_hda_spi.c new file +1 -0
+	/* Values setting for pre-reset. */

Nitpick: Given the name of the array, is this comment useful?

sound/pci/hda/tas2781_hda_spi.c line 122

Quoted 11 lines
sound/pci/hda/tas2781_hda_spi.c new file +11 -0
+	{ TASDEVICE_REG(0x00, 0x00, 0x02), {0x01, 0x1a, },},
+	{ TASDEVICE_REG(0x00, 0x01, 0x37), {0x01, 0x3a, },},
+	{ TASDEVICE_REG(0x00, 0xfd, 0x0d), {0x01, 0x0d, },},
+	{ TASDEVICE_REG(0x00, 0xfd, 0x06), {0x01, 0xc1, },},
+	{ TASDEVICE_REG(0x00, 0x01, 0x19), {0x01, 0xe0, },},
+	{ TASDEVICE_REG(0x00, 0xfd, 0x0d), {0x01, 0x0d, },},
+	{ TASDEVICE_REG(0x00, 0xfd, 0x06), {0x01, 0xd5, },},
+	{ TASDEVICE_REG(0x00, 0x00, 0x00), {0x01, 0x00, },},
+};
+
+static struct tasdevice_table tas2781_post_reset_table[] = {

Same 2 comemnts

Quoted 8 lines
sound/pci/hda/tas2781_hda_spi.c new file +8 -0
+	/* Values setting for post-reset. */
+	{ TASDEVICE_REG(0x00, 0x01, 0x37), {0x01, 0x3a, },},
+	{ TASDEVICE_REG(0x00, 0xfd, 0x0d), {0x01, 0x0d, },},
+	{ TASDEVICE_REG(0x00, 0xfd, 0x06), {0x01, 0xc1, },},
+	{ TASDEVICE_REG(0x00, 0xfd, 0x06), {0x01, 0xd5, },},
+	{ TASDEVICE_REG(0x00, 0xfd, 0x0a), {0x01, 0x01, },},
+	{ TASDEVICE_REG(0x00, 0x00, 0x00), {0x01, 0x00, },},
+};

...

sound/pci/hda/tas2781_hda_spi.c line 821

Quoted 3 lines
sound/pci/hda/tas2781_hda_spi.c new file +3 -0
+static void tas2781_apply_calib(struct tasdevice_priv *tas_priv)
+{
+	int j, rc;

Nitpick: i is more usual. (same things apply in some other places)

Quoted 25 lines
sound/pci/hda/tas2781_hda_spi.c new file +25 -0
+
+	/*
+	 * If no calibration data exist in tasdevice_priv *tas_priv,
+	 * calibration apply will be ignored, and use default values
+	 * in firmware binary, which was loaded during firmware download.
+	 */
+	if (tas_priv->cali_data[0] == 0)
+		return;
+	/*
+	 * Calibration data was saved in tasdevice_priv *tas_priv as:
+	 * unsigned int cali_data[CALIB_MAX];
+	 * and every data (in 4 bytes) will be saved in register which in
+	 * book 0, and page number in page_array[], offset was saved in
+	 * rgno_array[].
+	 */
+	for (j = 0; j < CALIB_MAX; j++) {
+		rc = tasdevice_spi_dev_bulk_write(tas_priv,
+			tas_priv->cali_reg_array[j],
+			(unsigned char *)&tas_priv->cali_data[j], 4);
+		if (rc < 0)
+			dev_err(tas_priv->dev,
+				"chn %d calib %d bulk_wr err = %d\n",
+				tas_priv->index, j, rc);
+	}
+}

...

Quoted 14 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +14 -0
+/* Block process function. */
+static int tasdevice_load_block_kernel(
+	struct tasdevice_priv *tasdevice, struct tasdev_blk *block)
+{
+	const unsigned int blk_size = block->blk_size;
+	unsigned char *data = block->data;
+	unsigned int i, length;
+
+	for (i = 0, length = 0; i < block->nr_subblocks; i++) {
+		int rc = tasdevice_process_block(tasdevice, data + length,
+			block->dev_idx, blk_size - length);
+		if (rc < 0) {
+			dev_err(tasdevice->dev,
+				"%s: %u %u sublock write error\n",

sound/pci/hda/tas2781_spi_fwlib.c line 873

Quoted 10 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +10 -0
+				__func__, length, blk_size);
+			break;
+		}
+		length += rc;
+		if (blk_size < length) {
+			dev_err(tasdevice->dev, "%s: %u %u out of boundary\n",
+				__func__, length, blk_size);
+			break;
+		}
+	}

Should an error code be returned if we reach one of the break above?
This error code is checked by the callers, so it looks strange to me to always return 0.

Quoted 3 lines
sound/pci/hda/tas2781_hda_spi.c new file +3 -0
+
+	return 0;
+}

...

Quoted 5 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +5 -0
+/*
+ * Return Code:
+ * true -- the registers are in the inblock yram
+ * false -- the registers are NOT in the inblock yram
+ */

sound/pci/hda/tas2781_spi_fwlib.c line 1242

Quoted 10 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +10 -0
+static bool check_inblock_yram(struct tas_crc *cd, unsigned char book,
+	unsigned char page, unsigned char reg, unsigned char len)
+{
+	bool in = false;
+
+	if (book == TAS2781_YRAM_BOOK1 || book == TAS2781_YRAM_BOOK2)
+		in = check_inblock_yram_bk(cd, page, reg, len);
+
+	return in;
+}

Nitpick: Add a new line?
If you agree, several other places above also needs to be updated.

Quoted 1 line

+/* yram page check. */

...

Quoted 8 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +8 -0
+static int dspfw_default_callback(struct tasdevice_priv *tas_priv,
+	unsigned int drv_ver, unsigned int ppcver)
+{
+	int rc = 0;
+
+	if (drv_ver == 0x100) {
+		if (ppcver >= PPC3_VERSION) {
+			tas_priv->fw_parse_variable_header =

sound/pci/hda/tas2781_spi_fwlib.c line 1603

Quoted 10 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +10 -0
+				fw_parse_variable_header_kernel;
+			tas_priv->fw_parse_program_data =
+				fw_parse_program_data_kernel;
+			tas_priv->fw_parse_configuration_data =
+				fw_parse_configuration_data_kernel;
+			tas_priv->tasdevice_load_block =
+				tasdevice_load_block_kernel;
+		} else {
+			switch (ppcver) {
+			case 0x00:

if it was:

		} else (ppcver == 0x00) {
			...
		} else {
		}

it would save 1 level of tabulation.

Quoted 5 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +5 -0
+				tas_priv->fw_parse_variable_header =
+					fw_parse_variable_header_git;
+				tas_priv->fw_parse_program_data =
+					fw_parse_program_data;
+				tas_priv->fw_parse_configuration_data =

sound/pci/hda/tas2781_spi_fwlib.c line 1618

Quoted 10 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +10 -0
+					fw_parse_configuration_data;
+				tas_priv->tasdevice_load_block =
+					tasdevice_load_block;
+				break;
+			default:
+				dev_err(tas_priv->dev,
+					"%s: PPCVer must be 0x0 or 0x%02x",
+					__func__, PPC3_VERSION);
+				dev_err(tas_priv->dev, " Current:0x%02x\n",
+					ppcver);

Why spliting into 2 dev_err()?

sound/pci/hda/tas2781_spi_fwlib.c line 1626

Quoted 8 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +8 -0
+				rc = -EINVAL;
+				break;
+			}
+		}
+	} else {
+		dev_err(tas_priv->dev,
+			"DrvVer must be 0x0, 0x230 or above 0x230 ");
+		dev_err(tas_priv->dev, "current is 0x%02x\n", drv_ver);

Why spliting into 2 dev_err()?

The comment does not seem to match the test above (if (drv_ver == 0x100)).

Quoted 5 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +5 -0
+		rc = -EINVAL;
+	}
+
+	return rc;
+}

...

Quoted 58 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +58 -0
+/* DSP firmware program load function. */
+int tasdevice_spi_select_tuningprm_cfg(void *context, int prm_no,
+	int cfg_no, int rca_conf_no)
+{
+	struct tasdevice_priv *tas_priv = context;
+	struct tasdevice_rca *rca = &tas_priv->rcabin;
+	struct tasdevice_config_info **cfg_info = rca->cfg_info;
+	struct tasdevice_fw *tas_fmw = tas_priv->fmw;
+	struct tasdevice_prog *program;
+	struct tasdevice_config *conf;
+	int prog_status = 0;
+	int status;
+
+	if (!tas_fmw) {
+		dev_err(tas_priv->dev, "%s: Firmware is NULL\n", __func__);
+		return 0;
+	}
+
+	if (cfg_no >= tas_fmw->nr_configurations) {
+		dev_err(tas_priv->dev,
+			"%s: cfg(%d) is not in range of conf %u\n",
+			__func__, cfg_no, tas_fmw->nr_configurations);
+		return 0;
+	}
+
+	if (prm_no >= tas_fmw->nr_programs) {
+		dev_err(tas_priv->dev,
+			"%s: prm(%d) is not in range of Programs %u\n",
+			__func__, prm_no, tas_fmw->nr_programs);
+		return 0;
+	}
+
+	if (rca_conf_no >= rca->ncfgs ||
+	    rca_conf_no < 0 ||
+	    !cfg_info) {
+		dev_err(tas_priv->dev,
+			"conf_no:%d should be in range from 0 to %u\n",
+			rca_conf_no, rca->ncfgs-1);
+		return 0;
+	}
+
+	if (prm_no >= 0	&&
+	   (tas_priv->cur_prog != prm_no ||
+	    tas_priv->force_fwload_status)) {
+		tas_priv->cur_conf = -1;
+		tas_priv->is_loading = true;
+		prog_status++;
+	}
+
+	if (prog_status) {
+		program = &tas_fmw->programs[prm_no];
+		tasdevice_load_data(tas_priv, &program->dev_data);
+		if (tas_priv->is_loaderr == false &&
+		    tas_priv->is_loading == true) {
+			struct tasdevice_fw *cal_fmw =
+				tas_priv->cali_data_fmw;
+
+			if (cal_fmw) {

sound/pci/hda/tas2781_spi_fwlib.c line 2028

Quoted 10 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +10 -0
+				struct tasdevice_calibration
+					*cal = cal_fmw->calibrations;
+
+				if (cal)
+					load_calib_data(tas_priv,
+						&cal->dev_data);
+			}
+			tas_priv->cur_prog = prm_no;
+		}
+

Nitpick: Unneeded extra new line.

Quoted 20 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +20 -0
+	}
+
+	if (cfg_no &&
+	   (cfg_no != tas_priv->cur_conf) &&
+	   (tas_priv->is_loaderr == false)) {
+		status++;
+		tas_priv->is_loading = true;
+	} else {
+		tas_priv->is_loading = false;
+	}
+	if (status) {
+		conf = &tas_fmw->configs[cfg_no];
+		status = 0;
+		tasdevice_load_data(tas_priv, &conf->dev_data);
+		if (tas_priv->is_loaderr == true) {
+			status |= 1 << 4;
+		} else if (tas_priv->is_loaderr == false &&
+			   tas_priv->is_loading == true) {
+			tas_priv->cur_conf = cfg_no;
+		}

sound/pci/hda/tas2781_spi_fwlib.c line 2058

Quoted 10 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +10 -0
+	} else {
+		dev_dbg(tas_priv->dev, "%s: Unneeded loading dsp conf %d\n",
+			__func__, cfg_no);
+	}
+
+	return prog_status;
+}
+
+/* DSP firmware program load interface function. */
+int tasdevice_spi_prmg_load(void *context, int prm_no)

This always called with prm_no = 0 and the returned value is never checked/used.

Does it make sense to simplify things?

Quoted 20 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +20 -0
+{
+	struct tasdevice_priv *tas_priv = context;
+	struct tasdevice_fw *tas_fmw = tas_priv->fmw;
+	struct tasdevice_prog *program;
+	struct tasdevice_config *conf;
+	int prog_status = 0;
+
+	if (!tas_fmw) {
+		dev_err(tas_priv->dev, "%s: Firmware is NULL\n", __func__);
+		return 0;
+	}
+
+	if (prm_no >= tas_fmw->nr_programs) {
+		dev_err(tas_priv->dev,
+			"%s: prm(%d) is not in range of Programs %u\n",
+			__func__, prm_no, tas_fmw->nr_programs);
+		return 0;
+	}
+
+	if (prm_no >= 0) {

sound/pci/hda/tas2781_spi_fwlib.c line 2088

Quoted 10 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +10 -0
+		tas_priv->cur_conf = 0;
+		tas_priv->is_loading = true;
+		prog_status++;
+	}
+	if (prog_status) {
+		program = &tas_fmw->programs[prm_no];
+		tasdevice_load_data(tas_priv, &program->dev_data);
+		tas_priv->cur_prog = prm_no;
+	}
+	if (prog_status) {

Nitpick: Why testing again and not merging with the lines above?

Quoted 15 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +15 -0
+		conf = &tas_fmw->configs[tas_priv->cur_conf];
+		tasdevice_load_data(tas_priv, &conf->dev_data);
+	}
+
+	return prog_status;
+}
+
+/* DSP firmware program switch interface function. */
+void tasdevice_spi_tuning_switch(void *context, int state)
+{
+	struct tasdevice_priv *tas_priv = context;
+	int profile_cfg_id = tas_priv->rcabin.profile_cfg_id;
+
+	if (tas_priv->fw_state == TASDEVICE_DSP_FW_FAIL) {
+		dev_err(tas_priv->dev, "DSP bin file not loaded\n");

sound/pci/hda/tas2781_spi_fwlib.c line 2113

Quoted 10 lines
sound/pci/hda/tas2781_spi_fwlib.c new file +10 -0
+		return;
+	}
+
+	if (state == 0) {
+		tasdevice_spi_select_cfg_blk(tas_priv, profile_cfg_id,
+			TASDEVICE_BIN_BLK_PRE_POWER_UP);
+	} else {
+		tasdevice_spi_select_cfg_blk(tas_priv, profile_cfg_id,
+			TASDEVICE_BIN_BLK_PRE_SHUTDOWN);
+	}

Nitpick: { } could be dropped on both branch.

Quoted 1 line

+}