Qualcomm Technologies, Inc. CPR regulator for Graphics

GFX CPR controller monitors the voltage of the graphics processor(GPU)
power rail. The CPR open-loop voltages are stored in hardware fuses
for GFX CPR controller. However, the CPR target quotients must be defined
in device tree. This driver supports CPR version 2 controller.

This document describes the bindings that apply for GFX CPR controller.

- compatible
	Usage:      required
	Value type: <string>
	Definition: should be "qcom,cpr2-gfx-regulator"

- reg
	Usage:      required
	Value type: <prop-encoded-array>
	Definition: Addresses and sizes for the memory of the CPR
		    controller and the first fuse row.

- reg-names
	Usage:      required
	Value type: <stringlist>
	Definition: Address names. Must be "rbcpr" and "efuse_addr". Must be
		    specified in the same order as the corresponding addresses
		    are specified in the reg property.

- regulator-name
	Usage:      required
	Value type: <string>
	Definition: A string used to describe the regulator.

- clocks
	Usage:      required
	Value type: <prop-encoded-array>
	Definition: Array of clock tuples in which each tuple consists of a
		    phandle to a clock device and a clock ID number.  The
		    following clocks must be specified: GFX RBCPR, GFX RBCPR
		    AHB.

- clock-names
	Usage:      required
	Value type: <stringlist>
	Definition: Clock names.  This list must match up 1-to-1 with the clocks
		    specified in the 'clocks' property. "core_clk" and "iface_clk"
		    must be specified.

- interrupts
	Usage:      required
	Value type: <prop-encoded-array>
	Definition: CPR interrupt specifier.

- vdd-gfx-supply
	Usage:      required
	Value type: <phandle>
	Definition: phandle of the underlying regulator device that is managed
		    by this CPR controller.

- qcom,cpr-corners
	Usage:      required
	Value type: <u32>
	Definition: Number of voltage corners present. Many other
		    properties are sized based upon this value.

- regulator-min-microvolt
	Usage:      required
	Value type: <u32>
	Definition: Minimum corner value which should be 1 to represent the
		    lowest supported corner.

- regulator-max-microvolt
	Usage:      required
	Value type: <u32>
	Definition: Maximum corner value which should be equal to largest value
		    listed in qcom,cpr-corners.

- qcom,cpr-voltage-ceiling
	Usage:      required
	Value type: <prop-encoded-array>
	Definition: Array of ceiling voltages in microvolts for voltage corners
		    ordered from lowest voltage corner to highest voltage corner.
		    This property must be of length defined by qcom,cpr-corners.

- qcom,cpr-voltage-floor
	Usage:      required
	Value type: <prop-encoded-array>
	Definition: Array of floor voltages in microvolts for voltage corners
		    ordered from lowest voltage corner to highest voltage corner.
		    This property must be of length defined by qcom,cpr-corners.

- qcom,vdd-gfx-step-up-limit
	Usage:      required
	Value type: <u32>
	Definition: Limit of vdd-gfx-supply steps for scaling up.

- qcom,vdd-gfx-step-down-limit
	Usage:      required
	Value type: <u32>
	Definition: Limit of vdd-gfx-supply steps for scaling down.

- qcom,cpr-ref-clk
	Usage:      required
	Value type: <u32>
	Definition: The reference clock rate in kHz.

- qcom,cpr-timer-delay
	Usage:      required
	Value type: <u32>
	Definition: The delay in microseconds for the timer interval.

- qcom,cpr-timer-cons-up
	Usage:      required
	Value type: <u32>
	Definition: The number of consecutive CPR step up events needed to
		    to trigger a up interrupt.  Supported values: 0 - 15.

- qcom,cpr-timer-cons-down
	Usage:      required
	Value type: <u32>
	Definition: The number of consecutive CPR step down events needed to
		    to trigger a down interrupt.  Supported values: 0 - 15.

- qcom,cpr-irq-line
	Usage:      required
	Value type: <u32>
	Definition: Internal interrupt route signal of RBCPR, one of 0, 1 or 2.

- qcom,cpr-step-quotient
	Usage:      required
	Value type: <u32>
	Definition: Defines the number of CPR quotient (i.e. Ring Oscillator(RO)
		    count) per vdd-gfx-supply output voltage step.  A single
		    integer value to be used for all RO's.

- qcom,cpr-gfx-volt-step
	Usage:      required
	Value type: <u32>
	Definition: The voltage in microvolts of a single step of the VDD supply
		    regulator being controlled by CPR.

- qcom,cpr-up-threshold
	Usage:      required
	Value type: <u32>
	Definition: The number CPR error steps required to generate an up event.
		    Supported values: 0 - 31.

- qcom,cpr-down-threshold
	Usage:      required
	Value type: <u32>
	Definition: The number CPR error steps required to generate a down
		    event. Supported values: 0 - 31.

- qcom,cpr-idle-clocks
	Usage:      required
	Value type: <u32>
	Definition: The number of CPR core clock cycles for the CPR controller
		    to wait in transitional states. Supported values: 0 - 31.

- qcom,cpr-gcnt-time
	Usage:      required
	Value type: <u32>
	Definition: The time for gate count in microseconds.

- qcom,cpr-fuse-init-voltage
	Usage:      required
	Value type: <prop-encoded-array>
	Definition: Array of quadruples in which each quadruple specifies a fuse
		    location to read in order to get an initial voltage for a
		    voltage corner. The fuse values are encoded as voltage steps
		    higher or lower than the voltages defined in
		    qcom,cpr-init-voltage-ref. Each step corresponds to the
		    voltage defined by the qcom,cpr-init-voltage-step property.
		    The 3 elements in one quadruple are:
		    [0] => fuse row number
		    [1] => bit offset within the row
		    [2] => number of bits in the fuse parameter
		    The quadruples are ordered from the lowest voltage corner to
		    the highest voltage corner. The number for quadruples must be
		    equal to the value specified in qcom,cpr-corners property.

- qcom,cpr-init-voltage-ref
	Usage:      required
	Value type: <prop-encoded-array>
	Definition: Array of reference voltages in microvolts used when decoding
		    the initial voltage fuse values.  The elements in the array
		    are ordered from lowest voltage corner to highest voltage
		    corner. This property must be of length defined by
		    qcom,cpr-corners.

- qcom,cpr-init-voltage-step
	Usage:      required if qcom,cpr-fuse-init-voltage is specified.
	Value type: <u32>
	Definition: The voltage step size in microvolts of the CPR initial
		    voltage fuses described by the qcom,cpr-fuse-init-voltage
		    property.

- qcom,cpr-ro-count
	Usage:      required
	Value type: <u32>
	Definition: Defines the number of Ring Oscillator(RO)s present.

- qcom,cpr-target-quotients
	Usage:      required
	Value type: <prop-encoded-array>
	Definition: A grouping of integer tuple lists. Each tuple defines the CPR
		    target quotient for each ring oscillator (RO) for a given corner.
		    Each tuple must be of the length defined by qcom,cpr-ro-count.
		    If a given RO is unused for a corner, then its target quotient
		    should be specified as 0. Each tuple list must contain the
		    number of tuples defined by the qcom,cpr-corners property.
		    The tuples in a given list are ordered from the lowest corner
		    to the highest corner. The tuple list grouping must contain
		    exactly 1 list if qcom,cpr-fuse-version-map is not specified or
		    the number of tuple lists must be equal to the number of tuples
		    in qcom,cpr-fuse-version-map.

- vdd-mx-supply
	Usage:      optional
	Value type: <phandle>
	Definition: Regulator to supply memory power as dependency of VDD_GFX.

- qcom,vdd-mx-corner-map
	Usage:      required if vdd-mx-supply is specified.
	Value type: <prop-encoded-array>
	Definition: Array of integers which define the mapping of the VDD_MX corner
		    to the corresponding GFX voltage corner. The elements in
		    the array are ordered from lowest voltage corner to highest
		    voltage corner.  The length of this property must be equal to
		    the value defined by qcom,cpr-corners.

- mem-acc-supply
	Usage:      optional
	Value type: <phandle>
	Definition: Regulator to vote for the memory accelerator configuration.
		    Not Present: memory accelerator configuration not supported.

- qcom,cpr-fuse-revision
	Usage:      optional
	Value type: <prop-encoded-array>
	Definition: Array of 3 integer elements which define the location of the
		    bits for the CPR fusing revision fuse parameter.
		    The 3 elements are:
		    [0] => fuse row number
		    [1] => bit offset within the row
		    [2] => number of bits in the fuse parameter
		    The fusing revision value is used to determine specific
		    adjustments that maybe required on some chips.

- qcom,process-id-fuse
	Usage:      optional
	Value type: <prop-encoded-array>
	Definition: Array of 3 integer elements which define the location of the
		    bits for the process node id fuse parameter.
		    The 3 elements are:
		    [0] => fuse row number
		    [1] => bit offset within the row
		    [2] => number of bits in the fuse parameter
		    This value is used to determine the specific adjustments that
		    may be required on some chips.

- qcom,foundry-id-fuse
	Usage:      optional
	Value type: <prop-encoded-array>
	Definition: Array of 3 integer elements which define the location of the
		    bits for the foundry identification fuse parameter.
		    The 3 elements are:
		    [0] => fuse row number
		    [1] => bit offset within the row
		    [2] => number of bits in the fuse parameter
		    This value is used to determine the specific adjustments that
		    may be required on some chips.

- qcom,cpr-fuse-version-map
	Usage:      optional
	Value type: <prop-encoded-array>
	Definition: Array of integer tuples which each match to a given
		    combination of CPR fuse parameter values.  Each tuple
		    consists of 3 elements. The elements in one tuple are:
		    [0] => the foundry identification
		    [1] => the CPR fuse revision
		    [2] => the process node id
		    Any element in a tuple may use the value 0xffffffff as a
		    wild card which will match against any fuse parameter value.
		    The first tuple that matches against the fuse values read
		    from hardware will be used. This property is used by several
		    properties to provide an index into their lists.

- qcom,cpr-init-voltage-adjustment
	Usage:      optional
	Value type: <prop-encoded-array>
	Definition: Array of integer tuples of initial voltage adjustments in
		    microvolts to add to the fused initial voltage values of
		    each fuse corner. The elements in a tuple are ordered from
		    lowest voltage corner to highest voltage corner. Each tuple
		    must be of the length defined by qcom,cpr-corners.
		    If the qcom,cpr-fuse-version-map property is specified, then
		    qcom,cpr-init-voltage-adjustment must contain the same
		    number of tuples as qcom,cpr-fuse-version-map. These tuples
		    are then mapped one-to-one in the order specified.  E.g. if
		    the second qcom,cpr-fuse-version-map tuple matches for a
		    given device, then the initial voltage adjustments defined
		    in the second qcom,cpr-init-voltage-adjustment tuple will be
		    applied. If the qcom,cpr-fuse-version-map property is not
		    specified, then qcom,cpr-init-voltage-adjustment must contain
		    a single tuple which is then applied unconditionally.  This
		    property can be used to add or subtract static initial voltage
		    margin from the regulator managed by the CPR controller.

- qcom,cpr-init-voltage-as-ceiling
	Usage:      optional
	Value type: <empty>
	Definition: Boolean which indicates that the ceiling voltage used for
		    a given virtual corner may be reduced to the initial voltage
		    value.

 - qcom,cpr-enable
	Usage:      optional
	Value type: <empty>
	Definition: Boolean flag which indicates that the CPR controller
		    should operate in closed-loop mode (i.e. CPR sensing loop
		    enabled) as opposed to open-loop mode (i.e. CPR sensing loop
		    disabled) by default.

- qcom,fuse-remap-source
	Usage:      optional
	Value type: <prop-encoded-array>
	Definition: Array of triplets in which each triplet specifies a fuse location to
		    remap.  The 3 elements in one triplet are:
			    [0] => fuse row number
			    [1] => bit offset within the row
			    [2] => number of bits in the fuse parameter
		    The fuse bits for all triplets are packed together in the order specified
		    into 64-bit virtual fuse rows beginning at the row number defined in the
		    qcom,fuse-remap-base-row property.  The remapped rows may be used by any
		    other properties.
		    Example:
			qcom,fuse-remap-base-row = <1000>;
			qcom,fuse-remap-source =
					<13 57 2>,
					<14 30 3>,
					<20  1 7>,
					<40 47 120>;

			This results in the following bit remapping:

			Row   Bits       Remap Row  Remap Bits
			13    57..58  -->  1000      0..1
			14    30..32  -->  1000      2..4
			20     1..7   -->  1000      5..11
			40    47..63  -->  1000     12..28
			41     0..34  -->  1000     29..63
			41    35..63  -->  1001      0..28
			42     0..34  -->  1001     29..63
			42    35..38  -->  1002      0..3

			A tuple like this could then be used to reference some of the
			concatenated bits from rows 13, 14, and 20:

			qcom,cpr-fuse-init-voltage = <1000 0 6>;

- qcom,fuse-remap-base-row
	Usage:      required if qcom,fuse-remap-source specified.
	Value type: <u32>
	Definition: Integer which defines the virtual row number to use as a base when remapping
		    fuse bits.  The remap base row number can be any value as long as it is
		    greater than all of the real row numbers addressed in other properties of
		    the cpr2-gfx-regulator device node.

- qcom,cpr-aging-sensor-id
	Usage:      optional
	Value type: <prop-encoded-array>
	Definition: Array of CPR sensor IDs to be used in the CPR de-aging algorithm.
		    The number of values should be equal to number of sensors selected
		    for age calibration. If this property is not specified,
		    then the de-aging procedure is not enabled.

- qcom,cpr-de-aging-allowed
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <u32>
	Definition: Integer values that specify whether the CPR de-aging procedure is allowed or
		    not for a particular fuse revision. If the qcom,cpr-fuse-version-map
		    property is specified, then qcom,cpr-de-aging-allowed must contain the same number
		    of elements as there are tuples in qcom,cpr-fuse-version-map. If qcom,cpr-fuse-version-map
		    is not specified, then qcom,cpr-de-aging-allowed must contain a single value that
		    is used unconditionally. An element value of 1 means that the CPR de-aging procedure
		    can be performed for parts with the corresponding fuse revision. An element value of 0
		    means that CPR de-aging cannot be performed.

- qcom,cpr-aging-ref-corner
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <u32>
	Definition: The vdd-gfx-supply reference virtual voltage corner to be set during
		    the CPR de-aging measurements. This corner value is needed to set
		    appropriate voltage on the dependent voltage rails such as vdd-mx
		    and mem-acc.

- cpr-aging-min-gfx-corner
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <u32>
	Definition: The minimum vdd-gfx-supply virtual voltage corner to start the CPR
		    de-aging measurements. This corner value is needed to make sure that
		    gfx CPR sensors are in active state. This corner value should filter
		    out the corners requested by non-gpu clients of gfx voltage rail.

- qcom,cpr-aging-ref-voltage
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <u32>
	Definition: The vdd-gfx-supply reference voltage in microvolts to be set during
		    the CPR de-aging measurements.

- qcom,cpr-max-aging-margin
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <u32>
	Definition: The maximum allowed aging voltage margin in microvolts.
		    This is used to limit the calculated aging voltage margin.

- qcom,cpr-aging-ro-scaling-factor
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <u32>
	Definition: The aging ring oscillator (RO) scaling factor with units of QUOT/V.
		    This value is used for calculating a voltage margin from RO measurements.

- qcom,cpr-ro-scaling-factor
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <prop-encoded-array>
	Definition: Array of scaling factors with units of QUOT/V for each ring oscillator ordered
		    from the lowest to the highest RO. These values are used to calculate
		    the aging voltage margin adjustment for all of the ROs. Since CPR2 supports
		    exactly 8 ROs, the array must contain 8 elements corresponding to RO0 through RO7 in order.
		    If a given RO is unused for a fuse corner, then its scaling factor may be specified as 0.

- qcom,cpr-aging-derate
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <prop-encoded-array>
	Definition: Array of scaling factors which define the amount of derating to apply to the reference
		    aging voltage margin adjustment for each of the fuse corners. Each element has units
		    of uV/mV. This property must be of length defined by qcom,cpr-corners.
		    The elements are ordered from the lowest to the highest corner.

- qcom,cpr-fuse-aging-init-quot-diff
	Usage:      required if qcom,cpr-aging-sensor-id specified
	Value type: <prop-encoded-array>
	Definition: Array of triplets in which each triplet specifies a fuse location to read in
		    order to get an initial quotient difference. The difference between quot min and quot max
		    is fused as the initial quotient difference.
		    The 3 elements are:
		    [0] => fuse row number
		    [1] => bit offset within the row
		    [2] => number of bits in the fuse parameter
		    The number of triplets should be equal to the number of values specified in
		    the qcom,cpr-aging-sensor-id property.

=======
Example
=======
gfx_vreg_corner: regulator@98000 {
	compatible = "qcom,cpr2-gfx-regulator";
	reg = <0x98000 0x1000>, <0xa4000 0x1000>;
	reg-names = "rbcpr", "efuse_addr";
	clocks = <&clock_gcc clk_gcc_rbcpr_gfx_clk>,
		<&clock_gcc clk_gcc_rbcpr_gfx_ahb_clk>;
	clock-names = "core_clk", "iface_clk";
	interrupts = <0 150 0>;

	regulator-name = "gfx_corner";
	qcom,cpr-corners = <8>;
	regulator-min-microvolt = <1>;
	regulator-max-microvolt = <8>;

	qcom,cpr-voltage-ceiling = <810000 865000 900000 950000 1010000 1050000 1110000 1165000>;
	qcom,cpr-voltage-floor =   <755000 755000 755000 795000  835000  855000  920000  945000>;
	vdd-gfx-supply = <&pm8004_s5>;

	vdd-mx-supply = <&pm8950_s6_level_ao>;
	qcom,vdd-mx-vmax = <RPM_SMD_REGULATOR_LEVEL_TURBO>;
	qcom,vdd-mx-corner-map = <RPM_SMD_REGULATOR_LEVEL_SVS>,
				 <RPM_SMD_REGULATOR_LEVEL_SVS>,
				 <RPM_SMD_REGULATOR_LEVEL_SVS>,
				 <RPM_SMD_REGULATOR_LEVEL_SVS>,
				 <RPM_SMD_REGULATOR_LEVEL_SVS_PLUS>,
				 <RPM_SMD_REGULATOR_LEVEL_NOM>,
				 <RPM_SMD_REGULATOR_LEVEL_NOM_PLUS>,
				 <RPM_SMD_REGULATOR_LEVEL_TURBO>;

	mem-acc-supply = <&mem_acc_gfx_vreg_corner>;

	qcom,cpr-ref-clk = <19200>;
	qcom,cpr-timer-delay = <5000>;
	qcom,cpr-timer-cons-up = <0>;
	qcom,cpr-timer-cons-down = <2>;
	qcom,cpr-irq-line = <0>;
	qcom,cpr-step-quotient = <16>;
	qcom,cpr-up-threshold = <2>;
	qcom,cpr-down-threshold = <4>;
	qcom,cpr-idle-clocks = <15>;
	qcom,cpr-gcnt-time = <1>;
	qcom,vdd-gfx-step-up-limit = <1>;
	qcom,vdd-gfx-step-down-limit = <1>;
	qcom,cpr-gfx-volt-step = <5000>;

	qcom,cpr-init-voltage-ref = <865000 865000 950000 950000 950000 1050000 1050000 1165000>;
	qcom,cpr-fuse-init-voltage =
				<72 50 5>,
				<72 50 5>,
				<72 45 5>,
				<72 45 5>,
				<72 45 5>,
				<72 40 5>,
				<72 40 5>,
				<72 35 5>;
	qcom,cpr-init-voltage-step = <12500>;
	qcom,cpr-ro-count = <8>;
	qcom,cpr-init-voltage-as-ceiling;
	qcom,cpr-init-voltage-adjustment =
			<(-55000) 0 (-60000) 0 (60000) 0 (65000) 0>;
	qcom,cpr-target-quotients =
			<513  489  620  574  237 272 144 177>,
			<562  536  675  627  264 303 163 199>,
			<631  606  744  699  315 356 205 245>,
			<780  752  902  854  412 459 283 330>,
			<879  847  1001 949  490 535 351 400>,
			<1010 971  1138 1080 579 626 428 479>,
			<1086 1039 1210 1146 643 684 489 538>,
			<1238 1179 1367 1290 752 789 586 633>;

	qcom,fuse-remap-base-row = <1000>;
	qcom,fuse-remap-source =
				<59 12 6>,
				<72 30 2>;

	qcom,cpr-aging-sensor-id = <3>;
	qcom,cpr-aging-ref-corner = <6>;
	qcom,cpr-aging-min-gfx-corner = <4>;
	qcom,cpr-aging-ref-voltage = <1050000>;
	qcom,cpr-max-aging-margin = <15000>;
	qcom,cpr-de-aging-allowed = <1>;
	qcom,cpr-aging-ro-scaling-factor = <3500>;
	qcom,cpr-ro-scaling-factor = <2500 2200 2500 2200 1600 1800 1200 1400>;
	qcom,cpr-aging-derate = <1000 1000 1000 1000 1000 1000 1250 1250>;
	qcom,cpr-fuse-aging-init-quot-diff = <1000 0 8 0>;
};
