From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Stefan Agner <stefan@agner.ch>,
Fugang Duan <B38611@freescale.com>,
Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 3.19 060/101] iio: adc: vf610: use ADC clock within specification
Date: Fri, 17 Apr 2015 15:28:48 +0200 [thread overview]
Message-ID: <20150417132516.972192853@linuxfoundation.org> (raw)
In-Reply-To: <20150417132514.379828774@linuxfoundation.org>
3.19-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stefan Agner <stefan@agner.ch>
commit f54e9f2be312a4e71b54aea865b2e33ccb95ef0c upstream.
Depending on conversion mode used, the ADC clock (ADCK) needs
to be below a maximum frequency. According to Vybrid's data
sheet this is 20MHz for the low power conversion mode.
The ADC clock is depending on input clock, which is the bus
clock by default. Vybrid SoC are typically clocked at at 400MHz
or 500MHz, which leads to 66MHz or 83MHz bus clock respectively.
Hence, a divider of 8 is required to stay below the specified
maximum clock of 20MHz.
Due to the different bus clock speeds, the resulting sampling
frequency is not static. Hence use the ADC clock and calculate
the actual available sampling frequency dynamically.
This fixes bogous values observed on some 500MHz clocked Vybrid
SoC. The resulting value usually showed Bit 9 being stuck at 1,
or 0, which lead to a value of +/-512.
Signed-off-by: Stefan Agner <stefan@agner.ch>
Acked-by: Fugang Duan <B38611@freescale.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/iio/adc/vf610_adc.c | 91 +++++++++++++++++++++++++++++---------------
1 file changed, 61 insertions(+), 30 deletions(-)
--- a/drivers/iio/adc/vf610_adc.c
+++ b/drivers/iio/adc/vf610_adc.c
@@ -141,9 +141,13 @@ struct vf610_adc {
struct regulator *vref;
struct vf610_adc_feature adc_feature;
+ u32 sample_freq_avail[5];
+
struct completion completion;
};
+static const u32 vf610_hw_avgs[] = { 1, 4, 8, 16, 32 };
+
#define VF610_ADC_CHAN(_idx, _chan_type) { \
.type = (_chan_type), \
.indexed = 1, \
@@ -180,35 +184,47 @@ static const struct iio_chan_spec vf610_
/* sentinel */
};
-/*
- * ADC sample frequency, unit is ADCK cycles.
- * ADC clk source is ipg clock, which is the same as bus clock.
- *
- * ADC conversion time = SFCAdder + AverageNum x (BCT + LSTAdder)
- * SFCAdder: fixed to 6 ADCK cycles
- * AverageNum: 1, 4, 8, 16, 32 samples for hardware average.
- * BCT (Base Conversion Time): fixed to 25 ADCK cycles for 12 bit mode
- * LSTAdder(Long Sample Time): fixed to 3 ADCK cycles
- *
- * By default, enable 12 bit resolution mode, clock source
- * set to ipg clock, So get below frequency group:
- */
-static const u32 vf610_sample_freq_avail[5] =
-{1941176, 559332, 286957, 145374, 73171};
+static inline void vf610_adc_calculate_rates(struct vf610_adc *info)
+{
+ unsigned long adck_rate, ipg_rate = clk_get_rate(info->clk);
+ int i;
+
+ /*
+ * Calculate ADC sample frequencies
+ * Sample time unit is ADCK cycles. ADCK clk source is ipg clock,
+ * which is the same as bus clock.
+ *
+ * ADC conversion time = SFCAdder + AverageNum x (BCT + LSTAdder)
+ * SFCAdder: fixed to 6 ADCK cycles
+ * AverageNum: 1, 4, 8, 16, 32 samples for hardware average.
+ * BCT (Base Conversion Time): fixed to 25 ADCK cycles for 12 bit mode
+ * LSTAdder(Long Sample Time): fixed to 3 ADCK cycles
+ */
+ adck_rate = ipg_rate / info->adc_feature.clk_div;
+ for (i = 0; i < ARRAY_SIZE(vf610_hw_avgs); i++)
+ info->sample_freq_avail[i] =
+ adck_rate / (6 + vf610_hw_avgs[i] * (25 + 3));
+}
static inline void vf610_adc_cfg_init(struct vf610_adc *info)
{
+ struct vf610_adc_feature *adc_feature = &info->adc_feature;
+
/* set default Configuration for ADC controller */
- info->adc_feature.clk_sel = VF610_ADCIOC_BUSCLK_SET;
- info->adc_feature.vol_ref = VF610_ADCIOC_VR_VREF_SET;
+ adc_feature->clk_sel = VF610_ADCIOC_BUSCLK_SET;
+ adc_feature->vol_ref = VF610_ADCIOC_VR_VREF_SET;
+
+ adc_feature->calibration = true;
+ adc_feature->ovwren = true;
- info->adc_feature.calibration = true;
- info->adc_feature.ovwren = true;
+ adc_feature->res_mode = 12;
+ adc_feature->sample_rate = 1;
+ adc_feature->lpm = true;
- info->adc_feature.clk_div = 1;
- info->adc_feature.res_mode = 12;
- info->adc_feature.sample_rate = 1;
- info->adc_feature.lpm = true;
+ /* Use a save ADCK which is below 20MHz on all devices */
+ adc_feature->clk_div = 8;
+
+ vf610_adc_calculate_rates(info);
}
static void vf610_adc_cfg_post_set(struct vf610_adc *info)
@@ -290,12 +306,10 @@ static void vf610_adc_cfg_set(struct vf6
cfg_data = readl(info->regs + VF610_REG_ADC_CFG);
- /* low power configuration */
cfg_data &= ~VF610_ADC_ADLPC_EN;
if (adc_feature->lpm)
cfg_data |= VF610_ADC_ADLPC_EN;
- /* disable high speed */
cfg_data &= ~VF610_ADC_ADHSC_EN;
writel(cfg_data, info->regs + VF610_REG_ADC_CFG);
@@ -435,10 +449,27 @@ static irqreturn_t vf610_adc_isr(int irq
return IRQ_HANDLED;
}
-static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("1941176, 559332, 286957, 145374, 73171");
+static ssize_t vf610_show_samp_freq_avail(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct vf610_adc *info = iio_priv(dev_to_iio_dev(dev));
+ size_t len = 0;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(info->sample_freq_avail); i++)
+ len += scnprintf(buf + len, PAGE_SIZE - len,
+ "%u ", info->sample_freq_avail[i]);
+
+ /* replace trailing space by newline */
+ buf[len - 1] = '\n';
+
+ return len;
+}
+
+static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(vf610_show_samp_freq_avail);
static struct attribute *vf610_attributes[] = {
- &iio_const_attr_sampling_frequency_available.dev_attr.attr,
+ &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
NULL
};
@@ -502,7 +533,7 @@ static int vf610_read_raw(struct iio_dev
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_CHAN_INFO_SAMP_FREQ:
- *val = vf610_sample_freq_avail[info->adc_feature.sample_rate];
+ *val = info->sample_freq_avail[info->adc_feature.sample_rate];
*val2 = 0;
return IIO_VAL_INT;
@@ -525,9 +556,9 @@ static int vf610_write_raw(struct iio_de
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
for (i = 0;
- i < ARRAY_SIZE(vf610_sample_freq_avail);
+ i < ARRAY_SIZE(info->sample_freq_avail);
i++)
- if (val == vf610_sample_freq_avail[i]) {
+ if (val == info->sample_freq_avail[i]) {
info->adc_feature.sample_rate = i;
vf610_adc_sample_set(info);
return 0;
next prev parent reply other threads:[~2015-04-17 13:28 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-17 13:27 [PATCH 3.19 000/101] 3.19.5-stable review Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 001/101] ALSA: hda - Add dock support for Thinkpad T450s (17aa:5036) Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 002/101] ALSA: hda - Add one more node in the EAPD supporting candidate list Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 003/101] ALSA: usb - Creative USB X-Fi Pro SB1095 volume knob support Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 004/101] ALSA: bebob: fix to processing in big-endian machine for sending cue Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 005/101] ALSA: hda/realtek - Make more stable to get pin sense for ALC283 Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 006/101] ALSA: hda - Fix headphone pin config for Lifebook T731 Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 007/101] PCI/AER: Avoid info leak in __print_tlp_header() Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 008/101] PCI: cpcihp: Add missing curly braces in cpci_configure_slot() Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 009/101] Revert "sparc/PCI: Clip bridge windows to fit in upstream windows" Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 010/101] PCI: Dont look for ACPI hotplug parameters if ACPI is disabled Greg Kroah-Hartman
2015-04-17 13:27 ` [PATCH 3.19 011/101] PCI: spear: Drop __initdata from spear13xx_pcie_driver Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 012/101] ARC: SA_SIGINFO ucontext regs off-by-one Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 013/101] ARC: signal handling robustify Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 014/101] ARM: sunxi: Have ARCH_SUNXI select RESET_CONTROLLER for clock driver usage Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 015/101] selinux: fix sel_write_enforce broken return value Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 016/101] blk-mq: fix use of incorrect goto label in blk_mq_init_queue error path Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 017/101] blkmq: Fix NULL pointer deref when all reserved tags in Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 018/101] Fix bug in blk_rq_merge_ok Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 019/101] block: fix blk_stack_limits() regression due to lcm() change Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 020/101] drm: Fixup racy refcounting in plane_force_disable Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 021/101] drm/edid: set ELD for firmware and debugfs override EDIDs Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 023/101] drm/radeon/dpm: fix 120hz handling harder Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 027/101] drm/i915/vlv: save/restore the power context base reg Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 028/101] drm/i915/vlv: remove wait for previous GFX clk disable request Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 030/101] drm/i915: Align initial plane backing objects correctly Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 031/101] btrfs: simplify insert_orphan_item Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 032/101] IB/uverbs: Prevent integer overflow in ib_umem_get address arithmetic Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 033/101] iwlwifi: dvm: run INIT firmware again upon .start() Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 034/101] x86/xen: prepare p2m list for memory hotplug Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 035/101] xen/balloon: before adding hotplugged memory, set frames to invalid Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 036/101] nfsd: return correct openowner when there is a race to put one in the hash Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 037/101] nfsd: return correct lockowner when there is a race on hash insert Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 038/101] sunrpc: make debugfs file creation failure non-fatal Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 039/101] powerpc: fix memory corruption by pnv_alloc_idle_core_states Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 040/101] powerpc: Re-enable dynticks Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 041/101] nbd: fix possible memory leak Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 042/101] mac80211: fix RX A-MPDU session reorder timer deletion Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 043/101] mm: fix anon_vma->degree underflow in anon_vma endless growing prevention Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 044/101] mm/memory hotplug: postpone the reset of obsolete pgdat Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 045/101] mm/page_alloc.c: call kernel_map_pages in unset_migrateype_isolate Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 046/101] sched: Fix RLIMIT_RTTIME when PI-boosting to RT Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 047/101] cpufreq: Schedule work for the first-online CPU on resume Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 048/101] writeback: add missing INITIAL_JIFFIES init in global_update_bandwidth() Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 049/101] writeback: fix possible underflow in write bandwidth calculation Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 050/101] libata: Update Crucial/Micron blacklist Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 051/101] libata: Blacklist queued TRIM on Samsung SSD 850 Pro Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 053/101] USB: keyspan_pda: add new device id Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 054/101] USB: ftdi_sio: Added custom PID for Synapse Wireless product Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 055/101] USB: ftdi_sio: Use jtag quirk for SNAP Connect E10 Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 056/101] Defer processing of REQ_PREEMPT requests for blocked devices Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 057/101] iio: inv_mpu6050: Clear timestamps fifo while resetting hardware fifo Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 058/101] iio: core: Fix double free Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 059/101] iio: bmc150: change sampling frequency Greg Kroah-Hartman
2015-04-17 13:28 ` Greg Kroah-Hartman [this message]
2015-04-17 13:28 ` [PATCH 3.19 061/101] iio: imu: Use iio_trigger_get for indio_dev->trig assignment Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 062/101] dmaengine: edma: fix memory leak when terminating running transfers Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 063/101] dmaengine: omap-dma: Fix memory leak when terminating running transfer Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 064/101] ath9k: fix tracking of enabled AP beacons Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 065/101] x86/reboot: Add ASRock Q1900DC-ITX mainboard reboot quirk Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 066/101] can: flexcan: fix bus-off error state handling Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 067/101] can: flexcan: Deferred on Regulator return EPROBE_DEFER Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 068/101] firmware: dmi_scan: Prevent dmi_num integer overflow Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 069/101] cpuidle: remove state_count field from struct cpuidle_device Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 070/101] cpuidle: ACPI: do not overwrite name and description of C0 Greg Kroah-Hartman
2015-04-17 13:28 ` [PATCH 3.19 071/101] usb: xhci: handle Config Error Change (CEC) in xhci driver Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 072/101] usb: xhci: apply XHCI_AVOID_BEI quirk to all Intel xHCI controllers Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 073/101] tty: serial: fsl_lpuart: specify transmit FIFO size Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 074/101] tty: serial: fsl_lpuart: clear receive flag on FIFO flush Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 075/101] n_tty: Fix read buffer overwrite when no newline Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 076/101] cifs: smb2_clone_range() - exit on unhandled error Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 077/101] cifs: fix use-after-free bug in find_writable_file Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 078/101] brcmfmac: disable MBSS feature for BCM43362 Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 079/101] iommu/vt-d: Detach domain *only* from attached iommus Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 080/101] rtlwifi: Fix IOMMU mapping leak in AP mode Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 081/101] drivers/of: Add empty ranges quirk for PA-Semi Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 082/101] Revert "PM / hibernate: avoid unsafe pages in e820 reserved regions" Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 083/101] Revert "libceph: use memalloc flags for net IO" Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 084/101] be2iscsi: Fix kernel panic when device initialization fails Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 085/101] ocfs2: _really_ sync the right range Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 086/101] ioctx_alloc(): fix vma (and file) leak on failure Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 087/101] iscsi target: fix oops when adding reject pdu Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 088/101] [media] sh_veu: v4l2_dev wasnt set Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 089/101] [media] media: s5p-mfc: fix mmap support for 64bit arch Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 090/101] [media] cx23885: fix querycap Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 091/101] [media] soc-camera: Fix devm_kfree() in soc_of_bind() Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 092/101] [media] vb2: Fix dma_dir setting for dma-contig mem type Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 093/101] [media] vb2: fix UNBALANCED warnings when calling vb2_thread_stop() Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 096/101] IB/mlx4: Saturate RoCE port PMA counters in case of overflow Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 097/101] timers/tick/broadcast-hrtimer: Fix suspicious RCU usage in idle loop Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 098/101] ext4: fix indirect punch hole corruption Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 099/101] xfs: ensure truncate forces zeroed blocks to disk Greg Kroah-Hartman
2015-04-17 13:29 ` [PATCH 3.19 101/101] kvm: avoid page allocation failure in kvm_set_memory_region() Greg Kroah-Hartman
2015-04-17 17:34 ` [PATCH 3.19 000/101] 3.19.5-stable review Shuah Khan
2015-04-17 19:43 ` Greg Kroah-Hartman
2015-04-17 20:03 ` Guenter Roeck
2015-04-18 18:59 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150417132516.972192853@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=B38611@freescale.com \
--cc=jic23@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stefan@agner.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).