From patchwork Thu Jan 2 18:19:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaro Koskinen X-Patchwork-Id: 855118 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C8DB1917FB; Thu, 2 Jan 2025 18:20:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735842013; cv=pass; b=IkbxwALRCbRl8vAqfwBktJ09zaeWyIsJzcRJAZeX9+E1FtNEJsf9wpYPEIAX68cIl4Ph1qGgAAnHND6kNf5Qjp2wVz1rHnOx1q5PknUZ9a6WIKy/6KroqMw2Xs6YMYG0r/EOgUkhGTmTCkJnKAMHus5r83EjaaXSk4yC0bQFgF0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735842013; c=relaxed/simple; bh=qv/VlLekQPhGRpk8vEhrhaQa+VvN3hOLRFgY/yQUbVo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sAxzGDYMYb0BRqO6vokbAWVCOPj5XQBxQRw4ezMPvrDf/XguzhwvEatUgYFWIKL3PkIYWo/wAxss9DMfHi63N/+ZSPa5Oo93boU2b+4mQo0bBwpPEFaxsd+gcCHUIlFbk2rMMUQcx9ZKe8GGxPXQn2UmLFsZMjWJ+T3dIH10WIQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=Dhl6GopV; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="Dhl6GopV" Received: from darkstar.. (85-76-116-195-nat.elisa-mobile.fi [85.76.116.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: aaro.koskinen) by meesny.iki.fi (Postfix) with ESMTPSA id 4YPFNx75R0zyfh; Thu, 2 Jan 2025 20:20:01 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1735842002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lRbGXqYktUW/gFltGyPoMIh4JupBfrLim1rMCpE9DT0=; b=Dhl6GopVPYrVeXJtGlfuahsYwV+u3RDgFOO2+siYGz5Xs15/4X5OIsMMMyGz1TWKBABUOm qtUTIxboOhEoNjzjpVGj041DEX8ZaHr70IKKKkplf42t6ocW4XPoq5NCEp+4/9Wq67VDGJ 09P0h0L+YH5zCBoX9cmGyGOp7ZXuMv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1735842002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lRbGXqYktUW/gFltGyPoMIh4JupBfrLim1rMCpE9DT0=; b=sysYI8rKe4LZOfyYVfMd3JFe/7/h136ZqduASkpgc77AADQYNJAQPiepAG7nIq326b8WU1 SvY/WDGzMP7hqTWKwajJD1mtwvJZ6+W7gfK0Lvr6ieIVzq9cWo85BrOqAtI1+dBte++G3R +97z/XCM4hcP1w3KbPJ0HV47fBDqA5o= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=aaro.koskinen smtp.mailfrom=aaro.koskinen@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1735842002; a=rsa-sha256; cv=none; b=XBOw7wq7Z5YlMurVq+96wjH5fWcCV316RbaiQZjgMD9sFQKNPdyGJhDk3TYArbYxpub8g8 YQsOvwHpigd4iBJLTBISZgzfQcVxf3UKY9H41vE4s2zNHw1rBoa548Nx21h+T0dJihYbzl 9Y9ehSTl4gBsorKnF2DlVKV4LbhaiI0= From: Aaro Koskinen To: Dmitry Torokhov , Helge Deller , Janusz Krzysztofik , Tony Lindgren , Linus Walleij , linux-fbdev@vger.kernel.org, linux-omap@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Aaro Koskinen Subject: [PATCH 1/3] fbdev: omap: use threaded IRQ for LCD DMA Date: Thu, 2 Jan 2025 20:19:51 +0200 Message-ID: <20250102181953.1020878-2-aaro.koskinen@iki.fi> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250102181953.1020878-1-aaro.koskinen@iki.fi> References: <20250102181953.1020878-1-aaro.koskinen@iki.fi> Precedence: bulk X-Mailing-List: linux-omap@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When using touchscreen and framebuffer, Nokia 770 crashes easily with: BUG: scheduling while atomic: irq/144-ads7846/82/0x00010000 Modules linked in: usb_f_ecm g_ether usb_f_rndis u_ether libcomposite configfs omap_udc ohci_omap ohci_hcd CPU: 0 UID: 0 PID: 82 Comm: irq/144-ads7846 Not tainted 6.12.7-770 #2 Hardware name: Nokia 770 Call trace: unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x54/0x5c dump_stack_lvl from __schedule_bug+0x50/0x70 __schedule_bug from __schedule+0x4d4/0x5bc __schedule from schedule+0x34/0xa0 schedule from schedule_preempt_disabled+0xc/0x10 schedule_preempt_disabled from __mutex_lock.constprop.0+0x218/0x3b4 __mutex_lock.constprop.0 from clk_prepare_lock+0x38/0xe4 clk_prepare_lock from clk_set_rate+0x18/0x154 clk_set_rate from sossi_read_data+0x4c/0x168 sossi_read_data from hwa742_read_reg+0x5c/0x8c hwa742_read_reg from send_frame_handler+0xfc/0x300 send_frame_handler from process_pending_requests+0x74/0xd0 process_pending_requests from lcd_dma_irq_handler+0x50/0x74 lcd_dma_irq_handler from __handle_irq_event_percpu+0x44/0x130 __handle_irq_event_percpu from handle_irq_event+0x28/0x68 handle_irq_event from handle_level_irq+0x9c/0x170 handle_level_irq from generic_handle_domain_irq+0x2c/0x3c generic_handle_domain_irq from omap1_handle_irq+0x40/0x8c omap1_handle_irq from generic_handle_arch_irq+0x28/0x3c generic_handle_arch_irq from call_with_stack+0x1c/0x24 call_with_stack from __irq_svc+0x94/0xa8 Exception stack(0xc5255da0 to 0xc5255de8) 5da0: 00000001 c22fc620 00000000 00000000 c08384a8 c106fc00 00000000 c240c248 5dc0: c113a600 c3f6ec30 00000001 00000000 c22fc620 c5255df0 c22fc620 c0279a94 5de0: 60000013 ffffffff __irq_svc from clk_prepare_lock+0x4c/0xe4 clk_prepare_lock from clk_get_rate+0x10/0x74 clk_get_rate from uwire_setup_transfer+0x40/0x180 uwire_setup_transfer from spi_bitbang_transfer_one+0x2c/0x9c spi_bitbang_transfer_one from spi_transfer_one_message+0x2d0/0x664 spi_transfer_one_message from __spi_pump_transfer_message+0x29c/0x498 __spi_pump_transfer_message from __spi_sync+0x1f8/0x2e8 __spi_sync from spi_sync+0x24/0x40 spi_sync from ads7846_halfd_read_state+0x5c/0x1c0 ads7846_halfd_read_state from ads7846_irq+0x58/0x348 ads7846_irq from irq_thread_fn+0x1c/0x78 irq_thread_fn from irq_thread+0x120/0x228 irq_thread from kthread+0xc8/0xe8 kthread from ret_from_fork+0x14/0x28 As a quick fix, switch to a threaded IRQ which provides a stable system. Signed-off-by: Aaro Koskinen --- drivers/video/fbdev/omap/lcd_dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/video/fbdev/omap/lcd_dma.c b/drivers/video/fbdev/omap/lcd_dma.c index f85817635a8c..0da23c57e475 100644 --- a/drivers/video/fbdev/omap/lcd_dma.c +++ b/drivers/video/fbdev/omap/lcd_dma.c @@ -432,8 +432,8 @@ static int __init omap_init_lcd_dma(void) spin_lock_init(&lcd_dma.lock); - r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0, - "LCD DMA", NULL); + r = request_threaded_irq(INT_DMA_LCD, NULL, lcd_dma_irq_handler, + IRQF_ONESHOT, "LCD DMA", NULL); if (r != 0) pr_err("unable to request IRQ for LCD DMA (error %d)\n", r); From patchwork Thu Jan 2 18:19:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaro Koskinen X-Patchwork-Id: 854805 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98D9818FC89; Thu, 2 Jan 2025 18:20:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735842012; cv=pass; b=VY1Naq+S8iN3hnbvqKA8Qegxq8NeuCUx0v/LBTOvUjSJRTHw+u6XyA/KQ/xUKfezDYa1ZEWQKEN7l0YquKmN/cUkS2YoF3iMxRWqTnFfK0EHVG1LoR1PhcQAXT8713qVw9CJH2v3sSE8V2j8iLI4rHCVr9b8lBWOv06EtWzGuLU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735842012; c=relaxed/simple; bh=0amcruyUhZ0TCaR74TWA+Nd564QsXdKTPAGngUKkOWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YNye9WGJBA91OYEQxkk5eHkYzjnIvBSI4xEvS++tYxKu6SDHc/Y1S4EnPwyU7rp7f0Ba/C0HWM5CKDZKgpajLsoSI2YzZj+fmRhEuFWSHzDpQOMpZAmIjZjYql+/YJ7zyRwFUYrt9SWaOpZQVgw0if6u5eXYmYkd7HCB9/4aAeU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=jBwa1CUb; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="jBwa1CUb" Received: from darkstar.. (85-76-116-195-nat.elisa-mobile.fi [85.76.116.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: aaro.koskinen) by meesny.iki.fi (Postfix) with ESMTPSA id 4YPFNy6VDLz10Fp; Thu, 2 Jan 2025 20:20:02 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1735842003; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5b3HVJ5u5IW7DiTMu6Bpl+/MZHk5pBEG4La1Q1ydqiQ=; b=jBwa1CUbXj2omTZzDdJGrQU0e84PxIR8Ai2hbuyPEbc4+Yv0OzrPVYQOspdNhu/cWPhoap YgcERbR3yL1SYcTWThWtU5PvXjhNhky7VFDlZTIrq/TSImxXAvVk1Z4QfCXnW0amvWe3sY F1Nj213nE276qGhKSUCjDxH4DISeOB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1735842003; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5b3HVJ5u5IW7DiTMu6Bpl+/MZHk5pBEG4La1Q1ydqiQ=; b=nNbCwonIsDbvJlz1mXCO8qqtXk2FnNvadla4qLxRjWUqiPYG3Wdf8p740kHdZvNO/jrDL8 Onn+PtMtOCHqAU8wmhZjIBbNmp3YQ40dYf5uuIiuueDmUoPIES8fgY2XSMVo/ud6lBjYPD ikSYSkPyOLfjU6azydLVB7E+INYtVNg= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=aaro.koskinen smtp.mailfrom=aaro.koskinen@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1735842003; a=rsa-sha256; cv=none; b=Q2dzVOi+EJvY0R+RYSk7SUg1y3Vdej5bzVN91jR2vKphuvBI6gYd4SZ58bSH0KZF69XE5D ftMvLxRPfk5NpQZbuuU0es5S1wWbzZujJerQKYDmEvvTZWZlRsgMANEc+0BTTVpO+JlsmW 70rtKGx/HwhjkhTGlFMLzx6/5BmFPho= From: Aaro Koskinen To: Dmitry Torokhov , Helge Deller , Janusz Krzysztofik , Tony Lindgren , Linus Walleij , linux-fbdev@vger.kernel.org, linux-omap@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Aaro Koskinen Subject: [PATCH 2/3] Input: ads7846 - fix up the pendown GPIO setup on Nokia 770 Date: Thu, 2 Jan 2025 20:19:52 +0200 Message-ID: <20250102181953.1020878-3-aaro.koskinen@iki.fi> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250102181953.1020878-1-aaro.koskinen@iki.fi> References: <20250102181953.1020878-1-aaro.koskinen@iki.fi> Precedence: bulk X-Mailing-List: linux-omap@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The GPIO is set up as an IRQ, so request it as non-exclusive. Otherwise the probe fails on Nokia 770 with: ads7846 spi2.0: failed to request pendown GPIO ads7846: probe of spi2.0 failed with error -16 Also the polarity is wrong. Fix it. Fixes: 767d83361aaa ("Input: ads7846 - Convert to use software nodes") Signed-off-by: Aaro Koskinen --- arch/arm/mach-omap1/board-nokia770.c | 2 +- drivers/input/touchscreen/ads7846.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm/mach-omap1/board-nokia770.c b/arch/arm/mach-omap1/board-nokia770.c index 3312ef93355d..9153b1a81577 100644 --- a/arch/arm/mach-omap1/board-nokia770.c +++ b/arch/arm/mach-omap1/board-nokia770.c @@ -287,7 +287,7 @@ static struct gpiod_lookup_table nokia770_irq_gpio_table = { .table = { /* GPIO used by SPI device 1 */ GPIO_LOOKUP("gpio-0-15", 15, "ads7846_irq", - GPIO_ACTIVE_HIGH), + GPIO_ACTIVE_LOW), /* GPIO used for retu IRQ */ GPIO_LOOKUP("gpio-48-63", 15, "retu_irq", GPIO_ACTIVE_HIGH), diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 066dc04003fa..54280ecca0a7 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -1021,7 +1021,8 @@ static int ads7846_setup_pendown(struct spi_device *spi, if (pdata->get_pendown_state) { ts->get_pendown_state = pdata->get_pendown_state; } else { - ts->gpio_pendown = gpiod_get(&spi->dev, "pendown", GPIOD_IN); + ts->gpio_pendown = gpiod_get(&spi->dev, "pendown", GPIOD_IN | + GPIOD_FLAGS_BIT_NONEXCLUSIVE); if (IS_ERR(ts->gpio_pendown)) { dev_err(&spi->dev, "failed to request pendown GPIO\n"); return PTR_ERR(ts->gpio_pendown); From patchwork Thu Jan 2 18:19:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaro Koskinen X-Patchwork-Id: 854804 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF66118B483; Thu, 2 Jan 2025 18:20:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735842015; cv=pass; b=jE+Dre7T+ty4TrUaMRXlQsxWdU1zKEetKM4fzbSH9IYvV8GHB7OMVYYHRPY1yzY46HjPgMMTjE8oilIKeAcYtNCDbfO71yrOhMwniaZhNL2tP8xa9a1nQDrizb1tJaLliYDR+UPMnarRW11WiGjanMjbl1XWVUUyVjDJxtf8OaQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735842015; c=relaxed/simple; bh=tblwxUmb7AHbvm2rXCcFi2dcrO58Ntrn2JL7FcJPt2U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kKtgaG3k80AgAJTZrmvwl0s6Sx/UxSMCGagbz/9HK2bP9Skhg+3gPIL1qzWm9E0KEstaeV/keu/rowmerjdAd3MC6xsygO/CT+JJMWkSy/+GtK4dbkKvfNoa49F3qobcw8fVR/KPMTyaGwvGvbrmIiOfMpiAk97FCljZWirXeeM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=KvGCYsV3; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="KvGCYsV3" Received: from darkstar.. (85-76-116-195-nat.elisa-mobile.fi [85.76.116.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: aaro.koskinen) by meesny.iki.fi (Postfix) with ESMTPSA id 4YPFNz4VnHz10DH; Thu, 2 Jan 2025 20:20:03 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1735842004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cw9JrGu+z6+Ep7xC+G+Ho+ahkF7zCarWeKEmRTbUS1o=; b=KvGCYsV3L2xQvPWmwOnGBJruUa9+YzS2owa6RCg1C9+S6SwYk2f8jax/bedccYydTEuUrN Ce91hS3TdZ/QFCem+keUPdPIdVFqcwbeR2cUO3wpb8axPX5ovYof22Zn67T7dVEht4GZ4s foNUtTD0F5yOWisYLLZAp1QWE5Ho1Rw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1735842004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cw9JrGu+z6+Ep7xC+G+Ho+ahkF7zCarWeKEmRTbUS1o=; b=s8CG/2DWOW4EiOFbi/lvnsoPaXmplpJ4KATo4bAzy8bm/XusjOoqm5LrGb6IlBa9990Kv4 9/qPqiteeMnzJ+n1Odeb4POgIqSuKEx4FWhk8D8m4Z7oaqfk0dDAkS8raN0hYG1A4XYQ1o 9CGCkPNhRPOGIhKO1IHMU2zE7VR5mio= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=aaro.koskinen smtp.mailfrom=aaro.koskinen@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1735842004; a=rsa-sha256; cv=none; b=t3RNzQPy/LdIXctE8N7Z1qDukCxAGXfLLBR91K9JvXxTxYF6ighIeb8sgYdxLR1cuNqbpx +7kTRyrCA/CMuPgxG4L2rhDqPcHt+CWZNp69Jj1tjK9FKCBOBMcDXy0UowUl9ukgMdeXVG obP5JvYeOo3Q3Wdbx1u3oDj0MLDmBG0= From: Aaro Koskinen To: Dmitry Torokhov , Helge Deller , Janusz Krzysztofik , Tony Lindgren , Linus Walleij , linux-fbdev@vger.kernel.org, linux-omap@vger.kernel.org, linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Aaro Koskinen Subject: [PATCH 3/3] Input: ads7846 - restore half-duplex support Date: Thu, 2 Jan 2025 20:19:53 +0200 Message-ID: <20250102181953.1020878-4-aaro.koskinen@iki.fi> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250102181953.1020878-1-aaro.koskinen@iki.fi> References: <20250102181953.1020878-1-aaro.koskinen@iki.fi> Precedence: bulk X-Mailing-List: linux-omap@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On some boards, the SPI controller is limited to half-duplex and the driver is just spamming "ads7846 spi2.0: spi_sync --> -22". Restore half-duplex support using multiple SPI transfers. Fixes: 9c9509717b53 ("Input: ads7846 - convert to full duplex") Signed-off-by: Aaro Koskinen --- drivers/input/touchscreen/ads7846.c | 168 +++++++++++++++++++++++++++- 1 file changed, 166 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 54280ecca0a7..276591c682ad 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -134,6 +134,9 @@ struct ads7846 { bool disabled; /* P: lock */ bool suspended; /* P: lock */ + int (*setup_spi_msg)(struct ads7846 *ts, + const struct ads7846_platform_data *pdata); + void (*read_state)(struct ads7846 *ts); int (*filter)(void *data, int data_idx, int *val); void *filter_data; int (*get_pendown_state)(void); @@ -797,6 +800,22 @@ static int ads7846_filter(struct ads7846 *ts) return 0; } +static int ads7846_filter_one(struct ads7846 *ts, unsigned int cmd_idx) +{ + struct ads7846_packet *packet = ts->packet; + struct ads7846_buf_layout *l = &packet->l[cmd_idx]; + int action, val; + + val = ads7846_get_value(&packet->rx[l->offset + l->count - 1]); + action = ts->filter(ts->filter_data, cmd_idx, &val); + if (action == ADS7846_FILTER_REPEAT) + return -EAGAIN; + else if (action != ADS7846_FILTER_OK) + return -EIO; + ads7846_set_cmd_val(ts, cmd_idx, val); + return 0; +} + static void ads7846_wait_for_hsync(struct ads7846 *ts) { if (ts->wait_for_sync) { @@ -819,6 +838,45 @@ static void ads7846_wait_for_hsync(struct ads7846 *ts) cpu_relax(); } +static void ads7846_halfd_read_state(struct ads7846 *ts) +{ + struct ads7846_packet *packet = ts->packet; + int msg_idx = 0; + + packet->ignore = false; + + while (msg_idx < ts->msg_count) { + int error; + + ads7846_wait_for_hsync(ts); + + error = spi_sync(ts->spi, &ts->msg[msg_idx]); + if (error) { + dev_err_ratelimited(&ts->spi->dev, "spi_sync --> %d\n", + error); + packet->ignore = true; + return; + } + + /* + * Last message is power down request, no need to convert + * or filter the value. + */ + if (msg_idx == ts->msg_count - 1) + break; + + error = ads7846_filter_one(ts, msg_idx); + if (error == -EAGAIN) { + continue; + } else if (error) { + packet->ignore = true; + msg_idx = ts->msg_count - 1; + } else { + msg_idx++; + } + } +} + static void ads7846_read_state(struct ads7846 *ts) { struct ads7846_packet *packet = ts->packet; @@ -947,7 +1005,7 @@ static irqreturn_t ads7846_irq(int irq, void *handle) while (!ts->stopped && get_pendown_state(ts)) { /* pen is down, continue with the measurement */ - ads7846_read_state(ts); + ts->read_state(ts); if (!ts->stopped) ads7846_report_state(ts); @@ -1035,6 +1093,102 @@ static int ads7846_setup_pendown(struct spi_device *spi, return 0; } +/* + * Set up the transfers to read touchscreen state; this assumes we + * use formula #2 for pressure, not #3. + */ +static int ads7846_halfd_spi_msg(struct ads7846 *ts, + const struct ads7846_platform_data *pdata) +{ + struct spi_message *m = ts->msg; + struct spi_transfer *x = ts->xfer; + struct ads7846_packet *packet = ts->packet; + int vref = pdata->keep_vref_on; + unsigned int offset = 0; + unsigned int cmd_idx, b; + size_t size = 0; + + if (pdata->settle_delay_usecs) + packet->count = 2; + else + packet->count = 1; + + if (ts->model == 7846) + packet->cmds = 5; /* x, y, z1, z2, pwdown */ + else + packet->cmds = 3; /* x, y, pwdown */ + + for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) { + struct ads7846_buf_layout *l = &packet->l[cmd_idx]; + unsigned int max_count; + + if (cmd_idx == packet->cmds - 1) { + cmd_idx = ADS7846_PWDOWN; + max_count = 1; + } else { + max_count = packet->count; + } + + l->offset = offset; + offset += max_count; + l->count = max_count; + l->skip = 0; + size += sizeof(*packet->rx) * max_count; + } + + /* We use two transfers per command. */ + if (ARRAY_SIZE(ts->xfer) < offset * 2) + return -ENOMEM; + + packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); + if (!packet->rx) + return -ENOMEM; + + if (ts->model == 7873) { + /* + * The AD7873 is almost identical to the ADS7846 + * keep VREF off during differential/ratiometric + * conversion modes. + */ + ts->model = 7846; + vref = 0; + } + + ts->msg_count = 0; + + for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) { + struct ads7846_buf_layout *l = &packet->l[cmd_idx]; + u8 cmd; + + ts->msg_count++; + spi_message_init(m); + m->context = ts; + + if (cmd_idx == packet->cmds - 1) + cmd_idx = ADS7846_PWDOWN; + + cmd = ads7846_get_cmd(cmd_idx, vref); + + for (b = 0; b < l->count; b++) { + packet->rx[l->offset + b].cmd = cmd; + x->tx_buf = &packet->rx[l->offset + b].cmd; + x->len = 1; + spi_message_add_tail(x, m); + x++; + x->rx_buf = &packet->rx[l->offset + b].data; + x->len = 2; + if (b < l->count - 1 && l->count > 1) { + x->delay.value = pdata->settle_delay_usecs; + x->delay.unit = SPI_DELAY_UNIT_USECS; + } + spi_message_add_tail(x, m); + x++; + } + m++; + } + return 0; +} + /* * Set up the transfers to read touchscreen state; this assumes we * use formula #2 for pressure, not #3. @@ -1249,6 +1403,14 @@ static int ads7846_probe(struct spi_device *spi) if (!ts) return -ENOMEM; + if (spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) { + ts->setup_spi_msg = ads7846_halfd_spi_msg; + ts->read_state = ads7846_halfd_read_state; + } else { + ts->setup_spi_msg = ads7846_setup_spi_msg; + ts->read_state = ads7846_read_state; + } + packet = devm_kzalloc(dev, sizeof(struct ads7846_packet), GFP_KERNEL); if (!packet) return -ENOMEM; @@ -1343,7 +1505,9 @@ static int ads7846_probe(struct spi_device *spi) ts->core_prop.swap_x_y = true; } - ads7846_setup_spi_msg(ts, pdata); + err = ts->setup_spi_msg(ts, pdata); + if (err) + return err; ts->reg = devm_regulator_get(dev, "vcc"); if (IS_ERR(ts->reg)) {