Skip to content

Commit bf0f394

Browse files
miquelraynalLee Jones
authored andcommitted
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: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Lee Jones <lee.jones@linaro.org> Link: https://lore.kernel.org/r/20211015081506.933180-36-miquel.raynal@bootlin.com
1 parent 2a4e333 commit bf0f394

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎drivers/mfd/ti_am335x_tscadc.c‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ static void tscadc_idle_config(struct ti_tscadc_dev *tscadc)
105105
{
106106
unsigned int idleconfig;
107107

108-
idleconfig = STEPCONFIG_YNN | STEPCONFIG_INM_ADCREFM |
109-
STEPCONFIG_INP_ADCREFM | STEPCONFIG_YPN;
108+
idleconfig = STEPCONFIG_INM_ADCREFM | STEPCONFIG_INP_ADCREFM;
109+
if (ti_adc_with_touchscreen(tscadc))
110+
idleconfig |= STEPCONFIG_YNN | STEPCONFIG_YPN;
110111

111112
regmap_write(tscadc->regmap, REG_IDLECONFIG, idleconfig);
112113
}
@@ -140,12 +141,14 @@ static int ti_tscadc_probe(struct platform_device *pdev)
140141

141142
tscadc->data = of_device_get_match_data(&pdev->dev);
142143

143-
node = of_get_child_by_name(pdev->dev.of_node, "tsc");
144-
of_property_read_u32(node, "ti,wires", &tscmag_wires);
145-
of_property_read_u32(node, "ti,coordiante-readouts", &readouts);
146-
of_node_put(node);
147-
if (tscmag_wires)
148-
use_tsc = true;
144+
if (ti_adc_with_touchscreen(tscadc)) {
145+
node = of_get_child_by_name(pdev->dev.of_node, "tsc");
146+
of_property_read_u32(node, "ti,wires", &tscmag_wires);
147+
of_property_read_u32(node, "ti,coordiante-readouts", &readouts);
148+
of_node_put(node);
149+
if (tscmag_wires)
150+
use_tsc = true;
151+
}
149152

150153
node = of_get_child_by_name(pdev->dev.of_node, "adc");
151154
of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) {
@@ -225,13 +228,16 @@ static int ti_tscadc_probe(struct platform_device *pdev)
225228
* of the CTRL register but not the subsystem enable bit which must be
226229
* added manually when timely.
227230
*/
228-
tscadc->ctrl = CNTRLREG_TSC_STEPCONFIGWRT | CNTRLREG_STEPID;
229-
if (use_tsc) {
230-
tscadc->ctrl |= CNTRLREG_TSC_ENB;
231-
if (tscmag_wires == 5)
232-
tscadc->ctrl |= CNTRLREG_TSC_5WIRE;
233-
else
234-
tscadc->ctrl |= CNTRLREG_TSC_4WIRE;
231+
tscadc->ctrl = CNTRLREG_STEPID;
232+
if (ti_adc_with_touchscreen(tscadc)) {
233+
tscadc->ctrl |= CNTRLREG_TSC_STEPCONFIGWRT;
234+
if (use_tsc) {
235+
tscadc->ctrl |= CNTRLREG_TSC_ENB;
236+
if (tscmag_wires == 5)
237+
tscadc->ctrl |= CNTRLREG_TSC_5WIRE;
238+
else
239+
tscadc->ctrl |= CNTRLREG_TSC_4WIRE;
240+
}
235241
}
236242
regmap_write(tscadc->regmap, REG_CTRL, tscadc->ctrl);
237243

‎include/linux/mfd/ti_am335x_tscadc.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
177177
return *tscadc_dev;
178178
}
179179

180+
static inline bool ti_adc_with_touchscreen(struct ti_tscadc_dev *tscadc)
181+
{
182+
return of_device_is_compatible(tscadc->dev->of_node,
183+
"ti,am3359-tscadc");
184+
}
185+
180186
void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val);
181187
void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val);
182188
void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val);

0 commit comments

Comments
 (0)