Commit bf0f394c authored by Miquel Raynal's avatar Miquel Raynal Committed by Lee Jones

mfd: ti_am335x_tscadc: Introduce a helper to deal with the type of hardware

One way of knowing which hardware we are dealing with is to check the
compatible string. When this must be done at several places, it's best
and certainly more clear to use a helper for that.

Introduce ti_adc_with_touchscreen() to indicate if there is a touchscreen
controller available (meaning it's an am33xx-like ADC). This helper does
not indicate if it is actually used (that is the purpose of the use_tsc
boolean).

Introducing this helper helps making a difference in the code between
what is generic to both types of ADCs and what is specific to the am33xx
hardware before introducing support for the am437x hardware.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/20211015081506.933180-36-miquel.raynal@bootlin.com
parent 2a4e333a
...@@ -105,8 +105,9 @@ static void tscadc_idle_config(struct ti_tscadc_dev *tscadc) ...@@ -105,8 +105,9 @@ static void tscadc_idle_config(struct ti_tscadc_dev *tscadc)
{ {
unsigned int idleconfig; unsigned int idleconfig;
idleconfig = STEPCONFIG_YNN | STEPCONFIG_INM_ADCREFM | idleconfig = STEPCONFIG_INM_ADCREFM | STEPCONFIG_INP_ADCREFM;
STEPCONFIG_INP_ADCREFM | STEPCONFIG_YPN; if (ti_adc_with_touchscreen(tscadc))
idleconfig |= STEPCONFIG_YNN | STEPCONFIG_YPN;
regmap_write(tscadc->regmap, REG_IDLECONFIG, idleconfig); regmap_write(tscadc->regmap, REG_IDLECONFIG, idleconfig);
} }
...@@ -140,12 +141,14 @@ static int ti_tscadc_probe(struct platform_device *pdev) ...@@ -140,12 +141,14 @@ static int ti_tscadc_probe(struct platform_device *pdev)
tscadc->data = of_device_get_match_data(&pdev->dev); tscadc->data = of_device_get_match_data(&pdev->dev);
if (ti_adc_with_touchscreen(tscadc)) {
node = of_get_child_by_name(pdev->dev.of_node, "tsc"); node = of_get_child_by_name(pdev->dev.of_node, "tsc");
of_property_read_u32(node, "ti,wires", &tscmag_wires); of_property_read_u32(node, "ti,wires", &tscmag_wires);
of_property_read_u32(node, "ti,coordiante-readouts", &readouts); of_property_read_u32(node, "ti,coordiante-readouts", &readouts);
of_node_put(node); of_node_put(node);
if (tscmag_wires) if (tscmag_wires)
use_tsc = true; use_tsc = true;
}
node = of_get_child_by_name(pdev->dev.of_node, "adc"); node = of_get_child_by_name(pdev->dev.of_node, "adc");
of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) { of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) {
...@@ -225,7 +228,9 @@ static int ti_tscadc_probe(struct platform_device *pdev) ...@@ -225,7 +228,9 @@ static int ti_tscadc_probe(struct platform_device *pdev)
* of the CTRL register but not the subsystem enable bit which must be * of the CTRL register but not the subsystem enable bit which must be
* added manually when timely. * added manually when timely.
*/ */
tscadc->ctrl = CNTRLREG_TSC_STEPCONFIGWRT | CNTRLREG_STEPID; tscadc->ctrl = CNTRLREG_STEPID;
if (ti_adc_with_touchscreen(tscadc)) {
tscadc->ctrl |= CNTRLREG_TSC_STEPCONFIGWRT;
if (use_tsc) { if (use_tsc) {
tscadc->ctrl |= CNTRLREG_TSC_ENB; tscadc->ctrl |= CNTRLREG_TSC_ENB;
if (tscmag_wires == 5) if (tscmag_wires == 5)
...@@ -233,6 +238,7 @@ static int ti_tscadc_probe(struct platform_device *pdev) ...@@ -233,6 +238,7 @@ static int ti_tscadc_probe(struct platform_device *pdev)
else else
tscadc->ctrl |= CNTRLREG_TSC_4WIRE; tscadc->ctrl |= CNTRLREG_TSC_4WIRE;
} }
}
regmap_write(tscadc->regmap, REG_CTRL, tscadc->ctrl); regmap_write(tscadc->regmap, REG_CTRL, tscadc->ctrl);
tscadc_idle_config(tscadc); tscadc_idle_config(tscadc);
......
...@@ -177,6 +177,12 @@ static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p) ...@@ -177,6 +177,12 @@ static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
return *tscadc_dev; return *tscadc_dev;
} }
static inline bool ti_adc_with_touchscreen(struct ti_tscadc_dev *tscadc)
{
return of_device_is_compatible(tscadc->dev->of_node,
"ti,am3359-tscadc");
}
void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val); void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val);
void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val); void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val);
void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val); void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment