ASoC: cs42l42: Use device_property API instead of of_property
[ Upstream commit ab78322a0dc8e5e472ff66ac7e18c94acc17587f ] Use the device_property APIs so that the code will work on devicetree and ACPI systems. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Signed-off-by: Lucas Tanure <tanureal@opensource.cirrus.com> Link: https://lore.kernel.org/r/20210426155303.853236-2-tanureal@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
ef9d007a91
commit
cb0fdd9aae
@@ -20,10 +20,9 @@
|
|||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
|
#include <linux/property.h>
|
||||||
#include <linux/regulator/consumer.h>
|
#include <linux/regulator/consumer.h>
|
||||||
#include <linux/gpio/consumer.h>
|
#include <linux/gpio/consumer.h>
|
||||||
#include <linux/of.h>
|
|
||||||
#include <linux/of_gpio.h>
|
|
||||||
#include <linux/of_device.h>
|
#include <linux/of_device.h>
|
||||||
#include <sound/core.h>
|
#include <sound/core.h>
|
||||||
#include <sound/pcm.h>
|
#include <sound/pcm.h>
|
||||||
@@ -1554,17 +1553,15 @@ static const unsigned int threshold_defaults[] = {
|
|||||||
CS42L42_HS_DET_LEVEL_1
|
CS42L42_HS_DET_LEVEL_1
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
static int cs42l42_handle_device_data(struct device *dev,
|
||||||
struct cs42l42_private *cs42l42)
|
struct cs42l42_private *cs42l42)
|
||||||
{
|
{
|
||||||
struct device_node *np = i2c_client->dev.of_node;
|
|
||||||
unsigned int val;
|
unsigned int val;
|
||||||
unsigned int thresholds[CS42L42_NUM_BIASES];
|
u32 thresholds[CS42L42_NUM_BIASES];
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "cirrus,ts-inv", &val);
|
ret = device_property_read_u32(dev, "cirrus,ts-inv", &val);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case CS42L42_TS_INV_EN:
|
case CS42L42_TS_INV_EN:
|
||||||
@@ -1572,7 +1569,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
cs42l42->ts_inv = val;
|
cs42l42->ts_inv = val;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(&i2c_client->dev,
|
dev_err(dev,
|
||||||
"Wrong cirrus,ts-inv DT value %d\n",
|
"Wrong cirrus,ts-inv DT value %d\n",
|
||||||
val);
|
val);
|
||||||
cs42l42->ts_inv = CS42L42_TS_INV_DIS;
|
cs42l42->ts_inv = CS42L42_TS_INV_DIS;
|
||||||
@@ -1585,8 +1582,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
CS42L42_TS_INV_MASK,
|
CS42L42_TS_INV_MASK,
|
||||||
(cs42l42->ts_inv << CS42L42_TS_INV_SHIFT));
|
(cs42l42->ts_inv << CS42L42_TS_INV_SHIFT));
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "cirrus,ts-dbnc-rise", &val);
|
ret = device_property_read_u32(dev, "cirrus,ts-dbnc-rise", &val);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case CS42L42_TS_DBNCE_0:
|
case CS42L42_TS_DBNCE_0:
|
||||||
@@ -1600,7 +1596,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
cs42l42->ts_dbnc_rise = val;
|
cs42l42->ts_dbnc_rise = val;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(&i2c_client->dev,
|
dev_err(dev,
|
||||||
"Wrong cirrus,ts-dbnc-rise DT value %d\n",
|
"Wrong cirrus,ts-dbnc-rise DT value %d\n",
|
||||||
val);
|
val);
|
||||||
cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000;
|
cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000;
|
||||||
@@ -1614,8 +1610,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
(cs42l42->ts_dbnc_rise <<
|
(cs42l42->ts_dbnc_rise <<
|
||||||
CS42L42_TS_RISE_DBNCE_TIME_SHIFT));
|
CS42L42_TS_RISE_DBNCE_TIME_SHIFT));
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "cirrus,ts-dbnc-fall", &val);
|
ret = device_property_read_u32(dev, "cirrus,ts-dbnc-fall", &val);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case CS42L42_TS_DBNCE_0:
|
case CS42L42_TS_DBNCE_0:
|
||||||
@@ -1629,7 +1624,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
cs42l42->ts_dbnc_fall = val;
|
cs42l42->ts_dbnc_fall = val;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(&i2c_client->dev,
|
dev_err(dev,
|
||||||
"Wrong cirrus,ts-dbnc-fall DT value %d\n",
|
"Wrong cirrus,ts-dbnc-fall DT value %d\n",
|
||||||
val);
|
val);
|
||||||
cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0;
|
cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0;
|
||||||
@@ -1643,13 +1638,12 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
(cs42l42->ts_dbnc_fall <<
|
(cs42l42->ts_dbnc_fall <<
|
||||||
CS42L42_TS_FALL_DBNCE_TIME_SHIFT));
|
CS42L42_TS_FALL_DBNCE_TIME_SHIFT));
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "cirrus,btn-det-init-dbnce", &val);
|
ret = device_property_read_u32(dev, "cirrus,btn-det-init-dbnce", &val);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
if (val <= CS42L42_BTN_DET_INIT_DBNCE_MAX)
|
if (val <= CS42L42_BTN_DET_INIT_DBNCE_MAX)
|
||||||
cs42l42->btn_det_init_dbnce = val;
|
cs42l42->btn_det_init_dbnce = val;
|
||||||
else {
|
else {
|
||||||
dev_err(&i2c_client->dev,
|
dev_err(dev,
|
||||||
"Wrong cirrus,btn-det-init-dbnce DT value %d\n",
|
"Wrong cirrus,btn-det-init-dbnce DT value %d\n",
|
||||||
val);
|
val);
|
||||||
cs42l42->btn_det_init_dbnce =
|
cs42l42->btn_det_init_dbnce =
|
||||||
@@ -1660,14 +1654,13 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
CS42L42_BTN_DET_INIT_DBNCE_DEFAULT;
|
CS42L42_BTN_DET_INIT_DBNCE_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "cirrus,btn-det-event-dbnce", &val);
|
ret = device_property_read_u32(dev, "cirrus,btn-det-event-dbnce", &val);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
if (val <= CS42L42_BTN_DET_EVENT_DBNCE_MAX)
|
if (val <= CS42L42_BTN_DET_EVENT_DBNCE_MAX)
|
||||||
cs42l42->btn_det_event_dbnce = val;
|
cs42l42->btn_det_event_dbnce = val;
|
||||||
else {
|
else {
|
||||||
dev_err(&i2c_client->dev,
|
dev_err(dev,
|
||||||
"Wrong cirrus,btn-det-event-dbnce DT value %d\n", val);
|
"Wrong cirrus,btn-det-event-dbnce DT value %d\n", val);
|
||||||
cs42l42->btn_det_event_dbnce =
|
cs42l42->btn_det_event_dbnce =
|
||||||
CS42L42_BTN_DET_EVENT_DBNCE_DEFAULT;
|
CS42L42_BTN_DET_EVENT_DBNCE_DEFAULT;
|
||||||
}
|
}
|
||||||
@@ -1676,19 +1669,17 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
CS42L42_BTN_DET_EVENT_DBNCE_DEFAULT;
|
CS42L42_BTN_DET_EVENT_DBNCE_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = of_property_read_u32_array(np, "cirrus,bias-lvls",
|
ret = device_property_read_u32_array(dev, "cirrus,bias-lvls",
|
||||||
(u32 *)thresholds, CS42L42_NUM_BIASES);
|
thresholds, ARRAY_SIZE(thresholds));
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
for (i = 0; i < CS42L42_NUM_BIASES; i++) {
|
for (i = 0; i < CS42L42_NUM_BIASES; i++) {
|
||||||
if (thresholds[i] <= CS42L42_HS_DET_LEVEL_MAX)
|
if (thresholds[i] <= CS42L42_HS_DET_LEVEL_MAX)
|
||||||
cs42l42->bias_thresholds[i] = thresholds[i];
|
cs42l42->bias_thresholds[i] = thresholds[i];
|
||||||
else {
|
else {
|
||||||
dev_err(&i2c_client->dev,
|
dev_err(dev,
|
||||||
"Wrong cirrus,bias-lvls[%d] DT value %d\n", i,
|
"Wrong cirrus,bias-lvls[%d] DT value %d\n", i,
|
||||||
thresholds[i]);
|
thresholds[i]);
|
||||||
cs42l42->bias_thresholds[i] =
|
cs42l42->bias_thresholds[i] = threshold_defaults[i];
|
||||||
threshold_defaults[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1696,8 +1687,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
cs42l42->bias_thresholds[i] = threshold_defaults[i];
|
cs42l42->bias_thresholds[i] = threshold_defaults[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "cirrus,hs-bias-ramp-rate", &val);
|
ret = device_property_read_u32(dev, "cirrus,hs-bias-ramp-rate", &val);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case CS42L42_HSBIAS_RAMP_FAST_RISE_SLOW_FALL:
|
case CS42L42_HSBIAS_RAMP_FAST_RISE_SLOW_FALL:
|
||||||
@@ -1717,7 +1707,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
|
|||||||
cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME3;
|
cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME3;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
dev_err(&i2c_client->dev,
|
dev_err(dev,
|
||||||
"Wrong cirrus,hs-bias-ramp-rate DT value %d\n",
|
"Wrong cirrus,hs-bias-ramp-rate DT value %d\n",
|
||||||
val);
|
val);
|
||||||
cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW;
|
cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW;
|
||||||
@@ -1848,11 +1838,9 @@ static int cs42l42_i2c_probe(struct i2c_client *i2c_client,
|
|||||||
(1 << CS42L42_ADC_PDN_SHIFT) |
|
(1 << CS42L42_ADC_PDN_SHIFT) |
|
||||||
(0 << CS42L42_PDN_ALL_SHIFT));
|
(0 << CS42L42_PDN_ALL_SHIFT));
|
||||||
|
|
||||||
if (i2c_client->dev.of_node) {
|
ret = cs42l42_handle_device_data(&i2c_client->dev, cs42l42);
|
||||||
ret = cs42l42_handle_device_data(i2c_client, cs42l42);
|
if (ret != 0)
|
||||||
if (ret != 0)
|
goto err_disable;
|
||||||
goto err_disable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Setup headset detection */
|
/* Setup headset detection */
|
||||||
cs42l42_setup_hs_type_detect(cs42l42);
|
cs42l42_setup_hs_type_detect(cs42l42);
|
||||||
|
Reference in New Issue
Block a user