From dfc04900c40eb14f9364d56e96db2cc3340a1f21 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Wed, 3 Jan 2024 14:43:43 +0000 Subject: [PATCH 1/5] ASoC: dwc: Defer bclk_ratio handling to hw_params bclk_ratio is only a factor in clock producer mode, and needs to override the default value of num_channels * sample_size. Move the bclk_ratio handling into the hw_params method, only latching the value in set_bclk_ratio, to address both of those matters. See: https://github.com/raspberrypi/linux/issues/5817 Signed-off-by: Phil Elwell --- sound/soc/dwc/dwc-i2s.c | 38 +++++++++++++++++++++----------------- sound/soc/dwc/local.h | 1 + 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/sound/soc/dwc/dwc-i2s.c b/sound/soc/dwc/dwc-i2s.c index 4638978bbcea1d..5c7b5d5235ba5f 100644 --- a/sound/soc/dwc/dwc-i2s.c +++ b/sound/soc/dwc/dwc-i2s.c @@ -263,6 +263,25 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } + if ((dev->capability & DW_I2S_MASTER) && dev->bclk_ratio) { + switch (dev->bclk_ratio) { + case 32: + dev->ccr = 0x00; + break; + + case 48: + dev->ccr = 0x08; + break; + + case 64: + dev->ccr = 0x10; + break; + + default: + return -EINVAL; + } + } + config->chan_nr = params_channels(params); switch (config->chan_nr) { @@ -436,23 +455,7 @@ static int dw_i2s_set_bclk_ratio(struct snd_soc_dai *cpu_dai, dev_dbg(dev->dev, "%s(%d)\n", __func__, ratio); - switch (ratio) { - case 32: - dev->ccr = 0x00; - break; - - case 48: - dev->ccr = 0x08; - break; - - case 64: - dev->ccr = 0x10; - break; - default: - return -EINVAL; - } - - i2s_write_reg(dev->i2s_base, CCR, dev->ccr); + dev->bclk_ratio = ratio; return 0; } @@ -746,6 +749,7 @@ static int dw_i2s_probe(struct platform_device *pdev) } } + dev->bclk_ratio = 0; dev->i2s_reg_comp1 = I2S_COMP_PARAM_1; dev->i2s_reg_comp2 = I2S_COMP_PARAM_2; if (pdata) { diff --git a/sound/soc/dwc/local.h b/sound/soc/dwc/local.h index d0efb1f78d78e5..948720d2cedf04 100644 --- a/sound/soc/dwc/local.h +++ b/sound/soc/dwc/local.h @@ -107,6 +107,7 @@ struct dw_i2s_dev { unsigned int quirks; unsigned int i2s_reg_comp1; unsigned int i2s_reg_comp2; + unsigned int bclk_ratio; struct device *dev; u32 ccr; u32 xfer_resolution; From d5066442e39dd9bf4ba6431ffb3f99e3d5085d3f Mon Sep 17 00:00:00 2001 From: Dave Stevenson Date: Thu, 4 Jan 2024 12:02:43 +0000 Subject: [PATCH 2/5] drm/vc4: Fix reading of frame count on GEN5 / Pi4 The frame count values moved within registers DISPSTAT1 and DISPSTAT2 with GEN5, so update the accessor function to accommodate that. Fixes: b51cd7ad143d ("drm/vc4: hvs: Fix frame count register readout") Signed-off-by: Dave Stevenson --- drivers/gpu/drm/vc4/vc4_hvs.c | 23 +++++++++++++++++++++-- drivers/gpu/drm/vc4/vc4_regs.h | 6 ++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c index 2b2cf736e2bdee..3775178ff2e3c0 100644 --- a/drivers/gpu/drm/vc4/vc4_hvs.c +++ b/drivers/gpu/drm/vc4/vc4_hvs.c @@ -823,10 +823,28 @@ u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo) if (!drm_dev_enter(drm, &idx)) return 0; - if (vc4->gen >= VC4_GEN_6) { + switch (vc4->gen) { + case VC4_GEN_6: field = VC4_GET_FIELD(HVS_READ(SCALER6_DISPX_STATUS(fifo)), SCALER6_DISPX_STATUS_FRCNT); - } else { + break; + case VC4_GEN_5: + switch (fifo) { + case 0: + field = VC4_GET_FIELD(HVS_READ(SCALER_DISPSTAT1), + SCALER5_DISPSTAT1_FRCNT0); + break; + case 1: + field = VC4_GET_FIELD(HVS_READ(SCALER_DISPSTAT1), + SCALER5_DISPSTAT1_FRCNT1); + break; + case 2: + field = VC4_GET_FIELD(HVS_READ(SCALER_DISPSTAT2), + SCALER5_DISPSTAT2_FRCNT2); + break; + } + break; + case VC4_GEN_4: switch (fifo) { case 0: field = VC4_GET_FIELD(HVS_READ(SCALER_DISPSTAT1), @@ -841,6 +859,7 @@ u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo) SCALER_DISPSTAT2_FRCNT2); break; } + break; } drm_dev_exit(idx); diff --git a/drivers/gpu/drm/vc4/vc4_regs.h b/drivers/gpu/drm/vc4/vc4_regs.h index fc8c54d99ec3f3..0759ced1646fe0 100644 --- a/drivers/gpu/drm/vc4/vc4_regs.h +++ b/drivers/gpu/drm/vc4/vc4_regs.h @@ -424,6 +424,10 @@ # define SCALER_DISPSTAT1_FRCNT0_SHIFT 18 # define SCALER_DISPSTAT1_FRCNT1_MASK VC4_MASK(17, 12) # define SCALER_DISPSTAT1_FRCNT1_SHIFT 12 +# define SCALER5_DISPSTAT1_FRCNT0_MASK VC4_MASK(25, 20) +# define SCALER5_DISPSTAT1_FRCNT0_SHIFT 20 +# define SCALER5_DISPSTAT1_FRCNT1_MASK VC4_MASK(19, 14) +# define SCALER5_DISPSTAT1_FRCNT1_SHIFT 14 #define SCALER_DISPSTATX(x) (SCALER_DISPSTAT0 + \ (x) * (SCALER_DISPSTAT1 - \ @@ -442,6 +446,8 @@ #define SCALER_DISPSTAT2 0x00000068 # define SCALER_DISPSTAT2_FRCNT2_MASK VC4_MASK(17, 12) # define SCALER_DISPSTAT2_FRCNT2_SHIFT 12 +# define SCALER5_DISPSTAT2_FRCNT2_MASK VC4_MASK(19, 14) +# define SCALER5_DISPSTAT2_FRCNT2_SHIFT 14 #define SCALER_DISPBASE2 0x0000006c #define SCALER_DISPALPHA2 0x00000070 From eeb5969ae34df16024f39a77496a44ae94bfab13 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Thu, 4 Jan 2024 13:56:39 +0000 Subject: [PATCH 3/5] ARM: dts: bcm2712-rpi-5-b: Add eth_ledx parameters Include the dtparams controlling the Ethernet jack LEDs, as used on other Pis. See: https://github.com/raspberrypi/linux/issues/5825 Signed-off-by: Phil Elwell --- arch/arm/boot/dts/bcm2712-rpi-5-b.dts | 2 ++ arch/arm/boot/dts/overlays/README | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm/boot/dts/bcm2712-rpi-5-b.dts b/arch/arm/boot/dts/bcm2712-rpi-5-b.dts index ea10e7eb3c9262..edfe1fc421e312 100644 --- a/arch/arm/boot/dts/bcm2712-rpi-5-b.dts +++ b/arch/arm/boot/dts/bcm2712-rpi-5-b.dts @@ -830,6 +830,8 @@ spi10_cs_pins: &spi10_cs_gpio1 {}; act_led_trigger = <&act_led>, "linux,default-trigger"; pwr_led_activelow = <&pwr_led>, "gpios:8"; pwr_led_trigger = <&pwr_led>, "linux,default-trigger"; + eth_led0 = <&phy1>,"led-modes:0"; + eth_led1 = <&phy1>,"led-modes:4"; drm_fb0_rp1_dsi0 = <&aliases>, "drm-fb0=",&dsi0; drm_fb0_rp1_dsi1 = <&aliases>, "drm-fb0=",&dsi1; drm_fb0_rp1_dpi = <&aliases>, "drm-fb0=",&dpi; diff --git a/arch/arm/boot/dts/overlays/README b/arch/arm/boot/dts/overlays/README index 9e8e2b8f7b19a0..b1913c67a87ffa 100644 --- a/arch/arm/boot/dts/overlays/README +++ b/arch/arm/boot/dts/overlays/README @@ -207,7 +207,7 @@ Params: 0 means never downshift (default 2). Pi3B+ only. eth_led0 Set mode of LED0 - amber on Pi3B+ (default "1"), - green on Pi4 (default "0"). + green on Pi4/5 (default "0"). The legal values are: Pi3B+ @@ -217,7 +217,7 @@ Params: 4=link100/1000/activity 5=link10/1000/activity 6=link10/100/activity 14=off 15=on - Pi4 + Pi4/5 0=Speed/Activity 1=Speed 2=Flash activity 3=FDX @@ -226,7 +226,7 @@ Params: 8=Link 9=Activity eth_led1 Set mode of LED1 - green on Pi3B+ (default "6"), - amber on Pi4 (default "8"). See eth_led0 for + amber on Pi4/5 (default "8"). See eth_led0 for legal values. eth_max_speed Set the maximum speed a link is allowed From 2c085a1ff40521ab89d8f1894757aa83b59b4607 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Thu, 4 Jan 2024 12:09:10 +0000 Subject: [PATCH 4/5] ARM: dts: bcm2712-rpi-5-b: Add fan speed dtparams Add dtparams for adjusting the Pi 5 cooling fan speeds and temperature thresholds. See: https://github.com/raspberrypi/linux/issues/5820 Signed-off-by: Phil Elwell --- arch/arm/boot/dts/bcm2712-rpi-5-b.dts | 13 +++++++++++++ arch/arm/boot/dts/overlays/README | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/arch/arm/boot/dts/bcm2712-rpi-5-b.dts b/arch/arm/boot/dts/bcm2712-rpi-5-b.dts index edfe1fc421e312..d960bc456b2f7c 100644 --- a/arch/arm/boot/dts/bcm2712-rpi-5-b.dts +++ b/arch/arm/boot/dts/bcm2712-rpi-5-b.dts @@ -844,5 +844,18 @@ spi10_cs_pins: &spi10_cs_gpio1 {}; drm_fb2_rp1_dsi1 = <&aliases>, "drm-fb2=",&dsi1; drm_fb2_rp1_dpi = <&aliases>, "drm-fb2=",&dpi; drm_fb2_vc4 = <&aliases>, "drm-fb2=",&vc4; + + fan_temp0 = <&cpu_tepid>,"temperature:0"; + fan_temp1 = <&cpu_warm>,"temperature:0"; + fan_temp2 = <&cpu_hot>,"temperature:0"; + fan_temp3 = <&cpu_vhot>,"temperature:0"; + fan_temp0_hyst = <&cpu_tepid>,"hysteresis:0"; + fan_temp1_hyst = <&cpu_warm>,"hysteresis:0"; + fan_temp2_hyst = <&cpu_hot>,"hysteresis:0"; + fan_temp3_hyst = <&cpu_vhot>,"hysteresis:0"; + fan_temp0_speed = <&fan>, "cooling-levels:4"; + fan_temp1_speed = <&fan>, "cooling-levels:8"; + fan_temp2_speed = <&fan>, "cooling-levels:12"; + fan_temp3_speed = <&fan>, "cooling-levels:16"; }; }; diff --git a/arch/arm/boot/dts/overlays/README b/arch/arm/boot/dts/overlays/README index b1913c67a87ffa..94147d17fc36e2 100644 --- a/arch/arm/boot/dts/overlays/README +++ b/arch/arm/boot/dts/overlays/README @@ -233,6 +233,31 @@ Params: to negotiate. Legal values are 10, 100 and 1000 (default 1000). Pi3B+ only. + fan_temp0 Temperature threshold (in millicelcius) for + 1st cooling level (default 50000). Pi5 only. + fan_temp0_hyst Temperature hysteresis (in millicelcius) for + 1st cooling level (default 5000). Pi5 only. + fan_temp0_speed Fan PWM setting for 1st cooling level (0-255, + default 75). Pi5 only. + fan_temp1 Temperature threshold (in millicelcius) for + 2nd cooling level (default 60000). Pi5 only. + fan_temp1_hyst Temperature hysteresis (in millicelcius) for + 2nd cooling level (default 5000). Pi5 only. + fan_temp1_speed Fan PWM setting for 2nd cooling level (0-255, + default 125). Pi5 only. + fan_temp2 Temperature threshold (in millicelcius) for + 3rd cooling level (default 67500). Pi5 only. + fan_temp2_hyst Temperature hysteresis (in millicelcius) for + 3rd cooling level (default 5000). Pi5 only. + fan_temp2_speed Fan PWM setting for 3rd cooling level (0-255, + default 175). Pi5 only. + fan_temp3 Temperature threshold (in millicelcius) for + 4th cooling level (default 75000). Pi5 only. + fan_temp3_hyst Temperature hysteresis (in millicelcius) for + 4th cooling level (default 5000). Pi5 only. + fan_temp3_speed Fan PWM setting for 4th cooling level (0-255, + default 250). Pi5 only. + hdmi Set to "off" to disable the HDMI interface (default "on") From 146bbf9627f6c37816939de29538ec8ee9a7be1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ADra=20Canal?= Date: Fri, 5 Jan 2024 15:07:34 -0300 Subject: [PATCH 5/5] drm/vc4: don't check if plane->state->fb == state->fb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, when using non-blocking commits, we can see the following kernel warning: [ 110.908514] ------------[ cut here ]------------ [ 110.908529] refcount_t: underflow; use-after-free. [ 110.908620] WARNING: CPU: 0 PID: 1866 at lib/refcount.c:87 refcount_dec_not_one+0xb8/0xc0 [ 110.908664] Modules linked in: rfcomm snd_seq_dummy snd_hrtimer snd_seq snd_seq_device cmac algif_hash aes_arm64 aes_generic algif_skcipher af_alg bnep hid_logitech_hidpp vc4 brcmfmac hci_uart btbcm brcmutil bluetooth snd_soc_hdmi_codec cfg80211 cec drm_display_helper drm_dma_helper drm_kms_helper snd_soc_core snd_compress snd_pcm_dmaengine fb_sys_fops sysimgblt syscopyarea sysfillrect raspberrypi_hwmon ecdh_generic ecc rfkill libaes i2c_bcm2835 binfmt_misc joydev snd_bcm2835(C) bcm2835_codec(C) bcm2835_isp(C) v4l2_mem2mem videobuf2_dma_contig snd_pcm bcm2835_v4l2(C) raspberrypi_gpiomem bcm2835_mmal_vchiq(C) videobuf2_v4l2 snd_timer videobuf2_vmalloc videobuf2_memops videobuf2_common snd videodev vc_sm_cma(C) mc hid_logitech_dj uio_pdrv_genirq uio i2c_dev drm fuse dm_mod drm_panel_orientation_quirks backlight ip_tables x_tables ipv6 [ 110.909086] CPU: 0 PID: 1866 Comm: kodi.bin Tainted: G C 6.1.66-v8+ #32 [ 110.909104] Hardware name: Raspberry Pi 3 Model B Rev 1.2 (DT) [ 110.909114] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 110.909132] pc : refcount_dec_not_one+0xb8/0xc0 [ 110.909152] lr : refcount_dec_not_one+0xb4/0xc0 [ 110.909170] sp : ffffffc00913b9c0 [ 110.909177] x29: ffffffc00913b9c0 x28: 000000556969bbb0 x27: 000000556990df60 [ 110.909205] x26: 0000000000000002 x25: 0000000000000004 x24: ffffff8004448480 [ 110.909230] x23: ffffff800570b500 x22: ffffff802e03a7bc x21: ffffffecfca68c78 [ 110.909257] x20: ffffff8002b42000 x19: ffffff802e03a600 x18: 0000000000000000 [ 110.909283] x17: 0000000000000011 x16: ffffffffffffffff x15: 0000000000000004 [ 110.909308] x14: 0000000000000fff x13: ffffffed577e47e0 x12: 0000000000000003 [ 110.909333] x11: 0000000000000000 x10: 0000000000000027 x9 : c912d0d083728c00 [ 110.909359] x8 : c912d0d083728c00 x7 : 65646e75203a745f x6 : 746e756f63666572 [ 110.909384] x5 : ffffffed579f62ee x4 : ffffffed579eb01e x3 : 0000000000000000 [ 110.909409] x2 : 0000000000000000 x1 : ffffffc00913b750 x0 : 0000000000000001 [ 110.909434] Call trace: [ 110.909441] refcount_dec_not_one+0xb8/0xc0 [ 110.909461] vc4_bo_dec_usecnt+0x4c/0x1b0 [vc4] [ 110.909903] vc4_cleanup_fb+0x44/0x50 [vc4] [ 110.910315] drm_atomic_helper_cleanup_planes+0x88/0xa4 [drm_kms_helper] [ 110.910669] vc4_atomic_commit_tail+0x390/0x9dc [vc4] [ 110.911079] commit_tail+0xb0/0x164 [drm_kms_helper] [ 110.911397] drm_atomic_helper_commit+0x1d0/0x1f0 [drm_kms_helper] [ 110.911716] drm_atomic_commit+0xb0/0xdc [drm] [ 110.912569] drm_mode_atomic_ioctl+0x348/0x4b8 [drm] [ 110.913330] drm_ioctl_kernel+0xec/0x15c [drm] [ 110.914091] drm_ioctl+0x24c/0x3b0 [drm] [ 110.914850] __arm64_sys_ioctl+0x9c/0xd4 [ 110.914873] invoke_syscall+0x4c/0x114 [ 110.914897] el0_svc_common+0xd0/0x118 [ 110.914917] do_el0_svc+0x38/0xd0 [ 110.914936] el0_svc+0x30/0x8c [ 110.914958] el0t_64_sync_handler+0x84/0xf0 [ 110.914979] el0t_64_sync+0x18c/0x190 [ 110.914996] ---[ end trace 0000000000000000 ]--- This happens because, although `prepare_fb` and `cleanup_fb` are perfectly balanced, we cannot guarantee consistency in the check plane->state->fb == state->fb. This means that sometimes we can increase the refcount in `prepare_fb` and don't decrease it in `cleanup_fb`. The opposite can also be true. In fact, the struct drm_plane .state shouldn't be accessed directly but instead, the `drm_atomic_get_new_plane_state()` helper function should be used. So, we could stick to this check, but using `drm_atomic_get_new_plane_state()`. But actually, this check is not really needed. We can increase and decrease the refcount symmetrically without problems. This is going to make the code more simple and consistent. Signed-off-by: MaĆ­ra Canal --- drivers/gpu/drm/vc4/vc4_plane.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c index 7689b835eb2b17..f20e573615e44d 100644 --- a/drivers/gpu/drm/vc4/vc4_plane.c +++ b/drivers/gpu/drm/vc4/vc4_plane.c @@ -2225,9 +2225,6 @@ static int vc4_prepare_fb(struct drm_plane *plane, drm_gem_plane_helper_prepare_fb(plane, state); - if (plane->state->fb == state->fb) - return 0; - return vc4_bo_inc_usecnt(bo); } @@ -2236,7 +2233,7 @@ static void vc4_cleanup_fb(struct drm_plane *plane, { struct vc4_bo *bo; - if (plane->state->fb == state->fb || !state->fb) + if (!state->fb) return; bo = to_vc4_bo(&drm_fb_dma_get_gem_obj(state->fb, 0)->base);