Skip to content

Commit 78b36b1

Browse files
committed
drm/i915: deprecate _SHIFT in favor of _MASK passed to accessors
bitfield.h defines FIELD_GET() and FIELD_PREP() macros to access bitfields using the mask alone, with no need for separate shift. Indeed, the shift is redundant. We define REG_FIELD_GET() and REG_FIELD_PREP() wrappers for the above, in part to force u32 and for consistency with REG_BIT() and REG_GENMASK(), but also as we'll need to redefine REG_FIELD_PREP() in follow-up work to make it produce integer constant expressions. For the most part, REG_FIELD_GET() is shorter than masking followed by shift, and arguably has more clarity. REG_FIELD_PREP() can get more verbose than simply shifting in place, but it does provide masking to ensure we don't overflow the mask, something we usually don't bother with currently. Convert power sequencer registers as an example. v3: - temp variable removal (Chris) - rebase v2: - Add the REG_FIELD_GET() and REG_FIELD_PREP() wrappers to use them consistently from the start. Cc: Chris Wilson <[email protected]> Cc: Joonas Lahtinen <[email protected]> Cc: Michal Wajdeczko <[email protected]> Cc: Mika Kuoppala <[email protected]> Reviewed-by: Chris Wilson <[email protected]> Acked-by: Rodrigo Vivi <[email protected]> Signed-off-by: Jani Nikula <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/ab68f52e55e3961bde9458c0d85a12d98ef471df.1552657998.git.jani.nikula@intel.com
1 parent 09b434d commit 78b36b1

File tree

3 files changed

+63
-66
lines changed

3 files changed

+63
-66
lines changed

drivers/gpu/drm/i915/i915_reg.h

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef _I915_REG_H_
2626
#define _I915_REG_H_
2727

28+
#include <linux/bitfield.h>
2829
#include <linux/bits.h>
2930

3031
/**
@@ -61,11 +62,11 @@
6162
* significant to least significant bit. Indent the register content macros
6263
* using two extra spaces between ``#define`` and the macro name.
6364
*
64-
* For bit fields, define a ``_MASK`` and a ``_SHIFT`` macro. Use
65-
* ``REG_GENMASK()`` to define _MASK. Define bit field contents so that they are
66-
* already shifted in place, and can be directly OR'd. For convenience,
67-
* function-like macros may be used to define bit fields, but do note that the
68-
* macros may be needed to read as well as write the register contents.
65+
* Define bit fields using ``REG_GENMASK(h, l)``. Define bit field contents so
66+
* that they are already shifted in place, and can be directly OR'd. For
67+
* convenience, function-like macros may be used to define bit fields, but do
68+
* note that the macros may be needed to read as well as write the register
69+
* contents.
6970
*
7071
* Define bits using ``REG_BIT(N)``. Do **not** add ``_BIT`` suffix to the name.
7172
*
@@ -107,7 +108,6 @@
107108
* #define FOO(pipe) _MMIO_PIPE(pipe, _FOO_A, _FOO_B)
108109
* #define FOO_ENABLE REG_BIT(31)
109110
* #define FOO_MODE_MASK REG_GENMASK(19, 16)
110-
* #define FOO_MODE_SHIFT 16
111111
* #define FOO_MODE_BAR (0 << 16)
112112
* #define FOO_MODE_BAZ (1 << 16)
113113
* #define FOO_MODE_QUX_SNB (2 << 16)
@@ -144,6 +144,30 @@
144144
__builtin_constant_p(__low) && \
145145
((__low) < 0 || (__high) > 31 || (__low) > (__high)))))
146146

147+
/**
148+
* REG_FIELD_PREP() - Prepare a u32 bitfield value
149+
* @__mask: shifted mask defining the field's length and position
150+
* @__val: value to put in the field
151+
152+
* Local wrapper for FIELD_PREP() to force u32 and for consistency with
153+
* REG_FIELD_GET(), REG_BIT() and REG_GENMASK().
154+
*
155+
* @return: @__val masked and shifted into the field defined by @__mask.
156+
*/
157+
#define REG_FIELD_PREP(__mask, __val) ((u32)FIELD_PREP(__mask, __val))
158+
159+
/**
160+
* REG_FIELD_GET() - Extract a u32 bitfield value
161+
* @__mask: shifted mask defining the field's length and position
162+
* @__val: value to extract the bitfield value from
163+
*
164+
* Local wrapper for FIELD_GET() to force u32 and for consistency with
165+
* REG_FIELD_PREP(), REG_BIT() and REG_GENMASK().
166+
*
167+
* @return: Masked and shifted value of the field defined by @__mask in @__val.
168+
*/
169+
#define REG_FIELD_GET(__mask, __val) ((u32)FIELD_GET(__mask, __val))
170+
147171
typedef struct {
148172
u32 reg;
149173
} i915_reg_t;
@@ -4727,7 +4751,6 @@ enum {
47274751
#define ICP_PP_CONTROL(x) _MMIO(((x) == 1) ? _PP_CONTROL_1 : \
47284752
_PP_CONTROL_2)
47294753
#define POWER_CYCLE_DELAY_MASK REG_GENMASK(8, 4)
4730-
#define POWER_CYCLE_DELAY_SHIFT 4
47314754
#define VDD_OVERRIDE_FORCE REG_BIT(3)
47324755
#define BACKLIGHT_ENABLE REG_BIT(2)
47334756
#define PWR_DOWN_ON_RESET REG_BIT(1)
@@ -4744,7 +4767,6 @@ enum {
47444767
#define PP_SEQUENCE_NONE (0 << 28)
47454768
#define PP_SEQUENCE_POWER_UP (1 << 28)
47464769
#define PP_SEQUENCE_POWER_DOWN (2 << 28)
4747-
#define PP_SEQUENCE_SHIFT 28
47484770
#define PP_CYCLE_DELAY_ACTIVE REG_BIT(27)
47494771
#define PP_SEQUENCE_STATE_MASK REG_GENMASK(3, 0)
47504772
#define PP_SEQUENCE_STATE_OFF_IDLE (0x0 << 0)
@@ -4770,31 +4792,24 @@ enum {
47704792

47714793
#define _PP_ON_DELAYS 0x61208
47724794
#define PP_ON_DELAYS(pps_idx) _MMIO_PPS(pps_idx, _PP_ON_DELAYS)
4773-
#define PANEL_PORT_SELECT_SHIFT 30
47744795
#define PANEL_PORT_SELECT_MASK REG_GENMASK(31, 30)
47754796
#define PANEL_PORT_SELECT_LVDS (0 << 30)
47764797
#define PANEL_PORT_SELECT_DPA (1 << 30)
47774798
#define PANEL_PORT_SELECT_DPC (2 << 30)
47784799
#define PANEL_PORT_SELECT_DPD (3 << 30)
47794800
#define PANEL_PORT_SELECT_VLV(port) ((port) << 30)
47804801
#define PANEL_POWER_UP_DELAY_MASK REG_GENMASK(28, 16)
4781-
#define PANEL_POWER_UP_DELAY_SHIFT 16
47824802
#define PANEL_LIGHT_ON_DELAY_MASK REG_GENMASK(12, 0)
4783-
#define PANEL_LIGHT_ON_DELAY_SHIFT 0
47844803

47854804
#define _PP_OFF_DELAYS 0x6120C
47864805
#define PP_OFF_DELAYS(pps_idx) _MMIO_PPS(pps_idx, _PP_OFF_DELAYS)
47874806
#define PANEL_POWER_DOWN_DELAY_MASK REG_GENMASK(28, 16)
4788-
#define PANEL_POWER_DOWN_DELAY_SHIFT 16
47894807
#define PANEL_LIGHT_OFF_DELAY_MASK REG_GENMASK(12, 0)
4790-
#define PANEL_LIGHT_OFF_DELAY_SHIFT 0
47914808

47924809
#define _PP_DIVISOR 0x61210
47934810
#define PP_DIVISOR(pps_idx) _MMIO_PPS(pps_idx, _PP_DIVISOR)
47944811
#define PP_REFERENCE_DIVIDER_MASK REG_GENMASK(31, 8)
4795-
#define PP_REFERENCE_DIVIDER_SHIFT 8
47964812
#define PANEL_POWER_CYCLE_DELAY_MASK REG_GENMASK(4, 0)
4797-
#define PANEL_POWER_CYCLE_DELAY_SHIFT 0
47984813

47994814
/* Panel fitting */
48004815
#define PFIT_CONTROL _MMIO(DISPLAY_MMIO_BASE(dev_priv) + 0x61230)

drivers/gpu/drm/i915/intel_dp.c

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6438,29 +6438,19 @@ intel_pps_readout_hw_state(struct intel_dp *intel_dp, struct edp_power_seq *seq)
64386438
pp_off = I915_READ(regs.pp_off);
64396439

64406440
/* Pull timing values out of registers */
6441-
seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
6442-
PANEL_POWER_UP_DELAY_SHIFT;
6443-
6444-
seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
6445-
PANEL_LIGHT_ON_DELAY_SHIFT;
6446-
6447-
seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
6448-
PANEL_LIGHT_OFF_DELAY_SHIFT;
6449-
6450-
seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
6451-
PANEL_POWER_DOWN_DELAY_SHIFT;
6441+
seq->t1_t3 = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, pp_on);
6442+
seq->t8 = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, pp_on);
6443+
seq->t9 = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, pp_off);
6444+
seq->t10 = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, pp_off);
64526445

64536446
if (i915_mmio_reg_valid(regs.pp_div)) {
64546447
u32 pp_div;
64556448

64566449
pp_div = I915_READ(regs.pp_div);
64576450

6458-
seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
6459-
PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
6460-
6451+
seq->t11_t12 = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, pp_div) * 1000;
64616452
} else {
6462-
seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
6463-
BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
6453+
seq->t11_t12 = REG_FIELD_GET(BXT_POWER_CYCLE_DELAY_MASK, pp_ctl) * 1000;
64646454
}
64656455
}
64666456

@@ -6620,10 +6610,10 @@ intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
66206610
I915_WRITE(regs.pp_ctrl, pp);
66216611
}
66226612

6623-
pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
6624-
(seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
6625-
pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
6626-
(seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
6613+
pp_on = REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, seq->t1_t3) |
6614+
REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, seq->t8);
6615+
pp_off = REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, seq->t9) |
6616+
REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, seq->t10);
66276617

66286618
/* Haswell doesn't have any port selection bits for the panel
66296619
* power sequencer any more. */
@@ -6655,19 +6645,15 @@ intel_dp_init_panel_power_sequencer_registers(struct intel_dp *intel_dp,
66556645
* Compute the divisor for the pp clock, simply match the Bspec formula.
66566646
*/
66576647
if (i915_mmio_reg_valid(regs.pp_div)) {
6658-
u32 pp_div;
6659-
6660-
pp_div = ((100 * div) / 2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
6661-
pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000) <<
6662-
PANEL_POWER_CYCLE_DELAY_SHIFT);
6663-
I915_WRITE(regs.pp_div, pp_div);
6648+
I915_WRITE(regs.pp_div,
6649+
REG_FIELD_PREP(PP_REFERENCE_DIVIDER_MASK, (100 * div) / 2 - 1) |
6650+
REG_FIELD_PREP(PANEL_POWER_CYCLE_DELAY_MASK, DIV_ROUND_UP(seq->t11_t12, 1000)));
66646651
} else {
66656652
u32 pp_ctl;
66666653

66676654
pp_ctl = I915_READ(regs.pp_ctrl);
66686655
pp_ctl &= ~BXT_POWER_CYCLE_DELAY_MASK;
6669-
pp_ctl |= (DIV_ROUND_UP(seq->t11_t12, 1000) <<
6670-
BXT_POWER_CYCLE_DELAY_SHIFT);
6656+
pp_ctl |= REG_FIELD_PREP(BXT_POWER_CYCLE_DELAY_MASK, DIV_ROUND_UP(seq->t11_t12, 1000));
66716657
I915_WRITE(regs.pp_ctrl, pp_ctl);
66726658
}
66736659

drivers/gpu/drm/i915/intel_lvds.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,17 @@ static void intel_lvds_pps_get_hw_state(struct drm_i915_private *dev_priv,
152152
pps->powerdown_on_reset = I915_READ(PP_CONTROL(0)) & PANEL_POWER_RESET;
153153

154154
val = I915_READ(PP_ON_DELAYS(0));
155-
pps->port = (val & PANEL_PORT_SELECT_MASK) >>
156-
PANEL_PORT_SELECT_SHIFT;
157-
pps->t1_t2 = (val & PANEL_POWER_UP_DELAY_MASK) >>
158-
PANEL_POWER_UP_DELAY_SHIFT;
159-
pps->t5 = (val & PANEL_LIGHT_ON_DELAY_MASK) >>
160-
PANEL_LIGHT_ON_DELAY_SHIFT;
155+
pps->port = REG_FIELD_GET(PANEL_PORT_SELECT_MASK, val);
156+
pps->t1_t2 = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, val);
157+
pps->t5 = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, val);
161158

162159
val = I915_READ(PP_OFF_DELAYS(0));
163-
pps->t3 = (val & PANEL_POWER_DOWN_DELAY_MASK) >>
164-
PANEL_POWER_DOWN_DELAY_SHIFT;
165-
pps->tx = (val & PANEL_LIGHT_OFF_DELAY_MASK) >>
166-
PANEL_LIGHT_OFF_DELAY_SHIFT;
160+
pps->t3 = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, val);
161+
pps->tx = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, val);
167162

168163
val = I915_READ(PP_DIVISOR(0));
169-
pps->divider = (val & PP_REFERENCE_DIVIDER_MASK) >>
170-
PP_REFERENCE_DIVIDER_SHIFT;
171-
val = (val & PANEL_POWER_CYCLE_DELAY_MASK) >>
172-
PANEL_POWER_CYCLE_DELAY_SHIFT;
164+
pps->divider = REG_FIELD_GET(PP_REFERENCE_DIVIDER_MASK, val);
165+
val = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, val);
173166
/*
174167
* Remove the BSpec specified +1 (100ms) offset that accounts for a
175168
* too short power-cycle delay due to the asynchronous programming of
@@ -209,16 +202,19 @@ static void intel_lvds_pps_init_hw(struct drm_i915_private *dev_priv,
209202
val |= PANEL_POWER_RESET;
210203
I915_WRITE(PP_CONTROL(0), val);
211204

212-
I915_WRITE(PP_ON_DELAYS(0), (pps->port << PANEL_PORT_SELECT_SHIFT) |
213-
(pps->t1_t2 << PANEL_POWER_UP_DELAY_SHIFT) |
214-
(pps->t5 << PANEL_LIGHT_ON_DELAY_SHIFT));
215-
I915_WRITE(PP_OFF_DELAYS(0), (pps->t3 << PANEL_POWER_DOWN_DELAY_SHIFT) |
216-
(pps->tx << PANEL_LIGHT_OFF_DELAY_SHIFT));
205+
I915_WRITE(PP_ON_DELAYS(0),
206+
REG_FIELD_PREP(PANEL_PORT_SELECT_MASK, pps->port) |
207+
REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, pps->t1_t2) |
208+
REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, pps->t5));
217209

218-
val = pps->divider << PP_REFERENCE_DIVIDER_SHIFT;
219-
val |= (DIV_ROUND_UP(pps->t4, 1000) + 1) <<
220-
PANEL_POWER_CYCLE_DELAY_SHIFT;
221-
I915_WRITE(PP_DIVISOR(0), val);
210+
I915_WRITE(PP_OFF_DELAYS(0),
211+
REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, pps->t3) |
212+
REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, pps->tx));
213+
214+
I915_WRITE(PP_DIVISOR(0),
215+
REG_FIELD_PREP(PP_REFERENCE_DIVIDER_MASK, pps->divider) |
216+
REG_FIELD_PREP(PANEL_POWER_CYCLE_DELAY_MASK,
217+
DIV_ROUND_UP(pps->t4, 1000) + 1));
222218
}
223219

224220
static void intel_pre_enable_lvds(struct intel_encoder *encoder,

0 commit comments

Comments
 (0)