1
0
Files
kernel-49/drivers/iio/adc/fsl-imx25-gcq.c
Greg Kroah-Hartman ef1453a447 Merge 4.9.137 into android-4.9
Changes in 4.9.137
	bcache: fix miss key refill->end in writeback
	hwmon: (pmbus) Fix page count auto-detection.
	jffs2: free jffs2_sb_info through jffs2_kill_sb()
	pcmcia: Implement CLKRUN protocol disabling for Ricoh bridges
	ipmi: Fix timer race with module unload
	parisc: Fix address in HPMC IVA
	parisc: Fix map_pages() to not overwrite existing pte entries
	ALSA: hda - Add quirk for ASUS G751 laptop
	ALSA: hda - Fix headphone pin config for ASUS G751
	ALSA: hda - Add mic quirk for the Lenovo G50-30 (17aa:3905)
	ALSA: ca0106: Disable IZD on SB0570 DAC to fix audio pops
	x86/speculation: Enable cross-hyperthread spectre v2 STIBP mitigation
	x86/corruption-check: Fix panic in memory_corruption_check() when boot option without value is provided
	x86/speculation: Support Enhanced IBRS on future CPUs
	bpf: do not blindly change rlimit in reuseport net selftest
	Revert "perf tools: Fix PMU term format max value calculation"
	xfrm: policy: use hlist rcu variants on insert
	sparc: Fix single-pcr perf event counter management.
	sparc64: Make proc_id signed.
	sched/fair: Fix the min_vruntime update logic in dequeue_entity()
	perf cpu_map: Align cpu map synthesized events properly.
	x86/fpu: Remove second definition of fpu in __fpu__restore_sig()
	net: qla3xxx: Remove overflowing shift statement
	selftests: ftrace: Add synthetic event syntax testcase
	i2c: rcar: cleanup DMA for all kinds of failure
	locking/lockdep: Fix debug_locks off performance problem
	ataflop: fix error handling during setup
	swim: fix cleanup on setup error
	tun: Consistently configure generic netdev params via rtnetlink
	s390/sthyi: Fix machine name validity indication
	hwmon: (pwm-fan) Set fan speed to 0 on suspend
	perf tools: Free temporary 'sys' string in read_event_files()
	perf tools: Cleanup trace-event-info 'tdata' leak
	perf strbuf: Match va_{add,copy} with va_end
	mmc: sdhci-pci-o2micro: Add quirk for O2 Micro dev 0x8620 rev 0x01
	iwlwifi: pcie: avoid empty free RB queue
	x86/olpc: Indicate that legacy PC XO-1 platform should not register RTC
	cpufreq: dt: Try freeing static OPPs only if we have added them
	Bluetooth: btbcm: Add entry for BCM4335C0 UART bluetooth
	x86: boot: Fix EFI stub alignment
	pinctrl: qcom: spmi-mpp: Fix err handling of pmic_mpp_set_mux
	brcmfmac: fix for proper support of 160MHz bandwidth
	kprobes: Return error if we fail to reuse kprobe instead of BUG_ON()
	ACPI / LPSS: Add alternative ACPI HIDs for Cherry Trail DMA controllers
	pinctrl: qcom: spmi-mpp: Fix drive strength setting
	pinctrl: spmi-mpp: Fix pmic_mpp_config_get() to be compliant
	pinctrl: ssbi-gpio: Fix pm8xxx_pin_config_get() to be compliant
	ixgbevf: VF2VF TCP RSS
	ath10k: schedule hardware restart if WMI command times out
	cgroup, netclassid: add a preemption point to write_classid
	scsi: esp_scsi: Track residual for PIO transfers
	scsi: megaraid_sas: fix a missing-check bug
	RDMA/core: Do not expose unsupported counters
	IB/ipoib: Clear IPCB before icmp_send
	tpm: suppress transmit cmd error logs when TPM 1.2 is disabled/deactivated
	VMCI: Resource wildcard match fixed
	usb: gadget: udc: atmel: handle at91sam9rl PMC
	ext4: fix argument checking in EXT4_IOC_MOVE_EXT
	MD: fix invalid stored role for a disk
	PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice
	coresight: etb10: Fix handling of perf mode
	crypto: caam - fix implicit casts in endianness helpers
	usb: chipidea: Prevent unbalanced IRQ disable
	driver/dma/ioat: Call del_timer_sync() without holding prep_lock
	uio: ensure class is registered before devices
	scsi: lpfc: Correct soft lockup when running mds diagnostics
	signal: Always deliver the kernel's SIGKILL and SIGSTOP to a pid namespace init
	dmaengine: dma-jz4780: Return error if not probed from DT
	ALSA: hda: Check the non-cached stream buffers more explicitly
	ARM: dts: exynos: Remove "cooling-{min|max}-level" for CPU nodes
	arm: dts: exynos: Add missing cooling device properties for CPUs
	ARM: dts: exynos: Convert exynos5250.dtsi to opp-v2 bindings
	ARM: dts: exynos: Mark 1 GHz CPU OPP as suspend OPP on Exynos5250
	xen-swiotlb: use actually allocated size on check physical continuous
	tpm: Restore functionality to xen vtpm driver.
	xen/blkfront: avoid NULL blkfront_info dereference on device removal
	xen: fix race in xen_qlock_wait()
	xen: make xen_qlock_wait() nestable
	libertas: don't set URB_ZERO_PACKET on IN USB transfer
	usbip:vudc: BUG kmalloc-2048 (Not tainted): Poison overwritten
	iwlwifi: mvm: check return value of rs_rate_from_ucode_rate()
	net/ipv4: defensive cipso option parsing
	libnvdimm: Hold reference on parent while scheduling async init
	ASoC: intel: skylake: Add missing break in skl_tplg_get_token()
	jbd2: fix use after free in jbd2_log_do_checkpoint()
	gfs2_meta: ->mount() can get NULL dev_name
	ext4: initialize retries variable in ext4_da_write_inline_data_begin()
	ext4: propagate error from dquot_initialize() in EXT4_IOC_FSSETXATTR
	HID: hiddev: fix potential Spectre v1
	EDAC, {i7core,sb,skx}_edac: Fix uncorrected error counting
	EDAC, skx_edac: Fix logical channel intermediate decoding
	PCI: Add Device IDs for Intel GPU "spurious interrupt" quirk
	signal/GenWQE: Fix sending of SIGKILL
	crypto: lrw - Fix out-of bounds access on counter overflow
	crypto: tcrypt - fix ghash-generic speed test
	ima: fix showing large 'violations' or 'runtime_measurements_count'
	hugetlbfs: dirty pages as they are added to pagecache
	kbuild: fix kernel/bounds.c 'W=1' warning
	iio: ad5064: Fix regulator handling
	iio: adc: imx25-gcq: Fix leak of device_node in mx25_gcq_setup_cfgs()
	iio: adc: at91: fix acking DRDY irq on simple conversions
	iio: adc: at91: fix wrong channel number in triggered buffer mode
	w1: omap-hdq: fix missing bus unregister at removal
	smb3: allow stats which track session and share reconnects to be reset
	smb3: do not attempt cifs operation in smb3 query info error path
	smb3: on kerberos mount if server doesn't specify auth type use krb5
	printk: Fix panic caused by passing log_buf_len to command line
	genirq: Fix race on spurious interrupt detection
	NFSv4.1: Fix the r/wsize checking
	nfsd: Fix an Oops in free_session()
	lockd: fix access beyond unterminated strings in prints
	dm ioctl: harden copy_params()'s copy_from_user() from malicious users
	powerpc/msi: Fix compile error on mpc83xx
	MIPS: OCTEON: fix out of bounds array access on CN68XX
	TC: Set DMA masks for devices
	media: v4l2-tpg: fix kernel oops when enabling HFLIP and OSD
	kgdboc: Passing ekgdboc to command line causes panic
	xen: fix xen_qlock_wait()
	media: em28xx: use a default format if TRY_FMT fails
	media: tvp5150: avoid going past array on v4l2_querymenu()
	media: em28xx: fix input name for Terratec AV 350
	media: em28xx: make v4l2-compliance happier by starting sequence on zero
	arm64: lse: remove -fcall-used-x0 flag
	rpmsg: smd: fix memory leak on channel create
	Cramfs: fix abad comparison when wrap-arounds occur
	arm64: dts: stratix10: Correct System Manager register size
	soc/tegra: pmc: Fix child-node lookup
	btrfs: Handle owner mismatch gracefully when walking up tree
	btrfs: locking: Add extra check in btrfs_init_new_buffer() to avoid deadlock
	btrfs: fix error handling in free_log_tree
	btrfs: iterate all devices during trim, instead of fs_devices::alloc_list
	btrfs: don't attempt to trim devices that don't support it
	btrfs: wait on caching when putting the bg cache
	btrfs: reset max_extent_size on clear in a bitmap
	btrfs: make sure we create all new block groups
	Btrfs: fix wrong dentries after fsync of file that got its parent replaced
	btrfs: qgroup: Dirty all qgroups before rescan
	Btrfs: fix null pointer dereference on compressed write path error
	btrfs: set max_extent_size properly
	MD: fix invalid stored role for a disk - try2
	Linux 4.9.137

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2019-02-11 22:53:25 +03:00

425 lines
10 KiB
C

/*
* Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <mpa@pengutronix.de>
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
*
* This is the driver for the imx25 GCQ (Generic Conversion Queue)
* connected to the imx25 ADC.
*/
#include <dt-bindings/iio/adc/fsl-imx25-gcq.h>
#include <linux/clk.h>
#include <linux/iio/iio.h>
#include <linux/interrupt.h>
#include <linux/mfd/imx25-tsadc.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#define MX25_GCQ_TIMEOUT (msecs_to_jiffies(2000))
static const char * const driver_name = "mx25-gcq";
enum mx25_gcq_cfgs {
MX25_CFG_XP = 0,
MX25_CFG_YP,
MX25_CFG_XN,
MX25_CFG_YN,
MX25_CFG_WIPER,
MX25_CFG_INAUX0,
MX25_CFG_INAUX1,
MX25_CFG_INAUX2,
MX25_NUM_CFGS,
};
struct mx25_gcq_priv {
struct regmap *regs;
struct completion completed;
struct clk *clk;
int irq;
struct regulator *vref[4];
u32 channel_vref_mv[MX25_NUM_CFGS];
};
#define MX25_CQG_CHAN(chan, id) {\
.type = IIO_VOLTAGE,\
.indexed = 1,\
.channel = chan,\
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_SCALE),\
.datasheet_name = id,\
}
static const struct iio_chan_spec mx25_gcq_channels[MX25_NUM_CFGS] = {
MX25_CQG_CHAN(MX25_CFG_XP, "xp"),
MX25_CQG_CHAN(MX25_CFG_YP, "yp"),
MX25_CQG_CHAN(MX25_CFG_XN, "xn"),
MX25_CQG_CHAN(MX25_CFG_YN, "yn"),
MX25_CQG_CHAN(MX25_CFG_WIPER, "wiper"),
MX25_CQG_CHAN(MX25_CFG_INAUX0, "inaux0"),
MX25_CQG_CHAN(MX25_CFG_INAUX1, "inaux1"),
MX25_CQG_CHAN(MX25_CFG_INAUX2, "inaux2"),
};
static const char * const mx25_gcq_refp_names[] = {
[MX25_ADC_REFP_YP] = "yp",
[MX25_ADC_REFP_XP] = "xp",
[MX25_ADC_REFP_INT] = "int",
[MX25_ADC_REFP_EXT] = "ext",
};
static irqreturn_t mx25_gcq_irq(int irq, void *data)
{
struct mx25_gcq_priv *priv = data;
u32 stats;
regmap_read(priv->regs, MX25_ADCQ_SR, &stats);
if (stats & MX25_ADCQ_SR_EOQ) {
regmap_update_bits(priv->regs, MX25_ADCQ_MR,
MX25_ADCQ_MR_EOQ_IRQ, MX25_ADCQ_MR_EOQ_IRQ);
complete(&priv->completed);
}
/* Disable conversion queue run */
regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FQS, 0);
/* Acknowledge all possible irqs */
regmap_write(priv->regs, MX25_ADCQ_SR, MX25_ADCQ_SR_FRR |
MX25_ADCQ_SR_FUR | MX25_ADCQ_SR_FOR |
MX25_ADCQ_SR_EOQ | MX25_ADCQ_SR_PD);
return IRQ_HANDLED;
}
static int mx25_gcq_get_raw_value(struct device *dev,
struct iio_chan_spec const *chan,
struct mx25_gcq_priv *priv,
int *val)
{
long timeout;
u32 data;
/* Setup the configuration we want to use */
regmap_write(priv->regs, MX25_ADCQ_ITEM_7_0,
MX25_ADCQ_ITEM(0, chan->channel));
regmap_update_bits(priv->regs, MX25_ADCQ_MR, MX25_ADCQ_MR_EOQ_IRQ, 0);
/* Trigger queue for one run */
regmap_update_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FQS,
MX25_ADCQ_CR_FQS);
timeout = wait_for_completion_interruptible_timeout(
&priv->completed, MX25_GCQ_TIMEOUT);
if (timeout < 0) {
dev_err(dev, "ADC wait for measurement failed\n");
return timeout;
} else if (timeout == 0) {
dev_err(dev, "ADC timed out\n");
return -ETIMEDOUT;
}
regmap_read(priv->regs, MX25_ADCQ_FIFO, &data);
*val = MX25_ADCQ_FIFO_DATA(data);
return IIO_VAL_INT;
}
static int mx25_gcq_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
{
struct mx25_gcq_priv *priv = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
mutex_lock(&indio_dev->mlock);
ret = mx25_gcq_get_raw_value(&indio_dev->dev, chan, priv, val);
mutex_unlock(&indio_dev->mlock);
return ret;
case IIO_CHAN_INFO_SCALE:
*val = priv->channel_vref_mv[chan->channel];
*val2 = 12;
return IIO_VAL_FRACTIONAL_LOG2;
default:
return -EINVAL;
}
}
static const struct iio_info mx25_gcq_iio_info = {
.read_raw = mx25_gcq_read_raw,
};
static const struct regmap_config mx25_gcq_regconfig = {
.max_register = 0x5c,
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
};
static int mx25_gcq_setup_cfgs(struct platform_device *pdev,
struct mx25_gcq_priv *priv)
{
struct device_node *np = pdev->dev.of_node;
struct device_node *child;
struct device *dev = &pdev->dev;
unsigned int refp_used[4] = {};
int ret, i;
/*
* Setup all configurations registers with a default conversion
* configuration for each input
*/
for (i = 0; i < MX25_NUM_CFGS; ++i)
regmap_write(priv->regs, MX25_ADCQ_CFG(i),
MX25_ADCQ_CFG_YPLL_OFF |
MX25_ADCQ_CFG_XNUR_OFF |
MX25_ADCQ_CFG_XPUL_OFF |
MX25_ADCQ_CFG_REFP_INT |
MX25_ADCQ_CFG_IN(i) |
MX25_ADCQ_CFG_REFN_NGND2);
/*
* First get all regulators to store them in channel_vref_mv if
* necessary. Later we use that information for proper IIO scale
* information.
*/
priv->vref[MX25_ADC_REFP_INT] = NULL;
priv->vref[MX25_ADC_REFP_EXT] =
devm_regulator_get_optional(&pdev->dev, "vref-ext");
priv->vref[MX25_ADC_REFP_XP] =
devm_regulator_get_optional(&pdev->dev, "vref-xp");
priv->vref[MX25_ADC_REFP_YP] =
devm_regulator_get_optional(&pdev->dev, "vref-yp");
for_each_child_of_node(np, child) {
u32 reg;
u32 refp = MX25_ADCQ_CFG_REFP_INT;
u32 refn = MX25_ADCQ_CFG_REFN_NGND2;
ret = of_property_read_u32(child, "reg", &reg);
if (ret) {
dev_err(dev, "Failed to get reg property\n");
of_node_put(child);
return ret;
}
if (reg >= MX25_NUM_CFGS) {
dev_err(dev,
"reg value is greater than the number of available configuration registers\n");
of_node_put(child);
return -EINVAL;
}
of_property_read_u32(child, "fsl,adc-refp", &refp);
of_property_read_u32(child, "fsl,adc-refn", &refn);
switch (refp) {
case MX25_ADC_REFP_EXT:
case MX25_ADC_REFP_XP:
case MX25_ADC_REFP_YP:
if (IS_ERR(priv->vref[refp])) {
dev_err(dev, "Error, trying to use external voltage reference without a vref-%s regulator.",
mx25_gcq_refp_names[refp]);
of_node_put(child);
return PTR_ERR(priv->vref[refp]);
}
priv->channel_vref_mv[reg] =
regulator_get_voltage(priv->vref[refp]);
/* Conversion from uV to mV */
priv->channel_vref_mv[reg] /= 1000;
break;
case MX25_ADC_REFP_INT:
priv->channel_vref_mv[reg] = 2500;
break;
default:
dev_err(dev, "Invalid positive reference %d\n", refp);
of_node_put(child);
return -EINVAL;
}
++refp_used[refp];
/*
* Shift the read values to the correct positions within the
* register.
*/
refp = MX25_ADCQ_CFG_REFP(refp);
refn = MX25_ADCQ_CFG_REFN(refn);
if ((refp & MX25_ADCQ_CFG_REFP_MASK) != refp) {
dev_err(dev, "Invalid fsl,adc-refp property value\n");
of_node_put(child);
return -EINVAL;
}
if ((refn & MX25_ADCQ_CFG_REFN_MASK) != refn) {
dev_err(dev, "Invalid fsl,adc-refn property value\n");
of_node_put(child);
return -EINVAL;
}
regmap_update_bits(priv->regs, MX25_ADCQ_CFG(reg),
MX25_ADCQ_CFG_REFP_MASK |
MX25_ADCQ_CFG_REFN_MASK,
refp | refn);
}
regmap_update_bits(priv->regs, MX25_ADCQ_CR,
MX25_ADCQ_CR_FRST | MX25_ADCQ_CR_QRST,
MX25_ADCQ_CR_FRST | MX25_ADCQ_CR_QRST);
regmap_write(priv->regs, MX25_ADCQ_CR,
MX25_ADCQ_CR_PDMSK | MX25_ADCQ_CR_QSM_FQS);
/* Remove unused regulators */
for (i = 0; i != 4; ++i) {
if (!refp_used[i]) {
if (!IS_ERR_OR_NULL(priv->vref[i]))
devm_regulator_put(priv->vref[i]);
priv->vref[i] = NULL;
}
}
return 0;
}
static int mx25_gcq_probe(struct platform_device *pdev)
{
struct iio_dev *indio_dev;
struct mx25_gcq_priv *priv;
struct mx25_tsadc *tsadc = dev_get_drvdata(pdev->dev.parent);
struct device *dev = &pdev->dev;
struct resource *res;
void __iomem *mem;
int ret;
int i;
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv));
if (!indio_dev)
return -ENOMEM;
priv = iio_priv(indio_dev);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mem = devm_ioremap_resource(dev, res);
if (IS_ERR(mem))
return PTR_ERR(mem);
priv->regs = devm_regmap_init_mmio(dev, mem, &mx25_gcq_regconfig);
if (IS_ERR(priv->regs)) {
dev_err(dev, "Failed to initialize regmap\n");
return PTR_ERR(priv->regs);
}
init_completion(&priv->completed);
ret = mx25_gcq_setup_cfgs(pdev, priv);
if (ret)
return ret;
for (i = 0; i != 4; ++i) {
if (!priv->vref[i])
continue;
ret = regulator_enable(priv->vref[i]);
if (ret)
goto err_regulator_disable;
}
priv->clk = tsadc->clk;
ret = clk_prepare_enable(priv->clk);
if (ret) {
dev_err(dev, "Failed to enable clock\n");
goto err_vref_disable;
}
priv->irq = platform_get_irq(pdev, 0);
if (priv->irq <= 0) {
dev_err(dev, "Failed to get IRQ\n");
ret = priv->irq;
if (!ret)
ret = -ENXIO;
goto err_clk_unprepare;
}
ret = request_irq(priv->irq, mx25_gcq_irq, 0, pdev->name, priv);
if (ret) {
dev_err(dev, "Failed requesting IRQ\n");
goto err_clk_unprepare;
}
indio_dev->dev.parent = &pdev->dev;
indio_dev->channels = mx25_gcq_channels;
indio_dev->num_channels = ARRAY_SIZE(mx25_gcq_channels);
indio_dev->info = &mx25_gcq_iio_info;
indio_dev->name = driver_name;
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(dev, "Failed to register iio device\n");
goto err_irq_free;
}
platform_set_drvdata(pdev, indio_dev);
return 0;
err_irq_free:
free_irq(priv->irq, priv);
err_clk_unprepare:
clk_disable_unprepare(priv->clk);
err_vref_disable:
i = 4;
err_regulator_disable:
for (; i-- > 0;) {
if (priv->vref[i])
regulator_disable(priv->vref[i]);
}
return ret;
}
static int mx25_gcq_remove(struct platform_device *pdev)
{
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct mx25_gcq_priv *priv = iio_priv(indio_dev);
int i;
iio_device_unregister(indio_dev);
free_irq(priv->irq, priv);
clk_disable_unprepare(priv->clk);
for (i = 4; i-- > 0;) {
if (priv->vref[i])
regulator_disable(priv->vref[i]);
}
return 0;
}
static const struct of_device_id mx25_gcq_ids[] = {
{ .compatible = "fsl,imx25-gcq", },
{ /* Sentinel */ }
};
MODULE_DEVICE_TABLE(of, mx25_gcq_ids);
static struct platform_driver mx25_gcq_driver = {
.driver = {
.name = "mx25-gcq",
.of_match_table = mx25_gcq_ids,
},
.probe = mx25_gcq_probe,
.remove = mx25_gcq_remove,
};
module_platform_driver(mx25_gcq_driver);
MODULE_DESCRIPTION("ADC driver for Freescale mx25");
MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
MODULE_LICENSE("GPL v2");