Commit Graph

1281092 Commits

Author SHA1 Message Date
XiaoDong Huang
b4606fb76f arm64: dts: rockchip: rv1126b: add rockchip_suspend node
Signed-off-by: XiaoDong Huang <derrick.huang@rock-chips.com>
Change-Id: Ie48cf27fec8a2543aa1dd24c96ba8aaed2de4012
2025-04-01 07:48:38 +00:00
XiaoDong Huang
12d2a304c6 dt-bindings: suspend: add rv1126b pm related macros
Signed-off-by: XiaoDong Huang <derrick.huang@rock-chips.com>
Change-Id: I9398c62976fe7c17ef74bcc7d44caea110106653
2025-04-01 07:48:38 +00:00
XiaoDong Huang
7d6827ff3b ARM: configs: rockchip: Add rv1126b-wakeup.config
Signed-off-by: XiaoDong Huang <derrick.huang@rock-chips.com>
Change-Id: I4e18ecc885b126def419d430d22edc9e2b583dae
2025-04-01 07:48:38 +00:00
XiaoDong Huang
b61ce5dfbb ARM: configs: rockchip: Add rv1126b-pm.config
Signed-off-by: XiaoDong Huang <derrick.huang@rock-chips.com>
Change-Id: Ia6ff37cb886fe8c1c50c167b6c91e2ac2d060810
2025-04-01 07:48:38 +00:00
Su Yuefu
ff9c0474ec arm64: dts: rockchip: rv1126b-evb-cam-csi0: fix csi_dphy_input5 reg
Signed-off-by: Su Yuefu <yuefu.su@rock-chips.com>
Change-Id: I47cecaa1d6d2e800a30ef5bc42ddc9af27ac8e35
2025-04-01 07:47:18 +00:00
Su Yuefu
e4496649f8 arm64: dts: rockchip: rv1126b-evb3-v10: fix npu regulator name error
Signed-off-by: Su Yuefu <yuefu.su@rock-chips.com>
Change-Id: I85fa6c13e0666f24d3200b34a3de7c0e59bea3be
2025-04-01 07:46:29 +00:00
Sandy Huang
548b641577 drm/rockchip: vop2: adjust bt1886 eotf for sdr2hdr for rk3568/rk3588
(1) sdr2hdr_tf use software config instead of hardware init;
(2) sdr2hdr_bt1886eotf dst range use 500 nit;
(3) sdr2hdr_bt1886eotf y0-y43 must multiply by 2 due to some special IC designs.

Signed-off-by: Sandy Huang <hjc@rock-chips.com>
Change-Id: I58afff82c49f6ebbedad350bccc383e9fad11c2f
2025-04-01 06:10:23 +00:00
Ye Zhang
84e5716948 clk: rockchip: clk-pvtpll: Add pm suspend/resume support
Signed-off-by: Ye Zhang <ye.zhang@rock-chips.com>
Change-Id: I436c08ef3ad6cf8d245a448cb62a90a613e5330a
2025-04-01 11:33:10 +08:00
Algea Cao
48498c68b5 drm/bridge: synopsys: dw-hdmi-qp: Call handle_plugged_change() when hdmi plug
Notify linux userspace hdmi has been plugged in or out and
audio needs to be reset.

Fixes: b84c5d0c81 ("drm/bridge: synopsys: dw-hdmi-qp: Only set extcon status when hdmi plug/unplug")

Change-Id: I7e7f3da2849ae4bb70d838281001a4ead2b7c03a
Signed-off-by: Algea Cao <algea.cao@rock-chips.com>
Signed-off-by: XiaoTan Luo <lxt@rock-chips.com>
2025-04-01 03:29:13 +00:00
Su Yuefu
da87a99cf2 arm64: dts: rockchip: rv1126b-evb3-v10: Add lcd/tp support
Signed-off-by: Su Yuefu <yuefu.su@rock-chips.com>
Change-Id: I60363f769840bceb603c5a8e53c0c4e10fba4849
2025-04-01 03:28:26 +00:00
Sach Lin
0286cc5b23 ARM: configs: rv1126b_defconfig: Enable avsp
+CONFIG_VIDEO_ROCKCHIP_AVSP=m

Signed-off-by: Sach Lin <sach.lin@rock-chips.com>
Change-Id: Id6280d2677c5257ba4ca49b26d165e86422dab89
2025-04-01 03:27:59 +00:00
Chaoyi Chen
15974f7d70 drm/rockchip: vop: Add version for interlace_read reg for RV1126B
Change-Id: Ie3bf300e8e5467a4ce4ceb52bee07bee44e5bdb7
Signed-off-by: Chaoyi Chen <chaoyi.chen@rock-chips.com>
2025-04-01 03:26:37 +00:00
Jianlong Wang
5d1fb00c35 arm64: dts: rockchip: rk3358m-automotive-ddr3-v11: Adjust some configs based on hardware
1\ fix rmii_pins for rxer is not used in rmii
2\ regulators for serdes should be always on
3\ add rk3358m-automotive-ddr3-v11-linux-tb

Change-Id: Ic12c214a51ad023738ee98b4d202742640de1ab9
Signed-off-by: Jianlong Wang <jianlong.wang@rock-chips.com>
2025-04-01 02:59:57 +00:00
Chaoyi Chen
2ace7d1fb1 drm/bridge: sii902x: Only set CLK_RATIO_2X for DRM_MODE_FLAG_DBLCLK
According to sii902x datasheet, the TClkSel (Bit[7:6] of reg 0x08,
that is SII902X_TPI_PIXEL_REPETITION) selects the factor by which
the input clock must be multiplied to give output clock frequency.

Some interlace mode may not set DRM_MODE_FLAG_DBLCLK flag like 1080i,
these mode should not enable CLK_RATIO_2X.

This patch make sure we only set CLK_RATIO_2X when the mode has
DRM_MODE_FLAG_DBLCLK flag.

Change-Id: I1cc98693c9c8348667fabddc13d8f5ac4e689e09
Signed-off-by: Chaoyi Chen <chaoyi.chen@rock-chips.com>
2025-04-01 02:56:56 +00:00
ZhengRong Ruan
cc082cd7b3 arm64: configs: rv1126b_defconfig: enable CONFIG_DMABUF_HEAPS_SYSTEM to support rockit mpp
Signed-off-by: ZhengRong Ruan <ryan.ruan@rock-chips.com>
Change-Id: I62ce6ea2809a6a9a92ffad1829df0b79e0c02adf
2025-04-01 02:51:28 +00:00
ZhengRong Ruan
c381f4a7e1 Revert "arm64: configs: enable mpp configs for rv1126b"
This reverts commit 3555e6e9ee.

support rockit mpp.

Change-Id: Icf36561fe8101001c3280956b3bef751bc971748
Signed-off-by: ZhengRong Ruan <ryan.ruan@rock-chips.com>
2025-04-01 02:51:28 +00:00
Sach Lin
3cac6fc38e arm64: dts: rockchip: rv1126b-evb1-v10: Enable avsp
Signed-off-by: Sach Lin <sach.lin@rock-chips.com>
Change-Id: I0071ff31c058c632f5d1b63fb2900b4b4424c6ab
2025-04-01 02:46:46 +00:00
Su Yuefu
a2a001d40b arm64: dts: rockchip: rv1126b-evb3-v10: Add saradc0 support
Signed-off-by: Su Yuefu <yuefu.su@rock-chips.com>
Change-Id: I0992674c69280e3e2fd9b11f2f29881da3250f86
2025-04-01 02:44:24 +00:00
Huibin Hong
6c866b2ffc soc: rockchip: debug: disable os lock for edpcsr
Change-Id: I59efc4705905880797ab14ce28726fb3542267f8
Signed-off-by: Huibin Hong <huibin.hong@rock-chips.com>
2025-04-01 02:33:57 +00:00
Huibin Hong
d61c690c97 ARM: configs: rv1126b-evb: enable ROCKCHIP_DEBUG
Change-Id: I51bc12cb09fab7a782fb1d802ba0197fa9ec0408
Signed-off-by: Huibin Hong <huibin.hong@rock-chips.com>
2025-04-01 02:33:38 +00:00
Su Yuefu
1e875f9110 arm64: dts: rockchip: rv1126b-evb3-v10: Add SDMMC0 for SDCard
Signed-off-by: Su Yuefu <yuefu.su@rock-chips.com>
Change-Id: I94ec91fcf7cb0a3b3d32bc6f48369e4569bb420a
2025-04-01 02:31:30 +00:00
Weiwen Chen
f50bd319c1 ARM: dts: rockchip: add rv1126b-evb1-v10-spi-nor board
Signed-off-by: Weiwen Chen <cww@rock-chips.com>
Change-Id: I62d8b4621286aa52acf8515d37eb470b04ba8965
2025-04-01 02:30:29 +00:00
Weiwen Chen
92839a32dd arm64: dts: rockchip: add rv1126b-evb1-v10-spi-nor board
Signed-off-by: Weiwen Chen <cww@rock-chips.com>
Change-Id: Ifcaab6437037db442cf58769843d33489c8ef74e
2025-04-01 02:30:09 +00:00
Sandy Huang
82294562bc drm/rockchip: drv: move clk unprotect to the end of drm_bind
rockchip_drm_bind() may be delayed for others driver delay probe,
this maybe cause rockchip_drm_show_logo() be called after
rockchip_clocks_loader_unprotect() and lead to display error,
so move clk unprotect to the end of drm_bind.

Signed-off-by: Sandy Huang <hjc@rock-chips.com>
Change-Id: I6eeae1c1307f91777fec23c66c5d5413443335d0
2025-04-01 02:29:06 +00:00
Zitong Cai
8ad85fa81d arm64: configs: rk3588_vehicle: Disable CONFIG_MFD_MAX96745 and CONFIG_MFD_MAX96755F
Change-Id: I3502e51aa408af9f92ecc36ad7288323eac35cf5
Signed-off-by: Zitong Cai <zitong.cai@rock-chips.com>
2025-04-01 02:19:16 +00:00
Chaoyi Chen
cd08e1a5ca drm/rockchip: vop: Add interlace mode support for RV1126B
Change-Id: Ieffc2d9a2862b854895a77befe8d201fea9ad984
Signed-off-by: Chaoyi Chen <chaoyi.chen@rock-chips.com>
2025-04-01 01:42:53 +00:00
Chaoyi Chen
d8a3282125 drm/rockchip: vop: Add bt656 support for RV1126B
Change-Id: I6e67a045fa6326c7924a6848948cf7ec9e9872f3
Signed-off-by: Chaoyi Chen <chaoyi.chen@rock-chips.com>
2025-04-01 01:42:53 +00:00
Chaoyi Chen
e19545e128 drm/rockchip: vop: Add support for force mcu rdn
The RV1126B introduce force RDN feature in MCU interface, which allow
to output high voltage level on the MCU_RDN line when MCU is sending
data, especially for data in the write direction. This feature helps
avoid unintended level flips on the RDN line.

Change-Id: I47d46e720e4ec44439570b216bddd694482851c7
Signed-off-by: Chaoyi Chen <chaoyi.chen@rock-chips.com>
2025-04-01 01:42:53 +00:00
Xing Zheng
381343d4fb ASoC: codecs: rk_dsm: Fix the silence during recover from XRUN
Here we need to restore the volume and ioswitch status.
Otherwise, there will be no sound if you restore from
the xrun state.

Signed-off-by: Xing Zheng <zhengxing@rock-chips.com>
Change-Id: I96e4bbcde035a700e2e18ee8782d75cdac2b18be
2025-04-01 01:42:09 +00:00
Damon Ding
49f88ec9c5 clk: rockchip: rk3576: expand pll rate table to support 152.6M vop dclk rate
Change-Id: Icd91181488730c2f88a3e8a9f6282afcc87123f8
Signed-off-by: Damon Ding <damon.ding@rock-chips.com>
2025-04-01 01:37:51 +00:00
Liang Chen
37bc97e286 arm64: configs: rv1126b: Enable CONFIG_ROCKCHIP_CLK_PVTPLL
Change-Id: I387a18151a5d7bb54b3060c47f1efa24b6f56f1e
Signed-off-by: Liang Chen <cl@rock-chips.com>
2025-03-31 11:50:53 +00:00
Elaine Zhang
2017b479cb clk: rockchip: rv1126b: fix soft reset num
Change-Id: Ie04afacca955d1a6bffb3b555cbb74986f927340
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2025-03-31 11:49:30 +00:00
Sugar Zhang
d05144590b arm64: dts: rockchip: rv1126b: Update audio_codec_pmu reg base
Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
Change-Id: Ic930eed27a04cb4d6fceb4b6995c9a839ce3d152
2025-03-31 11:45:26 +00:00
Joseph Chen
0a7732ef2f mfd: rk808: Use 'restart register' for rk801 rst function
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Ia9692a52525baed72b433fb0d94e79e6c3397463
2025-03-31 11:44:22 +00:00
Joseph Chen
331b32cfd3 regulator: rk801: Fix get mode
The error returns wrong mode but it doesn't result in a wrong set.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I078db470e3c7230b12f55685f021f01f4aa39157
2025-03-31 11:44:22 +00:00
Damon Ding
8332740f6c drm/rockchip: vop2: update the calculation of dclk_out division factor for RK3588 HDMI DSC mode
For RK3588, dclk_out is designed for DP, MIPI in both DSC and non-DSC
mode and HDMI in DSC mode.

In addditon, the dclk_out division factor should be the same as the
dclk_core division factor in HDMI DSC mode.

Change-Id: I08107a340036ff9984f52dd34044d8c634df14c1
Signed-off-by: Damon Ding <damon.ding@rock-chips.com>
2025-03-31 09:12:44 +00:00
Algea Cao
122ffa74f5 drm/bridge: synopsys: dw-hdmi-qp: Keep display state if userspace doesn't disable display pipeline after hdmi plug out.
However, the hdmi 2.0 spec requires that some flags are
set in the sink scdc regs, and those flags are very likely
to be reset when the cable has been disconnected. This will
thus result in a blank display, even if the display pipeline
configuration hasn't been modified or is in the exact
same state.

The solution we've had so far is to enable the scrambling
and high ratio related bits again on reconnection, but the
hdmi 2.0 spec (Section 6.1.3.1 - Scrambling Control) requires
that the scdc bit is set before sending any scrambled video
signal. Using that solution thus breaks that expectation.

So we need disable hdmi signal output when hdmi plug out.
writing scdc scrambling and high ratio regs when hdmi
plug in then enable hdmi signal output finally.

Change-Id: I422455e1d5b60c3fd4a3ef35ccb46de9fb0f28f8
Signed-off-by: Algea Cao <algea.cao@rock-chips.com>
2025-03-31 09:11:28 +00:00
luanyun lin
9367bc29e5 arm64: dts: rockchip: add rk3562-virtual-poweroff.dtsi to support virtual-poweroff for RK3562
Change-Id: If0c526d2785241229a6239a7a1b7818d5b4e69bd
Signed-off-by: luanyun lin <san.lin@rock-chips.com>
2025-03-31 09:10:31 +00:00
Michal Vrastil
fbed2bdfca UPSTREAM: Revert "usb: gadget: composite: fix OS descriptors w_value logic"
This reverts commit ec6ce7075ef879b91a8710829016005dc8170f17.

Fix installation of WinUSB driver using OS descriptors. Without the
fix the drivers are not installed correctly and the property
'DeviceInterfaceGUID' is missing on host side.

The original change was based on the assumption that the interface
number is in the high byte of wValue but it is in the low byte,
instead. Unfortunately, the fix is based on MS documentation which is
also wrong.

The actual USB request for OS descriptors (using USB analyzer) looks
like:

Offset  0   1   2   3   4   5   6   7
0x000   C1  A1  02  00  05  00  0A  00

C1: bmRequestType (device to host, vendor, interface)
A1: nas magic number
0002: wValue (2: nas interface)
0005: wIndex (5: get extended property i.e. nas interface GUID)
008E: wLength (142)

The fix was tested on Windows 10 and Windows 11.

Change-Id: Ic5535fb6f0dff1dc337b99bafb8500966538bcb5
Cc: stable@vger.kernel.org
Fixes: ec6ce7075ef8 ("usb: gadget: composite: fix OS descriptors w_value logic")
Signed-off-by: Michal Vrastil <michal.vrastil@hidglobal.com>
Signed-off-by: Elson Roy Serrao <quic_eserrao@quicinc.com>
Acked-by: Peter korsgaard <peter@korsgaard.com>
Link: https://lore.kernel.org/r/20241113235433.20244-1-quic_eserrao@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
2025-03-31 09:09:06 +00:00
William Wu
92f11a0056 usb: gadget: uvc: Fix frame size for framebase format
The commit e219a712bc ("usb: gadget: uvc: add v4l2
try_format api call") has introduced a bug that limit
the max frame size of framebase format (H264/H265) to
dw_max_video_frame_buffer_size which is a fixed value
460800 bytes.

This patch calculates the bytesperline value based on
the actual bBitsPerPixel and frame.w_width of framebase
format.

Fixes: e219a712bc ("usb: gadget: uvc: add v4l2 try_format api call")
Signed-off-by: William Wu <william.wu@rock-chips.com>
Change-Id: I40c5b72a9c3707bdcc13244d5ae912339626071b
2025-03-31 14:31:00 +08:00
Michael Grzeschik
b0914fdaab UPSTREAM: usb: gadget: uvc: dont call usb_composite_setup_continue when not streaming
If the streamoff call was triggered by some previous disconnect
or userspace application shutdown the uvc_function_setup_continue
should not be called and the state should not be overwritten.

For this situation the set_alt(0) was never called and the streaming ep
has no USB_GADGET_DELAYED_STATUS pending.

Since the state then was already updated before we also omit the state
update.

Change-Id: I65382e0ed663138ea694c27276fe813c30863f89
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20240403-uvc_request_length_by_interval-v7-9-e224bb1035f0@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit e723ebc3a9aa172ab8042382afcae310c953104d)
2025-03-31 14:31:00 +08:00
Michael Grzeschik
de97b80566 BACKPORT: usb: gadget: uvc: wake pump everytime we update the free list
Since the req_free list will updated if enqueuing one request was not
possible it will be added back to the free list. With every available
free request in the queue it is a valid case for the pump worker to use
it and continue the pending bufferdata into requests for the req_ready
list.

Change-Id: Ib52f29e23a938b469782f4b25221e127c01cc8a3
Fixes: 6acba0345b68 ("usb:gadget:uvc Do not use worker thread to pump isoc usb requests")
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20240403-uvc_request_length_by_interval-v7-1-e224bb1035f0@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit adc292d54de9db2e6b8ecb7f81f278bbbaf713e9)
2025-03-31 14:31:00 +08:00
Akash Kumar
8c339b276f BACKPORT: usb: gadget: uvc: configfs: Add frame-based frame format support
Add support for frame-based frame format, which can be used to support
multiple formats like H264 or H265, in addition to MJPEG and YUV frames.

The frame-based format is set to H264 by default, but it can be updated
to other formats by modifying the GUID through the guid configfs
attribute. Different structures are used for all three formats, as
H264 has a different structure compared to MJPEG and uncompressed
formats. These structures will be passed to the frame make function
based on the active format, using a common frame structure with
additional parameters needed only for frame-based formats. These
parameters are handled at runtime in the UVC driver.

Signed-off-by: Akash Kumar <quic_akakum@quicinc.com>
Link: https://lore.kernel.org/r/20240927152138.31416-1-quic_akakum@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Change-Id: I8be496e30e2f3f0e5756c0789c73f5c1746c9303
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit 7b5a58952fc3b51905c2963647485565df1e5e26)
2025-03-31 14:31:00 +08:00
Xu Yang
2c38326f65 UPSTREAM: usb: gadget: uvc: queue pump work in uvcg_video_enable()
Since commit "6acba0345b68 usb:gadget:uvc Do not use worker thread to pump
isoc usb requests", pump work could only be queued in uvc_video_complete()
and uvc_v4l2_qbuf(). If VIDIOC_QBUF is executed before VIDIOC_STREAMON,
we can only depend on uvc_video_complete() to queue pump work. However,
this requires some free requests in req_ready list. If req_ready list is
empty all the time, pump work will never be queued and video datas will
never be pumped to usb controller. Actually, this situation could happen
when run uvc-gadget with static image:

$ ./uvc-gadget -i 1080p.jpg uvc.0

When capture image from this device, the user app will always block there.

The issue is uvc driver has queued video buffer before streamon, but the
req_ready list is empty all the time after streamon. This will queue pump
work in uvcg_video_enable() to fill some request to req_ready list so the
uvc device could work properly.

Change-Id: Iedfba9335ea5f1a61dc1157f8d20c647803c84cd
Fixes: 6acba0345b68 ("usb:gadget:uvc Do not use worker thread to pump isoc usb requests")
Cc: stable@vger.kernel.org
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Link: https://lore.kernel.org/r/20240814112537.2608949-1-xu.yang_2@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit b52a07e07dead777517af3cbda851bb2cc157c9d)
2025-03-31 14:31:00 +08:00
Avichal Rakesh
c1a2d09287 UPSTREAM: usb: gadget: uvc: Remove nested locking
When handling error status from uvcg_video_usb_req_queue,
uvc_video_complete currently calls uvcg_queue_cancel with
video->req_lock held. uvcg_queue_cancel internally locks
queue->irqlock, which nests queue->irqlock inside
video->req_lock. This isn't a functional bug at the
moment, but does open up possibilities for ABBA
deadlocks in the future.

This patch fixes the accidental nesting by dropping
video->req_lock before calling uvcg_queue_cancel.

Change-Id: Ic96546cff545b397fdf52b4f361bca42702cb940
Fixes: 6acba0345b68 ("usb:gadget:uvc Do not use worker thread to pump isoc usb requests")
Signed-off-by: Avichal Rakesh <arakesh@google.com>
Link: https://lore.kernel.org/r/20240104215009.2252452-2-arakesh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit 9866dc4314c6c858e451933f965d64532aec00a9)
2025-03-31 14:31:00 +08:00
Avichal Rakesh
4548f07edf UPSTREAM: usb: gadget: uvc: Fix use are free during STREAMOFF
There is a path that may lead to freed memory being referenced,
causing kernel panics.

The kernel panic has the following stack trace:

Workqueue: uvcgadget uvcg_video_pump.c51fb85fece46625450f86adbf92c56c.cfi_jt
pstate: 60c00085 (nZCv daIf +PAN +UAO -TCO BTYPE=--)
pc : __list_del_entry_valid+0xc0/0xd4
lr : __list_del_entry_valid+0xc0/0xd4
Call trace:
  __list_del_entry_valid+0xc0/0xd4
  uvc_video_free_request+0x60/0x98
  uvcg_video_pump+0x1cc/0x204
  process_one_work+0x21c/0x4b8
  worker_thread+0x29c/0x574
  kthread+0x158/0x1b0
  ret_from_fork+0x10/0x30

The root cause is that uvcg_video_usb_req_queue frees the uvc_request
if is_enabled is false and returns an error status. video_pump also
frees the associated request if uvcg_video_usb_req_queue returns an
error status, leading to double free and accessing garbage memory.

To fix the issue, this patch removes freeing logic from
uvcg_video_usb_req_queue, and lets the callers to the function handle
queueing errors as they see fit.

Change-Id: I8d8e644de5b5f26601e7764fd675f775535f63d3
Fixes: 6acba0345b68 ("usb:gadget:uvc Do not use worker thread to pump isoc usb requests")
Tested-by: Avichal Rakesh <arakesh@google.com>
Signed-off-by: Avichal Rakesh <arakesh@google.com>
Link: https://lore.kernel.org/r/20240104215009.2252452-1-arakesh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit fe814b5b0f3042f1a583734497e726ee53783cc1)
2025-03-31 14:31:00 +08:00
Frank Li
4348336da3 BACKPORT: Revert "usb: gadget: f_uvc: change endpoint allocation in uvc_function_bind()"
This reverts commit 3c5b006f3e.

gadget_is_{super|dual}speed() API check UDC controller capitblity. It
should pass down highest speed endpoint descriptor to UDC controller. So
UDC controller driver can reserve enough resource at check_config(),
especially mult and maxburst. So UDC driver (such as cdns3) can know need
at least (mult + 1) * (maxburst + 1) * wMaxPacketSize internal memory for
this uvc functions.

Change-Id: Iae006b68943aac4ec9958e08a11f19dec270f954
Cc: <stable@vger.kernel.org>
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Link: https://lore.kernel.org/r/20231224153816.1664687-5-Frank.Li@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit 895ee5aefb7e24203de5dffae7ce9a02d78fa3d1)
2025-03-31 14:31:00 +08:00
Jayant Chowdhary
c9407f06fc UPSTREAM: usb:gadget:uvc Do not use worker thread to pump isoc usb requests
When we use an async work queue to perform the function of pumping
usb requests to the usb controller, it is possible that amongst other
factors, thread scheduling affects at what cadence we're able to pump
requests. This could mean isoc usb requests miss their uframes - resulting
in video stream flickers on the host device.

To avoid this, we make the async_wq thread only produce isoc usb_requests
with uvc buffers encoded into them. The process of queueing to the
endpoint is done by the uvc_video_complete() handler. In case no
usb_requests are ready with encoded information, we just queue a zero
length request to the endpoint from the complete handler.

For bulk endpoints the async_wq thread still queues usb requests to the
endpoint.

Change-Id: Idc1000fbd32f46455f3084101c15f00b05c20f80
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
Suggested-by: Avichal Rakesh <arakesh@google.com>
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Link: https://lore.kernel.org/r/20231120062026.3759463-1-jchowdhary@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit 6acba0345b68772830582ca1ca369a2f45631275)
2025-03-31 14:31:00 +08:00
Avichal Rakesh
5f00f1b5a7 UPSTREAM: usb: gadget: uvc: Fix use-after-free for inflight usb_requests
Currently, the uvc gadget driver allocates all uvc_requests as one array
and deallocates them all when the video stream stops. This includes
de-allocating all the usb_requests associated with those uvc_requests.
This can lead to use-after-free issues if any of those de-allocated
usb_requests were still owned by the usb controller.

This is patch 2 of 2 in fixing the use-after-free issue. It adds a new
flag to uvc_video to track when frames and requests should be flowing.
When disabling the video stream, the flag is tripped and, instead
of de-allocating all uvc_requests and usb_requests, the gadget
driver only de-allocates those usb_requests that are currently
owned by it (as present in req_free). Other usb_requests are left
untouched until their completion handler is called which takes care
of freeing the usb_request and its corresponding uvc_request.

Now that uvc_video does not depends on uvc->state, this patch removes
unnecessary upates to uvc->state that were made to accommodate uvc_video
logic. This should ensure that uvc gadget driver never accidentally
de-allocates a usb_request that it doesn't own.

Change-Id: Ie1cc134c191e087bcca114832ad99f5d3119e682
Link: https://lore.kernel.org/7cd81649-2795-45b6-8c10-b7df1055020d@google.com
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Suggested-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Tested-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Avichal Rakesh <arakesh@google.com>
Link: https://lore.kernel.org/r/20231109004104.3467968-4-arakesh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit da324ffce34c521b239f319d4051260444a3eb4a)
2025-03-31 14:31:00 +08:00
Avichal Rakesh
c5a3634277 UPSTREAM: usb: gadget: uvc: move video disable logic to its own function
This patch refactors the video disable logic in uvcg_video_enable
into its own separate function 'uvcg_video_disable'. This function
is now used anywhere uvcg_video_enable(video, 0) was used.

Change-Id: Ifba331485eee8b671126d92f5af7a2f71d79ecc2
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Suggested-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Avichal Rakesh <arakesh@google.com>
Link: https://lore.kernel.org/r/20231109004104.3467968-3-arakesh@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: William Wu <william.wu@rock-chips.com>
(cherry picked from commit 2079b60bda3257146a4e8ed7525513865f7e6b3e)
2025-03-31 14:31:00 +08:00