ALSA: hda: cs35l41: Tidyup code
Clean up and simplify cs35l41_hda_bind function Signed-off-by: Lucas Tanure <tanureal@opensource.cirrus.com> Link: https://lore.kernel.org/r/20220117160830.709403-6-tanureal@opensource.cirrus.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
a025df02ce
commit
8c286a0f97
4 changed files with 49 additions and 54 deletions
|
@ -1,6 +1,6 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
//
|
//
|
||||||
// cs35l41.c -- CS35l41 ALSA HDA audio driver
|
// CS35l41 ALSA HDA audio driver
|
||||||
//
|
//
|
||||||
// Copyright 2021 Cirrus Logic, Inc.
|
// Copyright 2021 Cirrus Logic, Inc.
|
||||||
//
|
//
|
||||||
|
@ -168,7 +168,6 @@ static void cs35l41_hda_playback_hook(struct device *dev, int action)
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
dev_warn(cs35l41->dev, "Failed to apply multi reg write: %d\n", ret);
|
dev_warn(cs35l41->dev, "Failed to apply multi reg write: %d\n", ret);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cs35l41_hda_channel_map(struct device *dev, unsigned int tx_num, unsigned int *tx_slot,
|
static int cs35l41_hda_channel_map(struct device *dev, unsigned int tx_num, unsigned int *tx_slot,
|
||||||
|
@ -185,20 +184,19 @@ static int cs35l41_hda_bind(struct device *dev, struct device *master, void *mas
|
||||||
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
|
struct cs35l41_hda *cs35l41 = dev_get_drvdata(dev);
|
||||||
struct hda_component *comps = master_data;
|
struct hda_component *comps = master_data;
|
||||||
|
|
||||||
if (comps && cs35l41->index >= 0 && cs35l41->index < HDA_MAX_COMPONENTS)
|
if (!comps || cs35l41->index < 0 || cs35l41->index >= HDA_MAX_COMPONENTS)
|
||||||
comps = &comps[cs35l41->index];
|
|
||||||
else
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (!comps->dev) {
|
comps = &comps[cs35l41->index];
|
||||||
|
if (comps->dev)
|
||||||
|
return -EBUSY;
|
||||||
|
|
||||||
comps->dev = dev;
|
comps->dev = dev;
|
||||||
strscpy(comps->name, dev_name(dev), sizeof(comps->name));
|
strscpy(comps->name, dev_name(dev), sizeof(comps->name));
|
||||||
comps->playback_hook = cs35l41_hda_playback_hook;
|
comps->playback_hook = cs35l41_hda_playback_hook;
|
||||||
comps->set_channel_map = cs35l41_hda_channel_map;
|
comps->set_channel_map = cs35l41_hda_channel_map;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -EBUSY;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cs35l41_hda_unbind(struct device *dev, struct device *master, void *master_data)
|
static void cs35l41_hda_unbind(struct device *dev, struct device *master, void *master_data)
|
||||||
|
@ -269,11 +267,7 @@ static int cs35l41_hda_apply_properties(struct cs35l41_hda *cs35l41,
|
||||||
cs35l41->reg_seq = &cs35l41_hda_reg_seq_ext_bst;
|
cs35l41->reg_seq = &cs35l41_hda_reg_seq_ext_bst;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, (unsigned int *)&hw_cfg->spk_pos);
|
return cs35l41_hda_channel_map(cs35l41->dev, 0, NULL, 1, (unsigned int *)&hw_cfg->spk_pos);
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41,
|
static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *cs35l41,
|
||||||
|
@ -282,7 +276,7 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
|
||||||
struct cs35l41_hda_hw_config *hw_cfg;
|
struct cs35l41_hda_hw_config *hw_cfg;
|
||||||
u32 values[HDA_MAX_COMPONENTS];
|
u32 values[HDA_MAX_COMPONENTS];
|
||||||
struct acpi_device *adev;
|
struct acpi_device *adev;
|
||||||
struct device *acpi_dev;
|
struct device *physdev;
|
||||||
char *property;
|
char *property;
|
||||||
size_t nval;
|
size_t nval;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
@ -293,11 +287,11 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
|
||||||
return ERR_PTR(-ENODEV);
|
return ERR_PTR(-ENODEV);
|
||||||
}
|
}
|
||||||
|
|
||||||
acpi_dev = get_device(acpi_get_first_physical_node(adev));
|
physdev = get_device(acpi_get_first_physical_node(adev));
|
||||||
acpi_dev_put(adev);
|
acpi_dev_put(adev);
|
||||||
|
|
||||||
property = "cirrus,dev-index";
|
property = "cirrus,dev-index";
|
||||||
ret = device_property_count_u32(acpi_dev, property);
|
ret = device_property_count_u32(physdev, property);
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
goto no_acpi_dsd;
|
goto no_acpi_dsd;
|
||||||
|
|
||||||
|
@ -307,7 +301,7 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
|
||||||
}
|
}
|
||||||
nval = ret;
|
nval = ret;
|
||||||
|
|
||||||
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
|
ret = device_property_read_u32_array(physdev, property, values, nval);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -324,7 +318,9 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No devm_ version as CLSA0100, in no_acpi_dsd case, can't use devm version */
|
/* To use the same release code for all laptop variants we can't use devm_ version of
|
||||||
|
* gpiod_get here, as CLSA010* don't have a fully functional bios with an _DSD node
|
||||||
|
*/
|
||||||
cs35l41->reset_gpio = fwnode_gpiod_get_index(&adev->fwnode, "reset", cs35l41->index,
|
cs35l41->reset_gpio = fwnode_gpiod_get_index(&adev->fwnode, "reset", cs35l41->index,
|
||||||
GPIOD_OUT_LOW, "cs35l41-reset");
|
GPIOD_OUT_LOW, "cs35l41-reset");
|
||||||
|
|
||||||
|
@ -335,46 +331,46 @@ static struct cs35l41_hda_hw_config *cs35l41_hda_read_acpi(struct cs35l41_hda *c
|
||||||
}
|
}
|
||||||
|
|
||||||
property = "cirrus,speaker-position";
|
property = "cirrus,speaker-position";
|
||||||
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
|
ret = device_property_read_u32_array(physdev, property, values, nval);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_free;
|
goto err_free;
|
||||||
hw_cfg->spk_pos = values[cs35l41->index];
|
hw_cfg->spk_pos = values[cs35l41->index];
|
||||||
|
|
||||||
property = "cirrus,gpio1-func";
|
property = "cirrus,gpio1-func";
|
||||||
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
|
ret = device_property_read_u32_array(physdev, property, values, nval);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_free;
|
goto err_free;
|
||||||
hw_cfg->gpio1_func = values[cs35l41->index];
|
hw_cfg->gpio1_func = values[cs35l41->index];
|
||||||
|
|
||||||
property = "cirrus,gpio2-func";
|
property = "cirrus,gpio2-func";
|
||||||
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
|
ret = device_property_read_u32_array(physdev, property, values, nval);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_free;
|
goto err_free;
|
||||||
hw_cfg->gpio2_func = values[cs35l41->index];
|
hw_cfg->gpio2_func = values[cs35l41->index];
|
||||||
|
|
||||||
property = "cirrus,boost-peak-milliamp";
|
property = "cirrus,boost-peak-milliamp";
|
||||||
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
|
ret = device_property_read_u32_array(physdev, property, values, nval);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
hw_cfg->bst_ipk = values[cs35l41->index];
|
hw_cfg->bst_ipk = values[cs35l41->index];
|
||||||
|
|
||||||
property = "cirrus,boost-ind-nanohenry";
|
property = "cirrus,boost-ind-nanohenry";
|
||||||
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
|
ret = device_property_read_u32_array(physdev, property, values, nval);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
hw_cfg->bst_ind = values[cs35l41->index];
|
hw_cfg->bst_ind = values[cs35l41->index];
|
||||||
|
|
||||||
property = "cirrus,boost-cap-microfarad";
|
property = "cirrus,boost-cap-microfarad";
|
||||||
ret = device_property_read_u32_array(acpi_dev, property, values, nval);
|
ret = device_property_read_u32_array(physdev, property, values, nval);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
hw_cfg->bst_cap = values[cs35l41->index];
|
hw_cfg->bst_cap = values[cs35l41->index];
|
||||||
|
|
||||||
put_device(acpi_dev);
|
put_device(physdev);
|
||||||
|
|
||||||
return hw_cfg;
|
return hw_cfg;
|
||||||
|
|
||||||
err_free:
|
err_free:
|
||||||
kfree(hw_cfg);
|
kfree(hw_cfg);
|
||||||
err:
|
err:
|
||||||
put_device(acpi_dev);
|
put_device(physdev);
|
||||||
dev_err(cs35l41->dev, "Failed property %s: %d\n", property, ret);
|
dev_err(cs35l41->dev, "Failed property %s: %d\n", property, ret);
|
||||||
|
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
|
@ -383,18 +379,18 @@ no_acpi_dsd:
|
||||||
/*
|
/*
|
||||||
* Device CLSA0100 doesn't have _DSD so a gpiod_get by the label reset won't work.
|
* Device CLSA0100 doesn't have _DSD so a gpiod_get by the label reset won't work.
|
||||||
* And devices created by i2c-multi-instantiate don't have their device struct pointing to
|
* And devices created by i2c-multi-instantiate don't have their device struct pointing to
|
||||||
* the correct fwnode, so acpi_dev must be used here
|
* the correct fwnode, so acpi_dev must be used here.
|
||||||
* And devm functions expect that the device requesting the resource has the correct
|
* And devm functions expect that the device requesting the resource has the correct
|
||||||
* fwnode
|
* fwnode.
|
||||||
*/
|
*/
|
||||||
if (strncmp(hid, "CLSA0100", 8) != 0)
|
if (strncmp(hid, "CLSA0100", 8) != 0)
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
|
|
||||||
/* check I2C address to assign the index */
|
/* check I2C address to assign the index */
|
||||||
cs35l41->index = id == 0x40 ? 0 : 1;
|
cs35l41->index = id == 0x40 ? 0 : 1;
|
||||||
cs35l41->reset_gpio = gpiod_get_index(acpi_dev, NULL, 0, GPIOD_OUT_HIGH);
|
cs35l41->reset_gpio = gpiod_get_index(physdev, NULL, 0, GPIOD_OUT_HIGH);
|
||||||
cs35l41->vspk_always_on = true;
|
cs35l41->vspk_always_on = true;
|
||||||
put_device(acpi_dev);
|
put_device(physdev);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -449,7 +445,8 @@ int cs35l41_hda_probe(struct device *dev, const char *device_name, int id, int i
|
||||||
|
|
||||||
ret = regmap_read(cs35l41->regmap, CS35L41_IRQ1_STATUS3, &int_sts);
|
ret = regmap_read(cs35l41->regmap, CS35L41_IRQ1_STATUS3, &int_sts);
|
||||||
if (ret || (int_sts & CS35L41_OTP_BOOT_ERR)) {
|
if (ret || (int_sts & CS35L41_OTP_BOOT_ERR)) {
|
||||||
dev_err(cs35l41->dev, "OTP Boot error\n");
|
dev_err(cs35l41->dev, "OTP Boot status %x error: %d\n",
|
||||||
|
int_sts & CS35L41_OTP_BOOT_ERR, ret);
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* SPDX-License-Identifier: GPL-2.0
|
/* SPDX-License-Identifier: GPL-2.0
|
||||||
*
|
*
|
||||||
* cs35l41_hda.h -- CS35L41 ALSA HDA audio driver
|
* CS35L41 ALSA HDA audio driver
|
||||||
*
|
*
|
||||||
* Copyright 2021 Cirrus Logic, Inc.
|
* Copyright 2021 Cirrus Logic, Inc.
|
||||||
*
|
*
|
||||||
|
|
|
@ -58,7 +58,6 @@ static struct i2c_driver cs35l41_i2c_driver = {
|
||||||
.probe = cs35l41_hda_i2c_probe,
|
.probe = cs35l41_hda_i2c_probe,
|
||||||
.remove = cs35l41_hda_i2c_remove,
|
.remove = cs35l41_hda_i2c_remove,
|
||||||
};
|
};
|
||||||
|
|
||||||
module_i2c_driver(cs35l41_i2c_driver);
|
module_i2c_driver(cs35l41_i2c_driver);
|
||||||
|
|
||||||
MODULE_DESCRIPTION("HDA CS35L41 driver");
|
MODULE_DESCRIPTION("HDA CS35L41 driver");
|
||||||
|
|
|
@ -55,7 +55,6 @@ static struct spi_driver cs35l41_spi_driver = {
|
||||||
.probe = cs35l41_hda_spi_probe,
|
.probe = cs35l41_hda_spi_probe,
|
||||||
.remove = cs35l41_hda_spi_remove,
|
.remove = cs35l41_hda_spi_remove,
|
||||||
};
|
};
|
||||||
|
|
||||||
module_spi_driver(cs35l41_spi_driver);
|
module_spi_driver(cs35l41_spi_driver);
|
||||||
|
|
||||||
MODULE_DESCRIPTION("HDA CS35L41 driver");
|
MODULE_DESCRIPTION("HDA CS35L41 driver");
|
||||||
|
|
Loading…
Add table
Reference in a new issue