Commit Graph

2994 Commits

Author SHA1 Message Date
Tao Huang
5b30e653ca clk: rockchip: build depends on CPU config
Change-Id: Ia35e7bba3eb7bd37f8f291d7501681a6ccea421f
Signed-off-by: Tao Huang <huangtao@rock-chips.com>
2018-03-13 18:38:21 +08:00
shengfei Xu
2fcb17dc99 regulator: rk808: rk809: the sw1 enable bit intercnvert with sw2
Change-Id: I240ac375005e0521c808c09b3f7f07e9899bda63
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2018-02-13 11:21:32 +08:00
Tao Huang
375c137b91 drivers/regulator/syr82x: fix compile warning
drivers/regulator/syr82x.c:451:3: warning: this if
clause does not guard... [-Wmisleading-indentation]

Change-Id: Ibdb1f6f903d1e0dece7b58aa3ec89d075e6d5b79
Signed-off-by: Tao Huang <huangtao@rock-chips.com>
2018-02-13 10:29:31 +08:00
tony.xie
4a56c8edc7 mfd: RK817 & RK809: Add new mfd driver for RK817 & RK809
The RK817 & RK809 chip is a power management IC for multimedia and handheld
devices. It contains the following components:

- Regulators
- RTC
- Clkout
- Pinctrl
- Powerkey

The RK817 & RK809 core driver is registered as a platform driver and provides
communication through I2C with the host device for the different
components.

The following is the different between the RK817 and the RK809.
1、The dcdc-buck5 is a boost dcdc for RK817 and is a buck for RK809.
2、The RK817 have one switch but The Rk809 have two.
3、The RK817 have a charger and powerpatch function but RK809 not.

Change-Id: I132029c5b28978db7ae06e13c327a1edf70f5b69
Signed-off-by: Tony Xie <tony.xie@rock-chips.com>
2018-02-05 16:18:20 +08:00
Tao Huang
707eebb0c9 regulator: debugfs: Adding debugfs functions into regulator framework
This change allows the user to read and edit regulator information
in user space through the debugfs file system.

Base on msm work.

Change-Id: I4b40d4fd662e3d3d0856127e8e030fa60e938df9
Signed-off-by: Tao Huang <huangtao@rock-chips.com>
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
2018-02-02 19:21:32 +08:00
Tao Huang
f9eefeeaa7 rk: add SPDX license identifier to files with no license
Change-Id: I754250669891307b0deab2bdab1bd01512713f79
Signed-off-by: Tao Huang <huangtao@rock-chips.com>
2018-01-31 20:56:06 +08:00
shengfei Xu
7051792ae3 regulator: rk808: rk816: fix up the DCDC and LDO setting off in sleep mode
Change-Id: I1022a7a8951a3115ac01a43f2165b5eac6202ab4
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2017-12-13 17:24:55 +08:00
shengfei Xu
14d16c1848 regulator: rk808: maps a hardware mode defined in a DTS to a standard mode
Change-Id: I304e0cbb3544abde112180b6ec459670d91c99ae
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2017-12-13 17:23:19 +08:00
shengfei Xu
f814345198 pmic: rk808: rk816: fix up the RK816 setting voltage drop make the system crash
Before adjusting voltage, increase clk_cpu div and reduce CPU frequency
Only support for RK312x chips.

Change-Id: Id327da9590f7d9d383450e79acd1b309e05cd024
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2017-12-11 14:18:04 +08:00
Tao Huang
afd240d168 Merge branch 'linux-linaro-lsk-v4.4-android' of git://git.linaro.org/kernel/linux-linaro-stable.git
* linux-linaro-lsk-v4.4-android: (510 commits)
  Linux 4.4.103
  Revert "sctp: do not peel off an assoc from one netns to another one"
  xen: xenbus driver must not accept invalid transaction ids
  s390/kbuild: enable modversions for symbols exported from asm
  ASoC: wm_adsp: Don't overrun firmware file buffer when reading region data
  btrfs: return the actual error value from from btrfs_uuid_tree_iterate
  ASoC: rsnd: don't double free kctrl
  netfilter: nf_tables: fix oob access
  netfilter: nft_queue: use raw_smp_processor_id()
  spi: SPI_FSL_DSPI should depend on HAS_DMA
  staging: iio: cdc: fix improper return value
  iio: light: fix improper return value
  mac80211: Suppress NEW_PEER_CANDIDATE event if no room
  mac80211: Remove invalid flag operations in mesh TSF synchronization
  drm: Apply range restriction after color adjustment when allocation
  ALSA: hda - Apply ALC269_FIXUP_NO_SHUTUP on HDA_FIXUP_ACT_PROBE
  ath10k: set CTS protection VDEV param only if VDEV is up
  ath10k: fix potential memory leak in ath10k_wmi_tlv_op_pull_fw_stats()
  ath10k: ignore configuring the incorrect board_id
  ath10k: fix incorrect txpower set by P2P_DEVICE interface
  ...

Conflicts:
	drivers/media/v4l2-core/v4l2-ctrls.c
	kernel/sched/fair.c

Change-Id: I48152b2a0ab1f9f07e1da7823119b94f9b9e1751
2017-12-01 11:04:13 +08:00
Guillaume Tucker
a272dc770f regulator: fan53555: fix I2C device ids
commit fc1111b885 upstream.

The device tree nodes all correctly describe the regulators as
syr827 or syr828, but the I2C device id is currently set to the
wildcard value of syr82x in the driver.  This causes udev to fail
to match the driver module with the modalias data from sysfs.

Fix this by replacing the I2C device ids with ones that match the
device tree descriptions, with syr827 and syr828.  Tested on
Firefly rk3288 board.  The syr82x id was not used anywhere.

Fixes: e80c47bd73 (regulator: fan53555: Export I2C module alias information)
Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-02 09:40:50 +01:00
Joseph Chen
392fd544e8 regulator: rk808: fix rk816 regulators register failed
fix commit: 45a046e.
regulator framework requires continuous regulator id.

Change-Id: I2e2b789c3ab9126e793d9e304ef2a44d8f46eacd
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2017-10-31 09:39:45 +08:00
shengfei Xu
dce2f990d7 regulator: rk808: fix the regulator control value in system suspend for rk816
set 1 if the regulator is enabled in system suspend, 0 if not.

Change-Id: I8d51ac685bbd2417f440842d010fe47946c9f567
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2017-10-26 10:07:42 +08:00
Joseph Chen
45a046e864 regulator: rk808: delete rk816 boost and otg switch regulator
Due to hardware issue, boost and otg switch must be conctrolled
with special timing carefully by rk816 battery driver. Otherwise
boost maybe burn off.

Change-Id: Id28208c5b9757e1ff0e57ec5d26f1ac0afb88ad5
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2017-10-25 14:38:42 +08:00
shengfei Xu
5256a970bf regulator: rk808: fix the enable_val of rk816
The bitmask value must equal enable_val, then the regulator can
be enabled with the regulator output at the predefined voltage.

Change-Id: Ieadac80c04f3826b364d6fd9fa2e3c956f79b6c4
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2017-08-28 11:31:22 +08:00
shengfei Xu
f6cd885bf2 regulator: rk808: add support for get_mode/set_mode/set_suspend_mode on regulators
The regulators support mode switching, so add support for
these ops to those types of regulators

Change-Id: Ia2d052aed85988c10137ecc5681867bed2d44c24
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2017-08-23 20:38:30 +08:00
shengfei Xu
8516153ecb regulator: rk808: fix regulator operations table to the bucks for rk816
the patch fixes the following BUG:
[    2.249731] PC is at regulator_map_voltage_linear+0x78/0x16c
[    2.255413] LR is at regulator_map_voltage_linear+0x68/0x16c
[    2.261092] pc : [<c042c1a8>]    lr : [<c042c198>]    psr: 60000013
[    2.261092] sp : ef0a5a08  ip : 00000000  fp : c0c34368
[    2.272578] r10: 000b71b0  r9 : c120394c  r8 : 000b71b0
[    2.277817] r7 : 000b71b0  r6 : ee85b800  r5 : 000b71b0  r4 : ee85b800
[    2.284357] r3 : 00000000  r2 : dc8ba64d  r1 : 60000013  r0 : 00000021
[    2.290899] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
[    2.298047] Control: 10c5387d  Table: 6000406a  DAC: 00000051

Change-Id: I4a0d773f7847e7af14d1850e2250671a216b0c86
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2017-08-23 20:37:15 +08:00
shengfei Xu
ce4e02a88b mfd: rk808: add rk816 support
include sub modules: regulator, rtc, gpio, pwrkey

Change-Id: I59cc4b943403f1e0b1210a314cfcbf61fc193bdf
Signed-off-by: shengfei Xu <xsf@rock-chips.com>
2017-07-19 14:33:51 +08:00
Huang, Tao
bdc986dd0b regulator: remove unused rockchip-pwm-regulator driver
Change-Id: I20594d198f49f6232b409031884ca27f95470592
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
2017-07-14 10:16:41 +08:00
Huang, Tao
ad2fc3b29a Merge tag 'lsk-v4.4-17.05-android' of git://git.linaro.org/kernel/linux-linaro-stable.git
LSK 17.05 v4.4-android

* tag 'lsk-v4.4-17.05-android': (266 commits)
  BACKPORT: mm/slab: clean up DEBUG_PAGEALLOC processing code
  Linux 4.4.70
  UPSTREAM: arm64: hibernate: Support DEBUG_PAGEALLOC
  BACKPORT: arm64: vmlinux.ld: Add mmuoff data sections and move mmuoff text into idmap
  BACKPORT: arm64: Create sections.h
  ANDROID: uid_sys_stats: defer io stats calulation for dead tasks
  ANDROID: AVB: Fix linter errors.
  ANDROID: AVB: Fix invalidate_vbmeta_submit().
  drivers: char: mem: Check for address space wraparound with mmap()
  nfsd: encoders mustn't use unitialized values in error cases
  drm/edid: Add 10 bpc quirk for LGD 764 panel in HP zBook 17 G2
  PCI: Freeze PME scan before suspending devices
  PCI: Fix pci_mmap_fits() for HAVE_PCI_RESOURCE_TO_USER platforms
  tracing/kprobes: Enforce kprobes teardown after testing
  osf_wait4(): fix infoleak
  genirq: Fix chained interrupt data ordering
  uwb: fix device quirk on big-endian hosts
  metag/uaccess: Check access_ok in strncpy_from_user
  metag/uaccess: Fix access_ok()
  iommu/vt-d: Flush the IOTLB to get rid of the initial kdump mappings
  ...
2017-06-07 10:03:03 +08:00
Richard Cochran
de74aedd71 regulator: tps65023: Fix inverted core enable logic.
commit c90722b54a upstream.

Commit 43530b69d7 ("regulator: Use
regmap_read/write(), regmap_update_bits functions directly") intended
to replace working inline helper functions with standard regmap
calls.  However, it also inverted the set/clear logic of the "CORE ADJ
Allowed" bit.  That patch was clearly never tested, since without that
bit cleared, the core VDCDC1 voltage output does not react to I2C
configuration changes.

This patch fixes the issue by clearing the bit as in the original,
correct implementation.  Note for stable back porting that, due to
subsequent driver churn, this patch will not apply on every kernel
version.

Fixes: 43530b69d7 ("regulator: Use regmap_read/write(), regmap_update_bits functions directly")
Signed-off-by: Richard Cochran <rcochran@linutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-25 14:30:09 +02:00
Jon Hunter
3e19487b9b regulator: core: Clear the supply pointer if enabling fails
commit 8e5356a736 upstream.

During the resolution of a regulator's supply, we may attempt to enable
the supply if the regulator itself is already enabled. If enabling the
supply fails, then we will call _regulator_put() for the supply.
However, the pointer to the supply has not been cleared for the
regulator and this will cause a crash if we then unregister the
regulator and attempt to call regulator_put() a second time for the
supply. Fix this by clearing the supply pointer if enabling the supply
after fails when resolving the supply for a regulator.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-05-02 21:19:49 -07:00
Wadim Egorov
0d8cf581f9 UPSTREAM: regulator: fan53555: Add support for FAN53555UC13X type
IC type options 00, 13 and 23 are sharing the same DIE_ID 0.
Let's differentiate between these revisions.
FAN53555UC13X has the ID 0 and REV 0xf, starts at 800mV and
increments in 10mV steps.

Change-Id: I3fdcd305013ccef73145da2b84f303021304876a
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit e57cbb70b7)
Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
2017-04-20 08:45:18 +08:00
Wadim Egorov
f3db077f8b UPSTREAM: regulator: fan53555: Add support for FAN53555BUC18X type
FAN53555BUC18X has the DIE_ID 8, starts at 600mV and
increments in 10mV steps.

Change-Id: If4f7d2d911748c42e79ad8268b884275d4230aef
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 5e39cf4972)
Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
2017-04-20 08:45:06 +08:00
Wadim Egorov
9d6c273f92 FROMLIST: regulator: rk808: Fix RK818 LDO2
Set the correct voltage select register for LDO2.

(am from https://patchwork.kernel.org/patch/9639275/)
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
Change-Id: I877d482e937920cdb3bf820a7c2cf7c650b24eff
Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
2017-04-20 08:43:08 +08:00
Huang, Tao
77bab04357 Merge tag 'lsk-v4.4-17.03-android' of git://git.linaro.org/kernel/linux-linaro-stable.git
LSK 17.03 v4.4-android

* tag 'lsk-v4.4-17.03-android': (166 commits)
  Linux 4.4.55
  ext4: don't BUG when truncating encrypted inodes on the orphan list
  dm: flush queued bios when process blocks to avoid deadlock
  nfit, libnvdimm: fix interleave set cookie calculation
  s390/kdump: Use "LINUX" ELF note name instead of "CORE"
  KVM: s390: Fix guest migration for huge guests resulting in panic
  mvsas: fix misleading indentation
  serial: samsung: Continue to work if DMA request fails
  USB: serial: io_ti: fix information leak in completion handler
  USB: serial: io_ti: fix NULL-deref in interrupt callback
  USB: iowarrior: fix NULL-deref in write
  USB: iowarrior: fix NULL-deref at probe
  USB: serial: omninet: fix reference leaks at open
  USB: serial: safe_serial: fix information leak in completion handler
  usb: host: xhci-plat: Fix timeout on removal of hot pluggable xhci controllers
  usb: host: xhci-dbg: HCIVERSION should be a binary number
  usb: gadget: function: f_fs: pass companion descriptor along
  usb: dwc3: gadget: make Set Endpoint Configuration macros safe
  usb: gadget: dummy_hcd: clear usb_gadget region before registration
  powerpc: Emulation support for load/store instructions on LE
  ...

Change-Id: I4db95bbe5b2523e19ddf22b3f65863f7f6d46632
2017-03-31 11:43:47 +08:00
Leonard Crestez
5cc0cd0e3a regulator: Fix regulator_summary for deviceless consumers
commit e42a46b6f5 upstream.

It is allowed to call regulator_get with a NULL dev argument
(_regulator_get explicitly checks for it) but this causes an error later
when printing /sys/kernel/debug/regulator_summary.

Fix this by explicitly handling "deviceless" consumers in the debugfs code.

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-03-12 06:37:25 +01:00
Boris Brezillon
d81d8e4b87 UPSTREAM: regulator: pwm: Support extra continuous mode cases
The continuous mode allows one to declare a PWM regulator without having
to declare the voltage <-> dutycycle association table. It works fine as
long as your voltage(dutycycle) function is linear, but also has the
following constraints:

- dutycycle for min_uV = 0%
- dutycycle for max_uV = 100%
- dutycycle for min_uV < dutycycle for max_uV

While the linearity constraint is acceptable for now, we sometimes need to
restrict of the PWM range (to limit the maximum/minimum voltage for
example) or have a min_uV_dutycycle > max_uV_dutycycle (this could be
tweaked with PWM polarity, but not all PWMs support inverted polarity).

Add the pwm-dutycycle-range and pwm-dutycycle-unit DT properties to define
such constraints. If those properties are not defined, the PWM regulator
use the default pwm-dutycycle-range = <0 100> and
pwm-dutycycle-unit = <100> values (existing behavior).

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
(cherry picked from commit ea398e2873)

Change-Id: I6e10c93a6620113e1463221d461fc23ccf3fe398
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Boris Brezillon
ccdd153753 UPSTREAM: regulator: pwm: Retrieve correct voltage
The continuous PWM voltage regulator is caching the voltage value in
the ->volt_uV field. While most of the time this value should reflect the
real voltage, sometime it can be sightly different if the PWM device
rounded the set_duty_cycle request.
Moreover, this value is not valid until someone has modified the regulator
output.

Remove the ->volt_uV field and always rely on the PWM state to calculate
the regulator output.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
(cherry picked from commit d9070fdbe4)

Change-Id: Iba7b143c1b08d547b5cd46ac42d9051fb34309df
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Boris Brezillon
cada6fee2f UPSTREAM: regulator: pwm: Properly initialize the ->state field
The ->state field is currently initialized to 0, thus referencing the
voltage selector at index 0, which might not reflect the current
voltage value.
If possible, retrieve the current voltage selector from the PWM state,
else return -EINVAL.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Brian Norris <briannorris@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
(cherry picked from commit 87248991a1)

Change-Id: I179395dc7bad7aa867e68c92be7ce92b03ae7112
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Boris Brezillon
d9e3d266ec UPSTREAM: regulator: pwm: Switch to the atomic PWM API
Use the atomic API wherever appropriate and get rid of pwm_apply_args()
call (the reference period and polarity are now explicitly set when
calling pwm_apply_state()).

We also make use of the pwm_set_relative_duty_cycle() helper to ease
relative to absolute duty_cycle conversion.

Note that changes introduced by commit fd786fb027 ("regulator: pwm:
Try to avoid voltage error in duty cycle calculation") are no longer
needed because pwm_set_relative_duty_cycle() takes care of all rounding
approximation for us.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
(cherry picked from commit 3f4eb39be9)

Change-Id: Id12d4d625fb6e1e5ff3725737cc9232e4df40c36
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Boris Brezillon
5452a5568c UPSTREAM: regulator: pwm: Adjust PWM config at probe time
The PWM attached to a PWM regulator device might have been previously
configured by the bootloader.
Make sure the bootloader and linux config are in sync, and adjust the PWM
config if that's not the case.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
(cherry picked from commit fd4f99c4c3)

Change-Id: I06abddddc4666cd6510b6317795931f282e44eb0
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Douglas Anderson
89ae836944 UPSTREAM: regulator: pwm: Fix regulator ramp delay for continuous mode
The original commit adding support for continuous voltage mode didn't
handle the regulator ramp delay properly.  It treated the delay as a
fixed delay in uS despite the property being defined as uV / uS.  Let's
adjust it.  Luckily there appear to be no users of this ramp delay for
PWM regulators (as per grepping through device trees in linuxnext).

Note also that the upper bound of usleep_range probably shouldn't be a
full 1 ms longer than the lower bound since I've seen plenty of hardware
with a ramp rate of ~5000 uS / uV and for small jumps the total delays
are in the tens of uS.  1000 is way too much.  We'll try to be dynamic
and use 10%.

NOTE: This commit doesn't add support for regulator-enable-ramp-delay.
That could be done in a future patch when someone has a user of that
featre.

Though this patch is shows as "fixing" a bug, there are no actual known
users of continuous mode PWM regulator w/ ramp delay in mainline and so
this likely won't have any effect on anyone unless they are working
out-of-tree with private patches.  For anyone in this state, it is
highly encouraged to also pick Boris Brezillon's WIP patches to get
yourself a reliable and glitch-free regulator.

Fixes: 4773be185a ("regulator: pwm-regulator: Add support for continuous-voltage")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Acked-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit c2588393e6)

Change-Id: Ib0af8e04275813f333af12d48567b7e411b4d49f
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Alexandre Courbot
60dc7d8eda UPSTREAM: regulator: pwm: Support for enable GPIO
Add an optional enable GPIO to the pwm-regulator driver.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 27bfa8893b)

Change-Id: I6530165e6bccb4fc82d2916d169a02ecdcbfcd3e
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Boris Brezillon
d1b4c71db8 UPSTREAM: regulator: pwm: Drop unneeded pwm_enable() call
Now that the PWM regulator driver implements the ->enable/disable() hooks
we can remove the pwm_enable() call from pwm_regulator_set_voltage().

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 830583004e)

Change-Id: I89fba9a44d98ed94ede099b841b7358ba4011e35
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Boris Brezillon
e4041f3958 UPSTREAM: regulator: pwm: Use pwm_get_args() where appropriate
The PWM framework has clarified the concept of reference PWM config (the
platform dependent config retrieved from the DT or the PWM lookup table)
and real PWM state.

Use pwm_get_args() when the PWM user wants to retrieve this reference
config and not the current state.

This is part of the rework allowing the PWM framework to support
hardware readout and expose real PWM state even when the PWM has just
been requested (before the user calls pwm_config/enable/disable()).

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
(cherry picked from 8c12ad8e91)

Conflicts:
	drivers/regulator/pwm-regulator.c

Change-Id: Id7fb1d823db7a0be207de4f0393e6c86df143335
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Jon Hunter
9f7ad83534 UPSTREAM: regulator: core: Add early supply resolution for regulators
The call to set_machine_constraints() in regulator_register(), will
attempt to get the voltage for the regulator. If a regulator is in
bypass will fail to get the voltage (ie. it's bypass voltage) and
hence register the regulator, because the supply for the regulator has
not been resolved yet.

To fix this, add a call to regulator_resolve_supply() before we call
set_machine_constraints(). If the call to regulator_resolve_supply()
fails, rather than returning an error at this point, allow the
registration of the regulator to continue because for some regulators
resolving the supply at this point may not be necessary and it will be
resolved later as more regulators are added. Furthermore, if the supply
is still not resolved for a bypassed regulator, this will be detected
when we attempt to get the voltage for the regulator and an error will
be propagated at this point.

If a bypassed regulator does not have a supply when we attempt to get
the voltage, rather than returing -EINVAL, return -EPROBE_DEFER instead
to allow the registration of the regulator to be deferred and tried
again later.

Please note that regulator_resolve_supply() will call
regulator_dev_lookup() which may acquire the regulator_list_mutex. To
avoid any deadlocks we cannot hold the regulator_list_mutex when calling
regulator_resolve_supply(). Therefore, rather than holding the lock
around a large portion of the registration code, just hold the lock when
aquiring any GPIOs and setting up supplies because these sections may
add entries to the regulator_map_list and regulator_ena_gpio_list,
respectively.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 45389c4752)

Change-Id: I9a0fa34c92b3326b9563672b74b5651cfd3a96f8
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
WEN Pingbo
0b97d6af04 UPSTREAM: regulator: refactor valid_ops_mask checking code
To make the code more compat and centralized, this patch add a
unified function - regulator_ops_is_valid. So we can add
some extra checking code easily later.

Signed-off-by: WEN Pingbo <pingbo.wen@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 8a34e979f6)

Change-Id: Ib3ffc949004c71abe3b75b4e0ffaf2e303f00d22
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Jon Hunter
14b8d1e030 UPSTREAM: regulator: helpers: Ensure bypass register field matches ON value
When checking bypass state for a regulator, we check to see if any bits
in the bypass mask are set. For most cases this is fine because there is
typically, only a single bit used to determine if the regulator is in
bypass. However, for some regulators, such as LDO6 on AS3722, the bypass
state is indicate by a value rather than a single bit. Therefore, when
checking the bypass state, check that the bypass field matches the ON
value.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit dd1a571dae)

Change-Id: Ic9f9ee919969cc744be7e7c94729ee7ab9e0e7a1
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Jon Hunter
e322305bba UPSTREAM: regulator: core: Move registration of regulator device
The public functions to acquire a regulator, such as regulator_get(),
internally look-up the regulator from the list of regulators that have
been registered with the regulator device class. The registration of
a new regulator with the regulator device class happens before the
regulator has been completely setup. Therefore, it is possible that
the regulator could be acquired before it has been setup successfully.
To avoid this move the device registration of the regulator to the end
of the regulator setup and update the error exit path accordingly.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit c438b9d017)

Change-Id: I9b33820c1ea748fdf5ccfb8949775b753af4a848
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Jon Hunter
2ba368178b UPSTREAM: regulator: core: Clear the supply pointer if enabling fails
During the resolution of a regulator's supply, we may attempt to enable
the supply if the regulator itself is already enabled. If enabling the
supply fails, then we will call _regulator_put() for the supply.
However, the pointer to the supply has not been cleared for the
regulator and this will cause a crash if we then unregister the
regulator and attempt to call regulator_put() a second time for the
supply. Fix this by clearing the supply pointer if enabling the supply
after fails when resolving the supply for a regulator.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 8e5356a736)

Change-Id: I3e83852db8c624fdd5b6c0bcab42c07289501a58
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Jon Hunter
faf68e977e UPSTREAM: regulator: core: Don't terminate supply resolution early
The function regulator_register_resolve_supply() is called from the
context of class_for_each_dev() (during the regulator registration) to
resolve any supplies added. regulator_register_resolve_supply() will
return an error if a regulator's supply cannot be resolved and this will
terminate the loop in class_for_each_dev(). This means that we will not
attempt to resolve any other supplies after one has failed. Hence, this
may delay the resolution of other regulator supplies until the failing
one itself can be resolved.

Rather than terminating the loop early, don't return an error code and
keep attempting to resolve any other supplies for regulators that have
been registered.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 7ddede6a58)

Change-Id: I92644a3c2006476440f0eeca2e4a9717743b13b9
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Richard Fitzgerald
2c0da078a7 UPSTREAM: regulator: core: Add debugfs to show constraint flags
There are debugfs entries for voltage and current, but not for
the constraint flags. It's useful for debugging to be able to
see what these flags are so this patch adds a new debugfs file.
We can't use debugfs_create_bool for this because the flags are
bitfields, so as this needs a special read callback they have been
collected into a single file that lists all the flags.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 2d80a91b2f)

Change-Id: Ia3e78960204e34e004340e28b3a7f933aa457371
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Mark Brown
59ba6e0376 UPSTREAM: regulator: core: Fix locking of GPIO list on free
When we acquire a shareable enable GPIO on probe we do so with the
regulator_list_mutex held.  However when we release the GPIOs we do this
immediately after dropping the mutex meaning that the list could become
corrupted.  Move the release into the locked region to avoid this.

Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 2c0a303a12)

Change-Id: I27a96e1b5ff3034fa068bda5436a479e01e5a61b
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Boris Brezillon
286d645c52 UPSTREAM: regulator: reorder initialization steps in regulator_register()
device_register() is calling ->get_voltage() as part of it's sysfs attribute
initialization process, and this functions might need to know the regulator
constraints to return a valid value.
This is at least true for the pwm regulator driver (when operating in
continuous mode) which needs to know the minimum and maximum voltage values
to calculate the current voltage:

min_uV + (((max_uV - min_uV) * dutycycle) / 100);

Move device_register() after set_machine_constraints() to make sure those
constraints are correctly initialized when ->get_voltage() is called.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reported-by: Stephen Barber <smbarber@chromium.org>
Tested-by: Caesar Wang <wxt@rock-chips.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 469b640e4f)

Change-Id: I83c95e5baef0501876d19f1e2e7a7e3af8631b1f
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Mark Brown
e8177c7621 UPSTREAM: regulator: core: Use parent voltage from the supply when bypassed
When a regulator is in bypass mode it is functioning as a switch
returning the voltage set in the regulator will not give the voltage
being output by the regulator as it's just passing through its supply.
This means that when we are getting the voltage from a regulator we
should check to see if it is in bypass mode and if it is we should
report the voltage from the supply rather than that which is set on the
regulator.

Reported-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
[treding@nvidia.com: return early for bypass mode]
Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

(cherry picked from commit fef9501901)

Change-Id: I889789bce3018bec24ba9a0476217c0573ce9a27
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Laxman Dewangan
782248a23a UPSTREAM: regulator: pwm: Try to avoid voltage error in duty cycle calculation
In continuous mode of the PWM regulators, the requested voltage
PWM duty cycle is calculated in terms of 100% scale where entire
range denotes 100%. The calculation for PWM pulse ON time(duty_pulse)
is done as:

	duty_cycle = ((requested - minimum) * 100) / voltage_range.

then duty pulse is calculated as
	duty_pulse = (pwm_period/100) * duty_cycle

This leads to the calculation error if we have the requested voltage
where accurate pulse time is possible.
For example: Consider following case
	voltage range is 800000uV to 1350000uV.
	pwm-period = 1550ns (1ns time is 1mV).

	Requested 900000uV.

	duty_cycle = ((900000uV - 800000uV) * 100)/ 1550000
		   = 6.45 but we will get 6.

	duty_pulse = (1550/100) * 6 = 90 pulse time.

90 pulse time is equivalent to 90mV and this gives us pulse time equivalent
to 890000uV instead of 900000uV.

Proposing the solution in which if requested voltage makes the accurate
duty pulse then there will not be any error. On this case, if
(req_uV - min_uV) * pwm_period is perfect dividable by voltage_range
then get the duty pulse time directly.

	duty_pulse = ((900000uV - 800000uV) * 1550)/1550000)
		   = 100

and this is equivalent to 100mV and so final voltage is
(800000 + 100000) = 900000uV which is same as requested,

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit fd786fb027)

Change-Id: I08b54da55b29be7f8cbf4c837bc2e2d993ebf9a0
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Jon Hunter
5dc7257e19 UPSTREAM: regulator: Fix deadlock during regulator registration
Commit 5e3ca2b349 ("regulator: Try to resolve regulators supplies on
registration") added a call to regulator_resolve_supply() within
regulator_register() where the regulator_list_mutex is held. This causes
a deadlock to occur on the Tegra114 Dalmore board when the palmas PMIC
is registered because regulator_register_resolve_supply() calls
regulator_dev_lookup() which may try to acquire the regulator_list_mutex
again.

Fix this by releasing the mutex before calling
regulator_register_resolve_supply() and update the error exit path to
ensure the mutex is released on an error.

[Made commit message more legible -- broonie]

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit a215137423)

Change-Id: I65ac4aeac254d2ef3f161c422b92defd5badbbc4
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Mark Brown
b63a6e6e3f UPSTREAM: regulator: of: Don't flag voltage change as possible for exact voltages
Flagging voltage changes as possible for exactly specified voltages
appears to be triggering bugs in the SDHCI code (it should be able to
handle the case where only one voltage it wants is in the range it is
allowed to set) so make sure we only set the flag in cases where there's
genuine variability.

Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 45fa2038cf)

Change-Id: I68c5c8fd3ca2da2ddb07af125f57158441040af3
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00
Mark Brown
c90bbfc477 UPSTREAM: regulator: core: Log when we bring constraints into range
This aids in debugging problems triggered by the regulator core applying
its constraints, we could potentially crash immediately after updating
the voltage if the constraints are buggy.

Signed-off-by: Mark Brown <broonie@kernel.org>
(cherry picked from commit 45a91e8f76)

Change-Id: I8c3e4a856f05c13e6ce3db8a6d46686557109962
Signed-off-by: David Wu <david.wu@rock-chips.com>
2017-03-06 18:28:40 +08:00