Changes in 4.9.259 HID: make arrays usage and value to be the same usb: quirks: add quirk to start video capture on ELMO L-12F document camera reliable ntfs: check for valid standard information attribute igb: Remove incorrect "unexpected SYS WRAP" log message arm64: tegra: Add power-domain for Tegra210 HDA NET: usb: qmi_wwan: Adding support for Cinterion MV31 cifs: Set CIFS_MOUNT_USE_PREFIX_PATH flag on setting cifs_sb->prepath. scripts/recordmcount.pl: support big endian for ARCH sh kdb: Make memory allocations more robust MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section random: fix the RNDRESEEDCRNG ioctl mm, thp: make do_huge_pmd_wp_page() lock page for testing mapcount Bluetooth: Fix initializing response id after clearing struct ARM: dts: exynos: correct PMIC interrupt trigger level on Spring ARM: dts: exynos: correct PMIC interrupt trigger level on Arndale Octa arm64: dts: exynos: correct PMIC interrupt trigger level on Espresso Bluetooth: drop HCI device reference before return Bluetooth: Put HCI device if inquiry procedure interrupts ARM: dts: Configure missing thermal interrupt for 4430 usb: dwc2: Do not update data length if it is 0 on inbound transfers usb: dwc2: Abort transaction after errors with unknown reason usb: dwc2: Make "trimming xfer length" a debug message arm64: dts: msm8916: Fix reserved and rfsa nodes unit address ARM: s3c: fix fiq for clang IAS bnxt_en: reverse order of TX disable and carrier off xen/netback: fix spurious event detection for common event case mac80211: fix potential overflow when multiplying to u32 integers b43: N-PHY: Fix the update of coef for the PHY revision >= 3case fbdev: aty: SPARC64 requires FB_ATY_CT drm/gma500: Fix error return code in psb_driver_load() gma500: clean up error handling in init MIPS: c-r4k: Fix section mismatch for loongson2_sc_init MIPS: lantiq: Explicitly compare LTQ_EBU_PCC_ISTAT against 0 media: vsp1: Fix an error handling path in the probe function media: media/pci: Fix memleak in empress_init media: tm6000: Fix memleak in tm6000_start_stream ASoC: cs42l56: fix up error handling in probe media: lmedm04: Fix misuse of comma media: qm1d1c0042: fix error return code in qm1d1c0042_init() media: cx25821: Fix a bug when reallocating some dma memory media: pxa_camera: declare variable when DEBUG is defined media: uvcvideo: Accept invalid bFormatIndex and bFrameIndex values ata: ahci_brcm: Add back regulators management btrfs: clarify error returns values in __load_free_space_cache crypto: ecdh_helper - Ensure 'len >= secret.len' in decode_key() fs/jfs: fix potential integer overflow on shift of a int jffs2: fix use after free in jffs2_sum_write_data() clk: meson: clk-pll: fix initializing the old rate (fallback) for a PLL spi: cadence-quadspi: Abort read if dummy cycles required are too many HID: core: detect and skip invalid inputs to snto32() dmaengine: fsldma: Fix a resource leak in the remove function dmaengine: fsldma: Fix a resource leak in an error handling path of the probe function fdt: Properly handle "no-map" field in the memory region of/fdt: Make sure no-map does not remove already reserved regions power: reset: at91-sama5d2_shdwc: fix wkupdbc mask clocksource/drivers/mxs_timer: Add missing semicolon when DEBUG is defined regulator: axp20x: Fix reference cout leak isofs: release buffer head before return IB/umad: Return EIO in case of when device disassociated powerpc/47x: Disable 256k page size mmc: usdhi6rol0: Fix a resource leak in the error handling path of the probe ARM: 9046/1: decompressor: Do not clear SCTLR.nTLSMD for ARMv7+ cores amba: Fix resource leak for drivers without .remove tracepoint: Do not fail unregistering a probe due to memory failure perf tools: Fix DSO filtering when not finding a map for a sampled address RDMA/rxe: Fix coding error in rxe_recv.c mfd: wm831x-auxadc: Prevent use after free in wm831x_auxadc_read_irq() powerpc/pseries/dlpar: handle ibm, configure-connector delay status spi: pxa2xx: Fix the controller numbering for Wildcat Point perf intel-pt: Fix missing CYC processing in PSB perf test: Fix unaligned access in sample parsing test Input: elo - fix an error code in elo_connect() sparc64: only select COMPAT_BINFMT_ELF if BINFMT_ELF is set misc: eeprom_93xx46: Fix module alias to enable module autoprobe misc: eeprom_93xx46: Add module alias to avoid breaking support for non device tree users pwm: rockchip: rockchip_pwm_probe(): Remove superfluous clk_unprepare() VMCI: Use set_page_dirty_lock() when unregistering guest memory PCI: Align checking of syscall user config accessors drm/msm/dsi: Correct io_start for MSM8994 (20nm PHY) i40e: Fix flow for IPv6 next header (extension header) net/mlx4_core: Add missed mlx4_free_cmd_mailbox() ocfs2: fix a use after free on error mm/memory.c: fix potential pte_unmap_unlock pte error mm/hugetlb: fix potential double free in hugetlb_register_node() error path arm64: Add missing ISB after invalidating TLB in __primary_switch i2c: brcmstb: Fix brcmstd_send_i2c_cmd condition scsi: bnx2fc: Fix Kconfig warning & CNIC build errors blk-settings: align max_sectors on "logical_block_size" boundary ACPI: configfs: add missing check after configfs_register_default_group() Input: raydium_ts_i2c - do not send zero length Input: xpad - add support for PowerA Enhanced Wired Controller for Xbox Series X|S Input: joydev - prevent potential read overflow in ioctl Input: i8042 - add ASUS Zenbook Flip to noselftest list USB: serial: option: update interface mapping for ZTE P685M usb: musb: Fix runtime PM race in musb_queue_resume_work USB: serial: mos7840: fix error code in mos7840_write() USB: serial: mos7720: fix error code in mos7720_write() usb: dwc3: gadget: Fix setting of DEPCFG.bInterval_m1 usb: dwc3: gadget: Fix dep->interval for fullspeed interrupt KEYS: trusted: Fix migratable=1 failing btrfs: abort the transaction if we fail to inc ref in btrfs_copy_root btrfs: fix reloc root leak with 0 ref reloc roots on recovery btrfs: fix extent buffer leak on failure to copy root seccomp: Add missing return in non-void function drivers/misc/vmw_vmci: restrict too big queue size in qp_host_alloc_queue staging: rtl8188eu: Add Edimax EW-7811UN V2 to device table x86/reboot: Force all cpus to exit VMX root if VMX is supported floppy: reintroduce O_NDELAY fix mtd: spi-nor: hisi-sfc: Put child node np on error path mm: hugetlb: fix a race between freeing and dissolving the page usb: renesas_usbhs: Clear pipe running flag in usbhs_pkt_pop() libnvdimm/dimm: Avoid race between probe and available_slots_show() module: Ignore _GLOBAL_OFFSET_TABLE_ when warning for undefined symbols mmc: sdhci-esdhc-imx: fix kernel panic when remove module gpio: pcf857x: Fix missing first interrupt f2fs: fix out-of-repair __setattr_copy() sparc32: fix a user-triggerable oops in clear_user() gfs2: Don't skip dlm unlock if glock has an lvb dm era: Recover committed writeset after crash dm era: Verify the data block size hasn't changed dm era: Fix bitset memory leaks dm era: Use correct value size in equality function of writeset tree dm era: Reinitialize bitset cache before digesting a new writeset dm era: only resize metadata in preresume futex: Fix OWNER_DEAD fixup futex: fix dead code in attach_to_pi_owner() icmp: introduce helper for nat'd source address in network device context icmp: allow icmpv6_ndo_send to work with CONFIG_IPV6=n gtp: use icmp_ndo_send helper sunvnet: use icmp_ndo_send helper ipv6: icmp6: avoid indirect call for icmpv6_send() ipv6: silence compilation warning for non-IPV6 builds net: icmp: pass zeroed opts from icmp{,v6}_ndo_send before sending dm era: Update in-core bitset after committing the metadata Linux 4.9.259 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Icef5fb8e40fc531a932878e86ae352f2d5e71d53
300 lines
6.7 KiB
C
300 lines
6.7 KiB
C
/*
|
|
* wm831x-auxadc.c -- AUXADC for Wolfson WM831x PMICs
|
|
*
|
|
* Copyright 2009-2011 Wolfson Microelectronics PLC.
|
|
*
|
|
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
* option) any later version.
|
|
*
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/mfd/core.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/mfd/wm831x/core.h>
|
|
#include <linux/mfd/wm831x/pdata.h>
|
|
#include <linux/mfd/wm831x/irq.h>
|
|
#include <linux/mfd/wm831x/auxadc.h>
|
|
#include <linux/mfd/wm831x/otp.h>
|
|
#include <linux/mfd/wm831x/regulator.h>
|
|
|
|
struct wm831x_auxadc_req {
|
|
struct list_head list;
|
|
enum wm831x_auxadc input;
|
|
int val;
|
|
struct completion done;
|
|
};
|
|
|
|
static int wm831x_auxadc_read_irq(struct wm831x *wm831x,
|
|
enum wm831x_auxadc input)
|
|
{
|
|
struct wm831x_auxadc_req *req;
|
|
int ret;
|
|
bool ena = false;
|
|
|
|
req = kzalloc(sizeof(*req), GFP_KERNEL);
|
|
if (!req)
|
|
return -ENOMEM;
|
|
|
|
init_completion(&req->done);
|
|
req->input = input;
|
|
req->val = -ETIMEDOUT;
|
|
|
|
mutex_lock(&wm831x->auxadc_lock);
|
|
|
|
/* Enqueue the request */
|
|
list_add(&req->list, &wm831x->auxadc_pending);
|
|
|
|
ena = !wm831x->auxadc_active;
|
|
|
|
if (ena) {
|
|
ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
|
|
WM831X_AUX_ENA, WM831X_AUX_ENA);
|
|
if (ret != 0) {
|
|
dev_err(wm831x->dev, "Failed to enable AUXADC: %d\n",
|
|
ret);
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
/* Enable the conversion if not already running */
|
|
if (!(wm831x->auxadc_active & (1 << input))) {
|
|
ret = wm831x_set_bits(wm831x, WM831X_AUXADC_SOURCE,
|
|
1 << input, 1 << input);
|
|
if (ret != 0) {
|
|
dev_err(wm831x->dev,
|
|
"Failed to set AUXADC source: %d\n", ret);
|
|
goto out;
|
|
}
|
|
|
|
wm831x->auxadc_active |= 1 << input;
|
|
}
|
|
|
|
/* We convert at the fastest rate possible */
|
|
if (ena) {
|
|
ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
|
|
WM831X_AUX_CVT_ENA |
|
|
WM831X_AUX_RATE_MASK,
|
|
WM831X_AUX_CVT_ENA |
|
|
WM831X_AUX_RATE_MASK);
|
|
if (ret != 0) {
|
|
dev_err(wm831x->dev, "Failed to start AUXADC: %d\n",
|
|
ret);
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
mutex_unlock(&wm831x->auxadc_lock);
|
|
|
|
/* Wait for an interrupt */
|
|
wait_for_completion_timeout(&req->done, msecs_to_jiffies(500));
|
|
|
|
mutex_lock(&wm831x->auxadc_lock);
|
|
ret = req->val;
|
|
|
|
out:
|
|
list_del(&req->list);
|
|
mutex_unlock(&wm831x->auxadc_lock);
|
|
|
|
kfree(req);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static irqreturn_t wm831x_auxadc_irq(int irq, void *irq_data)
|
|
{
|
|
struct wm831x *wm831x = irq_data;
|
|
struct wm831x_auxadc_req *req;
|
|
int ret, input, val;
|
|
|
|
ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
|
|
if (ret < 0) {
|
|
dev_err(wm831x->dev,
|
|
"Failed to read AUXADC data: %d\n", ret);
|
|
return IRQ_NONE;
|
|
}
|
|
|
|
input = ((ret & WM831X_AUX_DATA_SRC_MASK)
|
|
>> WM831X_AUX_DATA_SRC_SHIFT) - 1;
|
|
|
|
if (input == 14)
|
|
input = WM831X_AUX_CAL;
|
|
|
|
val = ret & WM831X_AUX_DATA_MASK;
|
|
|
|
mutex_lock(&wm831x->auxadc_lock);
|
|
|
|
/* Disable this conversion, we're about to complete all users */
|
|
wm831x_set_bits(wm831x, WM831X_AUXADC_SOURCE,
|
|
1 << input, 0);
|
|
wm831x->auxadc_active &= ~(1 << input);
|
|
|
|
/* Turn off the entire convertor if idle */
|
|
if (!wm831x->auxadc_active)
|
|
wm831x_reg_write(wm831x, WM831X_AUXADC_CONTROL, 0);
|
|
|
|
/* Wake up any threads waiting for this request */
|
|
list_for_each_entry(req, &wm831x->auxadc_pending, list) {
|
|
if (req->input == input) {
|
|
req->val = val;
|
|
complete(&req->done);
|
|
}
|
|
}
|
|
|
|
mutex_unlock(&wm831x->auxadc_lock);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static int wm831x_auxadc_read_polled(struct wm831x *wm831x,
|
|
enum wm831x_auxadc input)
|
|
{
|
|
int ret, src, timeout;
|
|
|
|
mutex_lock(&wm831x->auxadc_lock);
|
|
|
|
ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
|
|
WM831X_AUX_ENA, WM831X_AUX_ENA);
|
|
if (ret < 0) {
|
|
dev_err(wm831x->dev, "Failed to enable AUXADC: %d\n", ret);
|
|
goto out;
|
|
}
|
|
|
|
/* We force a single source at present */
|
|
src = input;
|
|
ret = wm831x_reg_write(wm831x, WM831X_AUXADC_SOURCE,
|
|
1 << src);
|
|
if (ret < 0) {
|
|
dev_err(wm831x->dev, "Failed to set AUXADC source: %d\n", ret);
|
|
goto out;
|
|
}
|
|
|
|
ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
|
|
WM831X_AUX_CVT_ENA, WM831X_AUX_CVT_ENA);
|
|
if (ret < 0) {
|
|
dev_err(wm831x->dev, "Failed to start AUXADC: %d\n", ret);
|
|
goto disable;
|
|
}
|
|
|
|
/* If we're not using interrupts then poll the
|
|
* interrupt status register */
|
|
timeout = 5;
|
|
while (timeout) {
|
|
msleep(1);
|
|
|
|
ret = wm831x_reg_read(wm831x,
|
|
WM831X_INTERRUPT_STATUS_1);
|
|
if (ret < 0) {
|
|
dev_err(wm831x->dev,
|
|
"ISR 1 read failed: %d\n", ret);
|
|
goto disable;
|
|
}
|
|
|
|
/* Did it complete? */
|
|
if (ret & WM831X_AUXADC_DATA_EINT) {
|
|
wm831x_reg_write(wm831x,
|
|
WM831X_INTERRUPT_STATUS_1,
|
|
WM831X_AUXADC_DATA_EINT);
|
|
break;
|
|
} else {
|
|
dev_err(wm831x->dev,
|
|
"AUXADC conversion timeout\n");
|
|
ret = -EBUSY;
|
|
goto disable;
|
|
}
|
|
}
|
|
|
|
ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
|
|
if (ret < 0) {
|
|
dev_err(wm831x->dev,
|
|
"Failed to read AUXADC data: %d\n", ret);
|
|
goto disable;
|
|
}
|
|
|
|
src = ((ret & WM831X_AUX_DATA_SRC_MASK)
|
|
>> WM831X_AUX_DATA_SRC_SHIFT) - 1;
|
|
|
|
if (src == 14)
|
|
src = WM831X_AUX_CAL;
|
|
|
|
if (src != input) {
|
|
dev_err(wm831x->dev, "Data from source %d not %d\n",
|
|
src, input);
|
|
ret = -EINVAL;
|
|
} else {
|
|
ret &= WM831X_AUX_DATA_MASK;
|
|
}
|
|
|
|
disable:
|
|
wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL, WM831X_AUX_ENA, 0);
|
|
out:
|
|
mutex_unlock(&wm831x->auxadc_lock);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* wm831x_auxadc_read: Read a value from the WM831x AUXADC
|
|
*
|
|
* @wm831x: Device to read from.
|
|
* @input: AUXADC input to read.
|
|
*/
|
|
int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
|
|
{
|
|
return wm831x->auxadc_read(wm831x, input);
|
|
}
|
|
EXPORT_SYMBOL_GPL(wm831x_auxadc_read);
|
|
|
|
/**
|
|
* wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC
|
|
*
|
|
* @wm831x: Device to read from.
|
|
* @input: AUXADC input to read.
|
|
*/
|
|
int wm831x_auxadc_read_uv(struct wm831x *wm831x, enum wm831x_auxadc input)
|
|
{
|
|
int ret;
|
|
|
|
ret = wm831x_auxadc_read(wm831x, input);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
ret *= 1465;
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(wm831x_auxadc_read_uv);
|
|
|
|
void wm831x_auxadc_init(struct wm831x *wm831x)
|
|
{
|
|
int ret;
|
|
|
|
mutex_init(&wm831x->auxadc_lock);
|
|
INIT_LIST_HEAD(&wm831x->auxadc_pending);
|
|
|
|
if (wm831x->irq) {
|
|
wm831x->auxadc_read = wm831x_auxadc_read_irq;
|
|
|
|
ret = request_threaded_irq(wm831x_irq(wm831x,
|
|
WM831X_IRQ_AUXADC_DATA),
|
|
NULL, wm831x_auxadc_irq,
|
|
IRQF_ONESHOT,
|
|
"auxadc", wm831x);
|
|
if (ret < 0) {
|
|
dev_err(wm831x->dev, "AUXADC IRQ request failed: %d\n",
|
|
ret);
|
|
wm831x->auxadc_read = NULL;
|
|
}
|
|
}
|
|
|
|
if (!wm831x->auxadc_read)
|
|
wm831x->auxadc_read = wm831x_auxadc_read_polled;
|
|
}
|