Commit 24d5c82f authored by Pantelis Antoniou's avatar Pantelis Antoniou Committed by Sebastian Andrzej Siewior
Browse files

mfd: ti_tscadc: deal with partial activation



Fix the mfd device in the case where a subdevice might not be activated.

Signed-off-by: default avatarPantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
parent c80df483
Loading
Loading
Loading
Loading
+25 −13
Original line number Original line Diff line number Diff line
@@ -107,11 +107,14 @@ static int ti_tscadc_probe(struct platform_device *pdev)
	of_property_read_u32(node, "ti,adc-channels", &adc_channels);
	of_property_read_u32(node, "ti,adc-channels", &adc_channels);


	total_channels = tsc_wires + adc_channels;
	total_channels = tsc_wires + adc_channels;

	if (total_channels > 8) {
	if (total_channels > 8) {
		dev_err(&pdev->dev, "Number of i/p channels more than 8\n");
		dev_err(&pdev->dev, "Number of i/p channels more than 8\n");
		return -EINVAL;
		return -EINVAL;
	}
	}
	if (total_channels == 0) {
		dev_err(&pdev->dev, "Need atleast one channel.\n");
		return -EINVAL;
	}


	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res) {
	if (!res) {
@@ -202,28 +205,37 @@ static int ti_tscadc_probe(struct platform_device *pdev)
	ctrl |= CNTRLREG_TSCSSENB;
	ctrl |= CNTRLREG_TSCSSENB;
	tscadc_writel(tscadc, REG_CTRL, ctrl);
	tscadc_writel(tscadc, REG_CTRL, ctrl);


	tscadc->used_cells = 0;
	tscadc->tsc_cell = -1;
	tscadc->adc_cell = -1;

	/* TSC Cell */
	/* TSC Cell */
	cell = &tscadc->cells[TSC_CELL];
	if (tsc_wires > 0) {
		tscadc->tsc_cell = tscadc->used_cells;
		cell = &tscadc->cells[tscadc->used_cells++];
		cell->name = "tsc";
		cell->name = "tsc";
		cell->of_compatible = "ti,am3359-tsc";
		cell->of_compatible = "ti,am3359-tsc";
		cell->platform_data = &tscadc;
		cell->platform_data = &tscadc;
		cell->pdata_size = sizeof(tscadc);
		cell->pdata_size = sizeof(tscadc);
	}


	/* ADC Cell */
	/* ADC Cell */
	cell = &tscadc->cells[ADC_CELL];
	if (adc_channels > 0) {
		tscadc->adc_cell = tscadc->used_cells;
		cell = &tscadc->cells[tscadc->used_cells++];
		cell->name = "tiadc";
		cell->name = "tiadc";
		cell->of_compatible = "ti,am3359-adc";
		cell->of_compatible = "ti,am3359-adc";
		cell->platform_data = &tscadc;
		cell->platform_data = &tscadc;
		cell->pdata_size = sizeof(tscadc);
		cell->pdata_size = sizeof(tscadc);
	}


	err = mfd_add_devices(&pdev->dev, pdev->id, tscadc->cells,
	err = mfd_add_devices(&pdev->dev, pdev->id, tscadc->cells,
			TSCADC_CELLS, NULL, 0, NULL);
			tscadc->used_cells, NULL, 0, NULL);
	if (err < 0)
	if (err < 0)
		goto err_disable_clk;
		goto err_disable_clk;


	device_init_wakeup(&pdev->dev, true);
	device_init_wakeup(&pdev->dev, true);
	platform_set_drvdata(pdev, tscadc);
	platform_set_drvdata(pdev, tscadc);

	return 0;
	return 0;


err_disable_clk:
err_disable_clk:
+3 −5
Original line number Original line Diff line number Diff line
@@ -120,11 +120,6 @@


#define TSCADC_CELLS		2
#define TSCADC_CELLS		2


enum tscadc_cells {
	TSC_CELL,
	ADC_CELL,
};

struct mfd_tscadc_board {
struct mfd_tscadc_board {
	struct tsc_data *tsc_init;
	struct tsc_data *tsc_init;
	struct adc_data *adc_init;
	struct adc_data *adc_init;
@@ -135,6 +130,9 @@ struct ti_tscadc_dev {
	struct regmap *regmap_tscadc;
	struct regmap *regmap_tscadc;
	void __iomem *tscadc_base;
	void __iomem *tscadc_base;
	int irq;
	int irq;
	int used_cells;	/* 1-2 */
	int tsc_cell;	/* -1 if not used */
	int adc_cell;	/* -1 if not used */
	struct mfd_cell cells[TSCADC_CELLS];
	struct mfd_cell cells[TSCADC_CELLS];
	u32 reg_se_cache;
	u32 reg_se_cache;
	spinlock_t reg_lock;
	spinlock_t reg_lock;