diff options
author | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2016-10-20 00:10:27 -0300 |
---|---|---|
committer | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2016-10-20 00:10:27 -0300 |
commit | d0b2f91bede3bd5e3d24dd6803e56eee959c1797 (patch) | |
tree | 7fee4ab0509879c373c4f2cbd5b8a5be5b4041ee /drivers/mfd/ti_am335x_tscadc.c | |
parent | e914f8eb445e8f74b00303c19c2ffceaedd16a05 (diff) |
Linux-libre 4.8.2-gnupck-4.8.2-gnu
Diffstat (limited to 'drivers/mfd/ti_am335x_tscadc.c')
-rw-r--r-- | drivers/mfd/ti_am335x_tscadc.c | 135 |
1 files changed, 56 insertions, 79 deletions
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c index e4e4b22ee..c8f027b4e 100644 --- a/drivers/mfd/ti_am335x_tscadc.c +++ b/drivers/mfd/ti_am335x_tscadc.c @@ -27,20 +27,6 @@ #include <linux/mfd/ti_am335x_tscadc.h> -static unsigned int tscadc_readl(struct ti_tscadc_dev *tsadc, unsigned int reg) -{ - unsigned int val; - - regmap_read(tsadc->regmap_tscadc, reg, &val); - return val; -} - -static void tscadc_writel(struct ti_tscadc_dev *tsadc, unsigned int reg, - unsigned int val) -{ - regmap_write(tsadc->regmap_tscadc, reg, val); -} - static const struct regmap_config tscadc_regmap_config = { .name = "ti_tscadc", .reg_bits = 32, @@ -48,89 +34,89 @@ static const struct regmap_config tscadc_regmap_config = { .val_bits = 32, }; -void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tsadc, u32 val) +void am335x_tsc_se_set_cache(struct ti_tscadc_dev *tscadc, u32 val) { unsigned long flags; - spin_lock_irqsave(&tsadc->reg_lock, flags); - tsadc->reg_se_cache |= val; - if (tsadc->adc_waiting) - wake_up(&tsadc->reg_se_wait); - else if (!tsadc->adc_in_use) - tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache); + spin_lock_irqsave(&tscadc->reg_lock, flags); + tscadc->reg_se_cache |= val; + if (tscadc->adc_waiting) + wake_up(&tscadc->reg_se_wait); + else if (!tscadc->adc_in_use) + regmap_write(tscadc->regmap, REG_SE, tscadc->reg_se_cache); - spin_unlock_irqrestore(&tsadc->reg_lock, flags); + spin_unlock_irqrestore(&tscadc->reg_lock, flags); } EXPORT_SYMBOL_GPL(am335x_tsc_se_set_cache); -static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tsadc) +static void am335x_tscadc_need_adc(struct ti_tscadc_dev *tscadc) { DEFINE_WAIT(wait); u32 reg; - reg = tscadc_readl(tsadc, REG_ADCFSM); + regmap_read(tscadc->regmap, REG_ADCFSM, ®); if (reg & SEQ_STATUS) { - tsadc->adc_waiting = true; - prepare_to_wait(&tsadc->reg_se_wait, &wait, + tscadc->adc_waiting = true; + prepare_to_wait(&tscadc->reg_se_wait, &wait, TASK_UNINTERRUPTIBLE); - spin_unlock_irq(&tsadc->reg_lock); + spin_unlock_irq(&tscadc->reg_lock); schedule(); - spin_lock_irq(&tsadc->reg_lock); - finish_wait(&tsadc->reg_se_wait, &wait); + spin_lock_irq(&tscadc->reg_lock); + finish_wait(&tscadc->reg_se_wait, &wait); /* * Sequencer should either be idle or * busy applying the charge step. */ - reg = tscadc_readl(tsadc, REG_ADCFSM); + regmap_read(tscadc->regmap, REG_ADCFSM, ®); WARN_ON((reg & SEQ_STATUS) && !(reg & CHARGE_STEP)); - tsadc->adc_waiting = false; + tscadc->adc_waiting = false; } - tsadc->adc_in_use = true; + tscadc->adc_in_use = true; } -void am335x_tsc_se_set_once(struct ti_tscadc_dev *tsadc, u32 val) +void am335x_tsc_se_set_once(struct ti_tscadc_dev *tscadc, u32 val) { - spin_lock_irq(&tsadc->reg_lock); - am335x_tscadc_need_adc(tsadc); + spin_lock_irq(&tscadc->reg_lock); + am335x_tscadc_need_adc(tscadc); - tscadc_writel(tsadc, REG_SE, val); - spin_unlock_irq(&tsadc->reg_lock); + regmap_write(tscadc->regmap, REG_SE, val); + spin_unlock_irq(&tscadc->reg_lock); } EXPORT_SYMBOL_GPL(am335x_tsc_se_set_once); -void am335x_tsc_se_adc_done(struct ti_tscadc_dev *tsadc) +void am335x_tsc_se_adc_done(struct ti_tscadc_dev *tscadc) { unsigned long flags; - spin_lock_irqsave(&tsadc->reg_lock, flags); - tsadc->adc_in_use = false; - tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache); - spin_unlock_irqrestore(&tsadc->reg_lock, flags); + spin_lock_irqsave(&tscadc->reg_lock, flags); + tscadc->adc_in_use = false; + regmap_write(tscadc->regmap, REG_SE, tscadc->reg_se_cache); + spin_unlock_irqrestore(&tscadc->reg_lock, flags); } EXPORT_SYMBOL_GPL(am335x_tsc_se_adc_done); -void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val) +void am335x_tsc_se_clr(struct ti_tscadc_dev *tscadc, u32 val) { unsigned long flags; - spin_lock_irqsave(&tsadc->reg_lock, flags); - tsadc->reg_se_cache &= ~val; - tscadc_writel(tsadc, REG_SE, tsadc->reg_se_cache); - spin_unlock_irqrestore(&tsadc->reg_lock, flags); + spin_lock_irqsave(&tscadc->reg_lock, flags); + tscadc->reg_se_cache &= ~val; + regmap_write(tscadc->regmap, REG_SE, tscadc->reg_se_cache); + spin_unlock_irqrestore(&tscadc->reg_lock, flags); } EXPORT_SYMBOL_GPL(am335x_tsc_se_clr); -static void tscadc_idle_config(struct ti_tscadc_dev *config) +static void tscadc_idle_config(struct ti_tscadc_dev *tscadc) { unsigned int idleconfig; idleconfig = STEPCONFIG_YNN | STEPCONFIG_INM_ADCREFM | STEPCONFIG_INP_ADCREFM | STEPCONFIG_YPN; - tscadc_writel(config, REG_IDLECONFIG, idleconfig); + regmap_write(tscadc->regmap, REG_IDLECONFIG, idleconfig); } static int ti_tscadc_probe(struct platform_device *pdev) @@ -182,8 +168,7 @@ static int ti_tscadc_probe(struct platform_device *pdev) } /* Allocate memory for device */ - tscadc = devm_kzalloc(&pdev->dev, - sizeof(struct ti_tscadc_dev), GFP_KERNEL); + tscadc = devm_kzalloc(&pdev->dev, sizeof(*tscadc), GFP_KERNEL); if (!tscadc) { dev_err(&pdev->dev, "failed to allocate memory.\n"); return -ENOMEM; @@ -202,11 +187,11 @@ static int ti_tscadc_probe(struct platform_device *pdev) if (IS_ERR(tscadc->tscadc_base)) return PTR_ERR(tscadc->tscadc_base); - tscadc->regmap_tscadc = devm_regmap_init_mmio(&pdev->dev, + tscadc->regmap = devm_regmap_init_mmio(&pdev->dev, tscadc->tscadc_base, &tscadc_regmap_config); - if (IS_ERR(tscadc->regmap_tscadc)) { + if (IS_ERR(tscadc->regmap)) { dev_err(&pdev->dev, "regmap init failed\n"); - err = PTR_ERR(tscadc->regmap_tscadc); + err = PTR_ERR(tscadc->regmap); goto ret; } @@ -236,11 +221,11 @@ static int ti_tscadc_probe(struct platform_device *pdev) /* TSCADC_CLKDIV needs to be configured to the value minus 1 */ tscadc->clk_div--; - tscadc_writel(tscadc, REG_CLKDIV, tscadc->clk_div); + regmap_write(tscadc->regmap, REG_CLKDIV, tscadc->clk_div); /* Set the control register bits */ ctrl = CNTRLREG_STEPCONFIGWRT | CNTRLREG_STEPID; - tscadc_writel(tscadc, REG_CTRL, ctrl); + regmap_write(tscadc->regmap, REG_CTRL, ctrl); /* Set register bits for Idle Config Mode */ if (tsc_wires > 0) { @@ -254,7 +239,7 @@ static int ti_tscadc_probe(struct platform_device *pdev) /* Enable the TSC module enable bit */ ctrl |= CNTRLREG_TSCSSENB; - tscadc_writel(tscadc, REG_CTRL, ctrl); + regmap_write(tscadc->regmap, REG_CTRL, ctrl); tscadc->used_cells = 0; tscadc->tsc_cell = -1; @@ -300,7 +285,7 @@ static int ti_tscadc_remove(struct platform_device *pdev) { struct ti_tscadc_dev *tscadc = platform_get_drvdata(pdev); - tscadc_writel(tscadc, REG_SE, 0x00); + regmap_write(tscadc->regmap, REG_SE, 0x00); pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); @@ -310,51 +295,43 @@ static int ti_tscadc_remove(struct platform_device *pdev) return 0; } -#ifdef CONFIG_PM -static int tscadc_suspend(struct device *dev) +static int __maybe_unused tscadc_suspend(struct device *dev) { - struct ti_tscadc_dev *tscadc_dev = dev_get_drvdata(dev); + struct ti_tscadc_dev *tscadc = dev_get_drvdata(dev); - tscadc_writel(tscadc_dev, REG_SE, 0x00); + regmap_write(tscadc->regmap, REG_SE, 0x00); pm_runtime_put_sync(dev); return 0; } -static int tscadc_resume(struct device *dev) +static int __maybe_unused tscadc_resume(struct device *dev) { - struct ti_tscadc_dev *tscadc_dev = dev_get_drvdata(dev); + struct ti_tscadc_dev *tscadc = dev_get_drvdata(dev); u32 ctrl; pm_runtime_get_sync(dev); /* context restore */ ctrl = CNTRLREG_STEPCONFIGWRT | CNTRLREG_STEPID; - tscadc_writel(tscadc_dev, REG_CTRL, ctrl); + regmap_write(tscadc->regmap, REG_CTRL, ctrl); - if (tscadc_dev->tsc_cell != -1) { - if (tscadc_dev->tsc_wires == 5) + if (tscadc->tsc_cell != -1) { + if (tscadc->tsc_wires == 5) ctrl |= CNTRLREG_5WIRE | CNTRLREG_TSCENB; else ctrl |= CNTRLREG_4WIRE | CNTRLREG_TSCENB; - tscadc_idle_config(tscadc_dev); + tscadc_idle_config(tscadc); } ctrl |= CNTRLREG_TSCSSENB; - tscadc_writel(tscadc_dev, REG_CTRL, ctrl); + regmap_write(tscadc->regmap, REG_CTRL, ctrl); - tscadc_writel(tscadc_dev, REG_CLKDIV, tscadc_dev->clk_div); + regmap_write(tscadc->regmap, REG_CLKDIV, tscadc->clk_div); return 0; } -static const struct dev_pm_ops tscadc_pm_ops = { - .suspend = tscadc_suspend, - .resume = tscadc_resume, -}; -#define TSCADC_PM_OPS (&tscadc_pm_ops) -#else -#define TSCADC_PM_OPS NULL -#endif +static SIMPLE_DEV_PM_OPS(tscadc_pm_ops, tscadc_suspend, tscadc_resume); static const struct of_device_id ti_tscadc_dt_ids[] = { { .compatible = "ti,am3359-tscadc", }, @@ -365,7 +342,7 @@ MODULE_DEVICE_TABLE(of, ti_tscadc_dt_ids); static struct platform_driver ti_tscadc_driver = { .driver = { .name = "ti_am3359-tscadc", - .pm = TSCADC_PM_OPS, + .pm = &tscadc_pm_ops, .of_match_table = ti_tscadc_dt_ids, }, .probe = ti_tscadc_probe, |