Skip to content

Commit cb0fdd9

Browse files
rfvirgilgregkh
authored andcommitted
ASoC: cs42l42: Use device_property API instead of of_property
[ Upstream commit ab78322 ] 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>
1 parent ef9d007 commit cb0fdd9

1 file changed

Lines changed: 24 additions & 36 deletions

File tree

‎sound/soc/codecs/cs42l42.c‎

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
#include <linux/regmap.h>
2121
#include <linux/slab.h>
2222
#include <linux/platform_device.h>
23+
#include <linux/property.h>
2324
#include <linux/regulator/consumer.h>
2425
#include <linux/gpio/consumer.h>
25-
#include <linux/of.h>
26-
#include <linux/of_gpio.h>
2726
#include <linux/of_device.h>
2827
#include <sound/core.h>
2928
#include <sound/pcm.h>
@@ -1554,25 +1553,23 @@ static const unsigned int threshold_defaults[] = {
15541553
CS42L42_HS_DET_LEVEL_1
15551554
};
15561555

1557-
static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
1556+
static int cs42l42_handle_device_data(struct device *dev,
15581557
struct cs42l42_private *cs42l42)
15591558
{
1560-
struct device_node *np = i2c_client->dev.of_node;
15611559
unsigned int val;
1562-
unsigned int thresholds[CS42L42_NUM_BIASES];
1560+
u32 thresholds[CS42L42_NUM_BIASES];
15631561
int ret;
15641562
int i;
15651563

1566-
ret = of_property_read_u32(np, "cirrus,ts-inv", &val);
1567-
1564+
ret = device_property_read_u32(dev, "cirrus,ts-inv", &val);
15681565
if (!ret) {
15691566
switch (val) {
15701567
case CS42L42_TS_INV_EN:
15711568
case CS42L42_TS_INV_DIS:
15721569
cs42l42->ts_inv = val;
15731570
break;
15741571
default:
1575-
dev_err(&i2c_client->dev,
1572+
dev_err(dev,
15761573
"Wrong cirrus,ts-inv DT value %d\n",
15771574
val);
15781575
cs42l42->ts_inv = CS42L42_TS_INV_DIS;
@@ -1585,8 +1582,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
15851582
CS42L42_TS_INV_MASK,
15861583
(cs42l42->ts_inv << CS42L42_TS_INV_SHIFT));
15871584

1588-
ret = of_property_read_u32(np, "cirrus,ts-dbnc-rise", &val);
1589-
1585+
ret = device_property_read_u32(dev, "cirrus,ts-dbnc-rise", &val);
15901586
if (!ret) {
15911587
switch (val) {
15921588
case CS42L42_TS_DBNCE_0:
@@ -1600,7 +1596,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
16001596
cs42l42->ts_dbnc_rise = val;
16011597
break;
16021598
default:
1603-
dev_err(&i2c_client->dev,
1599+
dev_err(dev,
16041600
"Wrong cirrus,ts-dbnc-rise DT value %d\n",
16051601
val);
16061602
cs42l42->ts_dbnc_rise = CS42L42_TS_DBNCE_1000;
@@ -1614,8 +1610,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
16141610
(cs42l42->ts_dbnc_rise <<
16151611
CS42L42_TS_RISE_DBNCE_TIME_SHIFT));
16161612

1617-
ret = of_property_read_u32(np, "cirrus,ts-dbnc-fall", &val);
1618-
1613+
ret = device_property_read_u32(dev, "cirrus,ts-dbnc-fall", &val);
16191614
if (!ret) {
16201615
switch (val) {
16211616
case CS42L42_TS_DBNCE_0:
@@ -1629,7 +1624,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
16291624
cs42l42->ts_dbnc_fall = val;
16301625
break;
16311626
default:
1632-
dev_err(&i2c_client->dev,
1627+
dev_err(dev,
16331628
"Wrong cirrus,ts-dbnc-fall DT value %d\n",
16341629
val);
16351630
cs42l42->ts_dbnc_fall = CS42L42_TS_DBNCE_0;
@@ -1643,13 +1638,12 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
16431638
(cs42l42->ts_dbnc_fall <<
16441639
CS42L42_TS_FALL_DBNCE_TIME_SHIFT));
16451640

1646-
ret = of_property_read_u32(np, "cirrus,btn-det-init-dbnce", &val);
1647-
1641+
ret = device_property_read_u32(dev, "cirrus,btn-det-init-dbnce", &val);
16481642
if (!ret) {
16491643
if (val <= CS42L42_BTN_DET_INIT_DBNCE_MAX)
16501644
cs42l42->btn_det_init_dbnce = val;
16511645
else {
1652-
dev_err(&i2c_client->dev,
1646+
dev_err(dev,
16531647
"Wrong cirrus,btn-det-init-dbnce DT value %d\n",
16541648
val);
16551649
cs42l42->btn_det_init_dbnce =
@@ -1660,14 +1654,13 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
16601654
CS42L42_BTN_DET_INIT_DBNCE_DEFAULT;
16611655
}
16621656

1663-
ret = of_property_read_u32(np, "cirrus,btn-det-event-dbnce", &val);
1664-
1657+
ret = device_property_read_u32(dev, "cirrus,btn-det-event-dbnce", &val);
16651658
if (!ret) {
16661659
if (val <= CS42L42_BTN_DET_EVENT_DBNCE_MAX)
16671660
cs42l42->btn_det_event_dbnce = val;
16681661
else {
1669-
dev_err(&i2c_client->dev,
1670-
"Wrong cirrus,btn-det-event-dbnce DT value %d\n", val);
1662+
dev_err(dev,
1663+
"Wrong cirrus,btn-det-event-dbnce DT value %d\n", val);
16711664
cs42l42->btn_det_event_dbnce =
16721665
CS42L42_BTN_DET_EVENT_DBNCE_DEFAULT;
16731666
}
@@ -1676,28 +1669,25 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
16761669
CS42L42_BTN_DET_EVENT_DBNCE_DEFAULT;
16771670
}
16781671

1679-
ret = of_property_read_u32_array(np, "cirrus,bias-lvls",
1680-
(u32 *)thresholds, CS42L42_NUM_BIASES);
1681-
1672+
ret = device_property_read_u32_array(dev, "cirrus,bias-lvls",
1673+
thresholds, ARRAY_SIZE(thresholds));
16821674
if (!ret) {
16831675
for (i = 0; i < CS42L42_NUM_BIASES; i++) {
16841676
if (thresholds[i] <= CS42L42_HS_DET_LEVEL_MAX)
16851677
cs42l42->bias_thresholds[i] = thresholds[i];
16861678
else {
1687-
dev_err(&i2c_client->dev,
1688-
"Wrong cirrus,bias-lvls[%d] DT value %d\n", i,
1679+
dev_err(dev,
1680+
"Wrong cirrus,bias-lvls[%d] DT value %d\n", i,
16891681
thresholds[i]);
1690-
cs42l42->bias_thresholds[i] =
1691-
threshold_defaults[i];
1682+
cs42l42->bias_thresholds[i] = threshold_defaults[i];
16921683
}
16931684
}
16941685
} else {
16951686
for (i = 0; i < CS42L42_NUM_BIASES; i++)
16961687
cs42l42->bias_thresholds[i] = threshold_defaults[i];
16971688
}
16981689

1699-
ret = of_property_read_u32(np, "cirrus,hs-bias-ramp-rate", &val);
1700-
1690+
ret = device_property_read_u32(dev, "cirrus,hs-bias-ramp-rate", &val);
17011691
if (!ret) {
17021692
switch (val) {
17031693
case CS42L42_HSBIAS_RAMP_FAST_RISE_SLOW_FALL:
@@ -1717,7 +1707,7 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
17171707
cs42l42->hs_bias_ramp_time = CS42L42_HSBIAS_RAMP_TIME3;
17181708
break;
17191709
default:
1720-
dev_err(&i2c_client->dev,
1710+
dev_err(dev,
17211711
"Wrong cirrus,hs-bias-ramp-rate DT value %d\n",
17221712
val);
17231713
cs42l42->hs_bias_ramp_rate = CS42L42_HSBIAS_RAMP_SLOW;
@@ -1848,11 +1838,9 @@ static int cs42l42_i2c_probe(struct i2c_client *i2c_client,
18481838
(1 << CS42L42_ADC_PDN_SHIFT) |
18491839
(0 << CS42L42_PDN_ALL_SHIFT));
18501840

1851-
if (i2c_client->dev.of_node) {
1852-
ret = cs42l42_handle_device_data(i2c_client, cs42l42);
1853-
if (ret != 0)
1854-
goto err_disable;
1855-
}
1841+
ret = cs42l42_handle_device_data(&i2c_client->dev, cs42l42);
1842+
if (ret != 0)
1843+
goto err_disable;
18561844

18571845
/* Setup headset detection */
18581846
cs42l42_setup_hs_type_detect(cs42l42);

0 commit comments

Comments
 (0)