Skip to content

Commit f0b1643

Browse files
Marek Beliskojic23
authored andcommitted
iio:adc:palmas: add DT support
Code was found at: https://android.googlesource.com/kernel/tegra/+/a90856a6626d502d42c6e7abccbdf9d730b36270%5E%21/#F1 Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Signed-off-by: Marek Belisko <marek@goldelico.com> [Fixed minor typos + add channels list to documentation] Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent e08e19c commit f0b1643

File tree

2 files changed

+95
-5
lines changed

2 files changed

+95
-5
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
* Palmas general purpose ADC IP block devicetree bindings
2+
3+
Channels list:
4+
0 battery type
5+
1 battery temp NTC (optional current source)
6+
2 GP
7+
3 temp (with ext. diode, optional current source)
8+
4 GP
9+
5 GP
10+
6 VBAT_SENSE
11+
7 VCC_SENSE
12+
8 Backup Battery voltage
13+
9 external charger (VCHG)
14+
10 VBUS
15+
11 DC-DC current probe (how does this work?)
16+
12 internal die temp
17+
13 internal die temp
18+
14 USB ID pin voltage
19+
15 test network
20+
21+
Required properties:
22+
- compatible : Must be "ti,palmas-gpadc".
23+
- #io-channel-cells: Should be set to <1>.
24+
25+
Optional sub-nodes:
26+
ti,channel0-current-microamp: Channel 0 current in uA.
27+
Values are rounded to derive 0uA, 5uA, 15uA, 20uA.
28+
ti,channel3-current-microamp: Channel 3 current in uA.
29+
Values are rounded to derive 0uA, 10uA, 400uA, 800uA.
30+
ti,enable-extended-delay: Enable extended delay.
31+
32+
Example:
33+
34+
pmic {
35+
compatible = "ti,twl6035-pmic", "ti,palmas-pmic";
36+
...
37+
gpadc {
38+
compatible = "ti,palmas-gpadc";
39+
interrupts = <18 0
40+
16 0
41+
17 0>;
42+
#io-channel-cells = <1>;
43+
ti,channel0-current-microamp = <5>;
44+
ti,channel3-current-microamp = <10>;
45+
};
46+
};
47+
...
48+
};

drivers/iio/adc/palmas_gpadc.c

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/pm.h>
2222
#include <linux/mfd/palmas.h>
2323
#include <linux/completion.h>
24+
#include <linux/of.h>
25+
#include <linux/of_device.h>
2426
#include <linux/iio/iio.h>
2527
#include <linux/iio/machine.h>
2628
#include <linux/iio/driver.h>
@@ -460,6 +462,34 @@ static const struct iio_chan_spec palmas_gpadc_iio_channel[] = {
460462
PALMAS_ADC_CHAN_IIO(IN15, IIO_VOLTAGE, IIO_CHAN_INFO_PROCESSED),
461463
};
462464

465+
static int palmas_gpadc_get_adc_dt_data(struct platform_device *pdev,
466+
struct palmas_gpadc_platform_data **gpadc_pdata)
467+
{
468+
struct device_node *np = pdev->dev.of_node;
469+
struct palmas_gpadc_platform_data *gp_data;
470+
int ret;
471+
u32 pval;
472+
473+
gp_data = devm_kzalloc(&pdev->dev, sizeof(*gp_data), GFP_KERNEL);
474+
if (!gp_data)
475+
return -ENOMEM;
476+
477+
ret = of_property_read_u32(np, "ti,channel0-current-microamp", &pval);
478+
if (!ret)
479+
gp_data->ch0_current = pval;
480+
481+
ret = of_property_read_u32(np, "ti,channel3-current-microamp", &pval);
482+
if (!ret)
483+
gp_data->ch3_current = pval;
484+
485+
gp_data->extended_delay = of_property_read_bool(np,
486+
"ti,enable-extended-delay");
487+
488+
*gpadc_pdata = gp_data;
489+
490+
return 0;
491+
}
492+
463493
static int palmas_gpadc_probe(struct platform_device *pdev)
464494
{
465495
struct palmas_gpadc *adc;
@@ -469,12 +499,17 @@ static int palmas_gpadc_probe(struct platform_device *pdev)
469499
int ret, i;
470500

471501
pdata = dev_get_platdata(pdev->dev.parent);
472-
if (!pdata || !pdata->gpadc_pdata) {
473-
dev_err(&pdev->dev, "No platform data\n");
474-
return -ENODEV;
475-
}
476502

477-
gpadc_pdata = pdata->gpadc_pdata;
503+
if (pdata && pdata->gpadc_pdata)
504+
gpadc_pdata = pdata->gpadc_pdata;
505+
506+
if (!gpadc_pdata && pdev->dev.of_node) {
507+
ret = palmas_gpadc_get_adc_dt_data(pdev, &gpadc_pdata);
508+
if (ret < 0)
509+
return ret;
510+
}
511+
if (!gpadc_pdata)
512+
return -EINVAL;
478513

479514
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc));
480515
if (!indio_dev) {
@@ -790,12 +825,19 @@ static const struct dev_pm_ops palmas_pm_ops = {
790825
palmas_gpadc_resume)
791826
};
792827

828+
static const struct of_device_id of_palmas_gpadc_match_tbl[] = {
829+
{ .compatible = "ti,palmas-gpadc", },
830+
{ /* end */ }
831+
};
832+
MODULE_DEVICE_TABLE(of, of_palmas_gpadc_match_tbl);
833+
793834
static struct platform_driver palmas_gpadc_driver = {
794835
.probe = palmas_gpadc_probe,
795836
.remove = palmas_gpadc_remove,
796837
.driver = {
797838
.name = MOD_NAME,
798839
.pm = &palmas_pm_ops,
840+
.of_match_table = of_palmas_gpadc_match_tbl,
799841
},
800842
};
801843

0 commit comments

Comments
 (0)