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

mfd: ti_am335x_tscadc: Use driver data

So far every sub-cell parameter in this driver was hardcoded: cell name,
cell compatible, specific clock name and desired clock frequency.

As we are about to introduce support for ADC1/magnetic reader, we need a
bit of flexibility. Let's add a driver data structure which will contain
these information.
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-18-miquel.raynal@bootlin.com
parent 61479479
...@@ -137,6 +137,8 @@ static int ti_tscadc_probe(struct platform_device *pdev) ...@@ -137,6 +137,8 @@ static int ti_tscadc_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
tscadc->data = of_device_get_match_data(&pdev->dev);
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", &tsc_wires); of_property_read_u32(node, "ti,wires", &tsc_wires);
of_property_read_u32(node, "ti,coordiante-readouts", &readouts); of_property_read_u32(node, "ti,coordiante-readouts", &readouts);
...@@ -212,7 +214,7 @@ static int ti_tscadc_probe(struct platform_device *pdev) ...@@ -212,7 +214,7 @@ static int ti_tscadc_probe(struct platform_device *pdev)
goto err_disable_clk; goto err_disable_clk;
} }
tscadc->clk_div = (clk_get_rate(clk) / ADC_CLK) - 1; tscadc->clk_div = (clk_get_rate(clk) / tscadc->data->target_clk_rate) - 1;
regmap_write(tscadc->regmap, REG_CLKDIV, tscadc->clk_div); regmap_write(tscadc->regmap, REG_CLKDIV, tscadc->clk_div);
/* Set the control register bits */ /* Set the control register bits */
...@@ -241,8 +243,8 @@ static int ti_tscadc_probe(struct platform_device *pdev) ...@@ -241,8 +243,8 @@ static int ti_tscadc_probe(struct platform_device *pdev)
if (tsc_wires > 0) { if (tsc_wires > 0) {
tscadc->tsc_cell = tscadc->used_cells; tscadc->tsc_cell = tscadc->used_cells;
cell = &tscadc->cells[tscadc->used_cells++]; cell = &tscadc->cells[tscadc->used_cells++];
cell->name = "TI-am335x-tsc"; cell->name = tscadc->data->secondary_feature_name;
cell->of_compatible = "ti,am3359-tsc"; cell->of_compatible = tscadc->data->secondary_feature_compatible;
cell->platform_data = &tscadc; cell->platform_data = &tscadc;
cell->pdata_size = sizeof(tscadc); cell->pdata_size = sizeof(tscadc);
} }
...@@ -251,8 +253,8 @@ static int ti_tscadc_probe(struct platform_device *pdev) ...@@ -251,8 +253,8 @@ static int ti_tscadc_probe(struct platform_device *pdev)
if (adc_channels > 0) { if (adc_channels > 0) {
tscadc->adc_cell = tscadc->used_cells; tscadc->adc_cell = tscadc->used_cells;
cell = &tscadc->cells[tscadc->used_cells++]; cell = &tscadc->cells[tscadc->used_cells++];
cell->name = "TI-am335x-adc"; cell->name = tscadc->data->adc_feature_name;
cell->of_compatible = "ti,am3359-adc"; cell->of_compatible = tscadc->data->adc_feature_compatible;
cell->platform_data = &tscadc; cell->platform_data = &tscadc;
cell->pdata_size = sizeof(tscadc); cell->pdata_size = sizeof(tscadc);
} }
...@@ -338,8 +340,16 @@ static int __maybe_unused tscadc_resume(struct device *dev) ...@@ -338,8 +340,16 @@ static int __maybe_unused tscadc_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(tscadc_pm_ops, tscadc_suspend, tscadc_resume); static SIMPLE_DEV_PM_OPS(tscadc_pm_ops, tscadc_suspend, tscadc_resume);
static const struct ti_tscadc_data tscdata = {
.adc_feature_name = "TI-am335x-adc",
.adc_feature_compatible = "ti,am3359-adc",
.secondary_feature_name = "TI-am335x-tsc",
.secondary_feature_compatible = "ti,am3359-tsc",
.target_clk_rate = ADC_CLK,
};
static const struct of_device_id ti_tscadc_dt_ids[] = { static const struct of_device_id ti_tscadc_dt_ids[] = {
{ .compatible = "ti,am3359-tscadc", }, { .compatible = "ti,am3359-tscadc", .data = &tscdata },
{ } { }
}; };
MODULE_DEVICE_TABLE(of, ti_tscadc_dt_ids); MODULE_DEVICE_TABLE(of, ti_tscadc_dt_ids);
......
...@@ -162,11 +162,20 @@ ...@@ -162,11 +162,20 @@
#define TSCADC_CELLS 2 #define TSCADC_CELLS 2
struct ti_tscadc_data {
char *adc_feature_name;
char *adc_feature_compatible;
char *secondary_feature_name;
char *secondary_feature_compatible;
unsigned int target_clk_rate;
};
struct ti_tscadc_dev { struct ti_tscadc_dev {
struct device *dev; struct device *dev;
struct regmap *regmap; struct regmap *regmap;
void __iomem *tscadc_base; void __iomem *tscadc_base;
phys_addr_t tscadc_phys_base; phys_addr_t tscadc_phys_base;
const struct ti_tscadc_data *data;
int irq; int irq;
int used_cells; /* 1-2 */ int used_cells; /* 1-2 */
int tsc_wires; int tsc_wires;
......
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