From patchwork Mon Feb 21 10:56:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Mo=C5=84?= X-Patchwork-Id: 544622 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FA4CC43217 for ; Mon, 21 Feb 2022 11:16:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355756AbiBULRP (ORCPT ); Mon, 21 Feb 2022 06:17:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356320AbiBULQW (ORCPT ); Mon, 21 Feb 2022 06:16:22 -0500 X-Greylist: delayed 66 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 21 Feb 2022 02:57:59 PST Received: from eu-smtp-delivery-197.mimecast.com (eu-smtp-delivery-197.mimecast.com [185.58.86.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 93587DF52 for ; Mon, 21 Feb 2022 02:57:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=camlingroup.com; s=mimecast20210310; t=1645441077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lyk1Iv2AyEpdVklKZ/IDwiuJJEQ9EyrVIcrOte333Ag=; b=PyGTaF7MvLH44pmxWWwXpN364NyqtlrgNNRk+8ujwre//pBSJhQGhbDO+tT3ocp6nN+hhk Ok51Mx6RZmmfaUaZKqySNLVvnGL+Gd0dAeh2P6poPxj3YaGVuG++aPaf476pb1L705+67s GRmtwRSBXmfjzvenRfOZ4OVcjJVgfYM= Received: from GBR01-LO2-obe.outbound.protection.outlook.com (mail-lo2gbr01lp2058.outbound.protection.outlook.com [104.47.21.58]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id uk-mta-27-0W8be5_rNGatXmzuGt-v3Q-2; Mon, 21 Feb 2022 10:56:50 +0000 X-MC-Unique: 0W8be5_rNGatXmzuGt-v3Q-2 Received: from CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:16b::6) by CWLP123MB6574.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:184::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.24; Mon, 21 Feb 2022 10:56:49 +0000 Received: from CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM ([fe80::6dad:8602:45c5:6747]) by CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM ([fe80::6dad:8602:45c5:6747%8]) with mapi id 15.20.4995.027; Mon, 21 Feb 2022 10:56:49 +0000 From: =?utf-8?q?Tomasz_Mo=C5=84?= To: linux-serial@vger.kernel.org CC: Phil Elwell , Daniel Mack , Jiri Slaby , Greg Kroah-Hartman , =?utf-8?q?Krzysztof_Drobi?= =?utf-8?q?=C5=84ski?= , Lech Perczak , =?utf-8?q?Tomasz_Mo=C5=84?= Subject: [PATCH 1/6] sc16is7xx: Preserve EFR bits on update Date: Mon, 21 Feb 2022 11:56:13 +0100 Message-ID: <20220221105618.3503470-2-tomasz.mon@camlingroup.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220221105618.3503470-1-tomasz.mon@camlingroup.com> References: <20220221105618.3503470-1-tomasz.mon@camlingroup.com> X-ClientProxiedBy: LO4P123CA0469.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a8::6) To CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:16b::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 271ac456-7c74-480c-3e7b-08d9f528dc92 X-MS-TrafficTypeDiagnostic: CWLP123MB6574:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: 5HRViof0OKNF0L9wYMRjP+4OZjx1fw8gjWZxZC1a+Hblqi32cbY68XA2HJCd3IAt1w9BLWhLoOw9RrqqoUuPT+2wALtI8s2wMktOjuQGoZkvW8Si92GYOF0KlHje5adIns5krAuzsc+1RiRGxFRJPVwWOU5LEhetYEWIVeWuwFxg3QAfCaULnjAq/d+IzwrC4ey7C6IrQNeIT7QttAc1kdSmHjMRnVAIHN9Sl8ZP2ItJGwAJlhnVubZtM3bqAWO8LwQyeBY8Evg8Wvl1r9br81ghlB1K2ZcoRx0L/GoQZtgO2NPGzhz7U05x7HUqHGB/WxbWPcqLQ8VEI1KaenvEUWqST3sj5Yhoypx4HbPEx9RVOYxUwJ5trNRtneClkuH9/ngZHgul7F2tpul2uPQ8gpJIB6fmvFg6yW2zOkyYi7rRSUuNPcSNnuhsWFB6N6qdWJCh7CYE0+2a1L4QzEa0zWwkignd68VJexMy3VQ9N+fp3osp+555q8akT1sP8peSL5vgY1VZR4jMdlQjPBicQS+TXQwPjgys0b4vHPJ+uSLGA8yshuqJHsWX+FCyU7igTZ3exEgWDGPY4KIlBu0gR6y4IGFIm5SvKjfSDGcDFLHt8/xyx1n7rIbBqCwO6xnlI5UT+Iivj/Qmv5hRQKTOd4XIJM8/2aHIg9FXUovoeXANvzn3TgDvrapJd7EzgXxqKGdTcB7uJ3NSoLfh/15pYA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230001)(366004)(107886003)(52116002)(6666004)(6512007)(6506007)(5660300002)(508600001)(8936002)(38350700002)(38100700002)(36756003)(15650500001)(2906002)(86362001)(4326008)(8676002)(6486002)(54906003)(2616005)(83380400001)(66946007)(66556008)(66476007)(6916009)(316002)(26005)(186003)(1076003); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bC8G89OeoTGJ7C48fMMvFuS67Q6jKt5VDBmL4EdRr9Avydj2/nou+XBeOdpdHa5LmSabpdoXpHJr3MtUmtGve9uBm/7/YhlmPg+K5BV45TzD1iK+WGglVtSDdIN8wvhoVcRDneduQ+cnv3+xHowMbx1uKV9cKQ2P3x3UXMusJ4A+RwPf9jJmkaKk9ca3X5XzqYChpcKa/8Agwlf//SCsmp4nXX5h2rG40/VqRM7FfQ8I0/AkXUJs8QAc5UZ7uTufwy13QmEG3fBUK8dyq0wKaQa3nD/a4ZHJDTjkmG7XOimWrc8k+3CISJNNvke40ZQWK7Ar4EPELXGzyobcuuhPxAY9ZqDljBNjnn3VJtt/i6s0GQpzyVHF4jMjIK5D8mWN4uzPzhhWeI+umrkeIZwJKA9Hn/FFeBr6W3dfYpLL6nhfVHAk6dnrDRElQniSt93MHguR9PL92to3BdNEBGllmUerGYqWc9nF0Jh2q2PBeudP4zmRoF2TZ9ssOFBaBbZIW3v0eeMdA/GAMEA6HbTfFBgZfwiBWrp2+jtec7fH/3/Zt/eFghGu6yvku8pea0LroJix3UTg4r/nC09ZzAIOGAbEwJXxi/tYcmm1apQH6qcHJtmCBSrl+VeT8sNml9NW6kC2zVyS5UIufbMP76l/MHJHnIYLMr6+3Tq5i7QKSKf58UiJrYG2WkMb6nlvxs700gG5Jh2lebzQRuzz6YliYe4HFKit7O77VyBifUMsHDFmehcsuXWfkKDBXUL4iYP/x5NrbALP/yHLRWmZqydY17rlUrx1+YiVpELieHI4BdGavFTnO7yhC94/7cdU9cyrhLTes819ys22G7ilppm/p1nB20qJrce8t+COOv7TpYJAP/LWglQKfKjsn8XlxctYltRmELdn7V5ZbOKwYXpzv7/5biC96oasP7fiJYo0OJ+lOh61Y8xSeh7LyroYobfkmOed4SHlo8j8/DZSTyfIPwvZM8e+Oi4ZiP9Je7QA4XnWsH/w9OaSHMrP78f+krNWanWMj+LnUnSMGY4R04l1qR9TD95OmACi6sEmPUtDV2BnSBa4FBWgKc6pvPon1lkuv2f6WgOx/WVrpkOu4gydkkxi9dYv5+2o0zPYstxkWGARcdPtDOUe2fQE9344QmzP5I6EjgVvPUpKFYq73DyqYxl9x3G/OC3dvFsJbuI/p115uTAtJ/JMKffg2tEnNNu3v5E9gqQeahBjDeAEqoJwpcXORBa41hV1Tkuoyp0WZ9gHuo6I/TxrSTzX4h8osvBRgCyRU8ShjMDz6F5tGXNpQeVul9q3j7QwLThkos+64pfhp8eT7pydDB409CsCyF6Pxx9P/mwidzMbu+XQW+mSrzLJlmI1rYKbHdyFnFc0DF095j1kZ9RCGyxF7gQ9beRwF4OwpUSWEcpmULexhx9ADyA/b48qEEFBSb1H43nsVklWYrFjwr14Qw72u61tc2HZHXcvnP4DH6BnAQNGwCkSj3bxNKXPcSaPjnmYPSW0E0QYAT2qEEgS8pXZyYqnBZkL/SJznK9MIOfBNVOAoUDpEtev6PBafXI/bgj7yQM56WAQir4YyJJem7YFzk7aRmYh+RP670pXrDuGpbuOEAcVbdgq/h+CAnyz+qN1VQANKtCMUyTOiczXrmTX7jponpIIiZvsIQHgNbX2KT2oEaZxdeqMC0iFkpFVwf8CTviyvdU= X-OriginatorOrg: camlingroup.com X-MS-Exchange-CrossTenant-Network-Message-Id: 271ac456-7c74-480c-3e7b-08d9f528dc92 X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Feb 2022 10:56:49.8641 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fd4b1729-b18d-46d2-9ba0-2717b852b252 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Z+rZ03km6qkU44kTRA6fIEhG49yYCGy1G04ab3ymGCCbM7kqdenCpHr+6qm1CADd59o5screprn9zw7QmcY5Z8ryNiit/e8FdxzGUeU3hng= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP123MB6574 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUK97A341 smtp.mailfrom=tomasz.mon@camlingroup.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: camlingroup.com Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lech Perczak Preserve unaffected bits state when accessing EFR register. This prevents hardware flow control bits from being cleared on enhanced functions access. Signed-off-by: Lech Perczak Signed-off-by: Tomasz Moń --- drivers/tty/serial/sc16is7xx.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 38d1c0748533..3800733452fe 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -289,6 +289,14 @@ * XON1, XON2, XOFF1 and * XOFF2 */ +#define SC16IS7XX_EFR_FLOWCTRL_BITS (SC16IS7XX_EFR_AUTORTS_BIT | \ + SC16IS7XX_EFR_AUTOCTS_BIT | \ + SC16IS7XX_EFR_XOFF2_DETECT_BIT | \ + SC16IS7XX_EFR_SWFLOW3_BIT | \ + SC16IS7XX_EFR_SWFLOW2_BIT | \ + SC16IS7XX_EFR_SWFLOW1_BIT | \ + SC16IS7XX_EFR_SWFLOW0_BIT) + /* Misc definitions */ #define SC16IS7XX_FIFO_SIZE (64) @@ -523,8 +531,10 @@ static int sc16is7xx_set_baud(struct uart_port *port, int baud) /* Enable enhanced features */ regcache_cache_bypass(s->regmap, true); - sc16is7xx_port_write(port, SC16IS7XX_EFR_REG, - SC16IS7XX_EFR_ENABLE_BIT); + sc16is7xx_port_update(port, SC16IS7XX_EFR_REG, + SC16IS7XX_EFR_ENABLE_BIT, + SC16IS7XX_EFR_ENABLE_BIT); + regcache_cache_bypass(s->regmap, false); /* Put LCR back to the normal mode */ @@ -935,7 +945,10 @@ static void sc16is7xx_set_termios(struct uart_port *port, if (termios->c_iflag & IXOFF) flow |= SC16IS7XX_EFR_SWFLOW1_BIT; - sc16is7xx_port_write(port, SC16IS7XX_EFR_REG, flow); + sc16is7xx_port_update(port, + SC16IS7XX_EFR_REG, + SC16IS7XX_EFR_FLOWCTRL_BITS, + flow); regcache_cache_bypass(s->regmap, false); /* Update LCR register */ @@ -1010,8 +1023,9 @@ static int sc16is7xx_startup(struct uart_port *port) regcache_cache_bypass(s->regmap, true); /* Enable write access to enhanced features and internal clock div */ - sc16is7xx_port_write(port, SC16IS7XX_EFR_REG, - SC16IS7XX_EFR_ENABLE_BIT); + sc16is7xx_port_update(port, SC16IS7XX_EFR_REG, + SC16IS7XX_EFR_ENABLE_BIT, + SC16IS7XX_EFR_ENABLE_BIT); /* Enable TCR/TLR */ sc16is7xx_port_update(port, SC16IS7XX_MCR_REG, From patchwork Mon Feb 21 10:56:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Mo=C5=84?= X-Patchwork-Id: 544623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FC7CC433EF for ; Mon, 21 Feb 2022 11:16:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355705AbiBULRL (ORCPT ); Mon, 21 Feb 2022 06:17:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356091AbiBULPu (ORCPT ); Mon, 21 Feb 2022 06:15:50 -0500 Received: from eu-smtp-delivery-197.mimecast.com (eu-smtp-delivery-197.mimecast.com [185.58.85.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5BE8D63D9 for ; Mon, 21 Feb 2022 02:56:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=camlingroup.com; s=mimecast20210310; t=1645441013; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tJ7Aqxscf1ebJzYXvq+ijt0vA7p0BjtSmO7gWSOnhyY=; b=Vnki8MeMMFambJgaQwZP1UNuuTex+3iYZ+fxA10abcmOEaKRTEjDUozL/vkTE+CNwiK1hp OCj6mx4M3D/M+/JGa05ap+jxORfRjDFyLctViVFXjaIie4XTJU0t95irgkA7FKDFdGlOLN oHa7PxemIz/kkxtAst9lcBZHOc0IVa0= Received: from GBR01-LO2-obe.outbound.protection.outlook.com (mail-lo2gbr01lp2057.outbound.protection.outlook.com [104.47.21.57]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id uk-mta-186-sFZuGmm8PL-ZXRndpeuHEA-1; Mon, 21 Feb 2022 10:56:52 +0000 X-MC-Unique: sFZuGmm8PL-ZXRndpeuHEA-1 Received: from CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:16b::6) by CWLP123MB6574.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:184::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.24; Mon, 21 Feb 2022 10:56:51 +0000 Received: from CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM ([fe80::6dad:8602:45c5:6747]) by CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM ([fe80::6dad:8602:45c5:6747%8]) with mapi id 15.20.4995.027; Mon, 21 Feb 2022 10:56:51 +0000 From: =?utf-8?q?Tomasz_Mo=C5=84?= To: linux-serial@vger.kernel.org CC: Phil Elwell , Daniel Mack , Jiri Slaby , Greg Kroah-Hartman , =?utf-8?q?Krzysztof_Drobi?= =?utf-8?q?=C5=84ski?= , Lech Perczak , =?utf-8?q?Tomasz_Mo=C5=84?= Subject: [PATCH 3/6] sc16is7xx: Separate GPIOs from modem control lines Date: Mon, 21 Feb 2022 11:56:15 +0100 Message-ID: <20220221105618.3503470-4-tomasz.mon@camlingroup.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220221105618.3503470-1-tomasz.mon@camlingroup.com> References: <20220221105618.3503470-1-tomasz.mon@camlingroup.com> X-ClientProxiedBy: LO4P123CA0469.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a8::6) To CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:16b::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60fd1645-435e-4044-5e4b-08d9f528dd4c X-MS-TrafficTypeDiagnostic: CWLP123MB6574:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: rr2iFqG0UF3t09ydxNLYHnc8KaRIiA3WBuzkysnPU20DtEYpaG6gm3T6Q9tKR0aJeLZbTsru9kHSkReK9I1g2qtNmlxMFuJCHeFIMEdJh2lDizZZo5OQbpn4KqCKzKmSPzWJbbH56pp5YeSBy6yki0oWL3u/nveVuzNDQXY28JBmiEwH13SYAwQ7ft84rTvYy1EszU9mNrZIYzc7Vl4IojWCoUW4/+COvMVndo3/SmiWwkjuotFYfRDoeVXy4cNCsEr6GScWDTV1xzhFlNTz2LXDq8DRN2lN4dpaaJKaiPn6BXcM4gZ57tKiDpP6aRAr3wj7MThaPluMp3R7F9ANBJ+FuYUHAqpmv+O9BLO8BUdkZON6ZWwozONyohyPQ75U/+LnvYc+viHaEUyTI7hFqPD+e3TMED9qFNdpEfzfhmueyca/vMh75KEOrJC09C41QlVpV0sr/onIOUaGk2+juzF0YwwT5uPzdV7KXoIfJoZVhckBMmn9eRcXqVt7gh5+Z3kod7dJ1jFQllLlCYrl+C6JMfEdUd+SvPGBQIHkCVorHkvrxOyghZZgRP/TlhSQUvxOCN/Es+Kswbda0gjbDUPQ/5Pp3Rb1NqjbaEUsxH7csb7kFx4emHDlkyfwIOL4IVTVFdBalqOra2B6E9kCyWVQTmvT/DB1v0b7N3cJkRCJ9k5jk2Kkh+NBfnUz70s8gpYb/L70ItbodvF9En3W3g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230001)(366004)(107886003)(52116002)(6666004)(6512007)(6506007)(5660300002)(508600001)(8936002)(38350700002)(38100700002)(36756003)(2906002)(86362001)(4326008)(8676002)(6486002)(54906003)(2616005)(83380400001)(66946007)(66556008)(66476007)(6916009)(316002)(26005)(186003)(1076003); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TJK1GncvJ6///JgcT5QN6DcrwCVgOVQX/tLeua9otO6OQNVTmKf1J2WBZOwnVZifQKiIJPI1Hdpcd2/iFtJpQ8KjBrgOpn8q4DqdYQBy1rNy1x39uq12BYKb254KbjOiI5659eN80TfBoMVltz3Fg23w6xFp1GJ5kdW4gMs0bFfb+k+2fsvTi/EhQ6HrTdlj3XQULVjtngtbiOiJtx4Uf+DsZCKfIUtC35EzTCg3gq4iZUxE2LtKqpgINKlnQ/bcmMmSoJw7Cq4RRefP8GilIqCBJSPzATO1amWY/e792NEjYPZcr4l4vDSM54aQYn3oE6H67mVHqYmnhmqgnU4qJ8BJ88fE7rxSUpj9Ht0Ck02iRaZvEBzi/TxBeBNsMicH8ePqoike/R3o8JE6hb7CDoQWlpAg3t1WbSSNIA854EkyVnp7LDfOls9dXbDooriv0xHJXxvOilblzySBMZNgJDImcW1N12QylYotN3D2LaHoovq/+saZ/qG0UdQCURDv4J+Fc/7J3qwhaDkoyFJp0fbyGBX54lRmm8OceT9KRBc06uIs7fUmdiPx6qA1R2ugJdajecMe8B4xxk/gi3V7ajfMLThRtTUDmKl2ItsHLrHPfbJugau3ORPQOsb4VaGzNbztW5+AJ5VnKW5saepWj2A309EwMXoYnod0HEIPC1WzTGC5N8pujLtkiJ9stAiYggkLowc6PZeIv132wVXhd+K3krggtnxwODOrUnCL1RadN1GSY1W503cKl90v/7LE+x9rAHmInf2Jcjp0CEhVXwg2ePuW5f9KjORvAT1haw5wbJZRkNfksnax355lp2XJrPqU2ktmAZGocPJlftjOh6cBjBO2iYSzJ0bQ5FjK9jRlNbv3Nl3EWc1RrBTLrgTzt3JLClauL5NCWrOGBMo4yuVmwzpUNT/kfij1S1nUHf9sLycUi1OxyHZCb/aUnjnBsKijqcmLwu9VW3u/ikFsWoZLd/GObCN75uRg6CJJWBnHRzD0cMVolgDihIsmiyJEVhouWp8rQVuir9nHfE5uj/x1xTgqyaUmFvWldrMhJT6B0RuApKA5DmLfvjOFITemerzSOuoyewJaasA1fHEUivyve3M0OC0Sc/tpiE3FDFN6jLcY+d8Wzba5dB+/o3Np45wZWspWlrH7X3NubtGXj/8ZlclsO8mBcxCwoFl6i0Z5rI2nMTgZ8S9g+aJYt4qFJ5veldKPEOkaEcL5B7apN7x4v1Khb8voRbY5FsofFmx/4C6jTXW1Epaj5nShm7q32JbkVEUfy4C+VOjrKJgAyr7rDyaC3e/FfvuCaEQMh4VeIEi9rnD/80G/NxSdrPzhxF65LQ1ahjbA/oAqZO/KEq2LYcz4PGuLqDdFT2FRFmXfL0D6w49DWyKlzLM4xF+6pOtx7B2owUoAx6pSCYOiUyi3Yv2zuZ+IGnSl0P7kiQwE5i/lLEMxRZcgYGiRjD1lT2UYCUlCJVZ4o9yM7Jt3Ji2DCld0a+TZbDnNnlOyPJE4DDAIgphyxFH/BElpXWATEWEjmzaMkCp67K6BfnQZo2mOB/AKy6tWws4UuOuftCuKfa2a9oxWRDfnVuXLVLLck/5UZ2KhCQC0BuwDesTegrSKVk+Jm1R7I/2SOGhzJLyjFMzW+EGVJDaIEUqxZ9SjkdGmqCHqA4WwOo8CsiLiFRHfSw/G/3NBfhhZO7O9QaY= X-OriginatorOrg: camlingroup.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60fd1645-435e-4044-5e4b-08d9f528dd4c X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Feb 2022 10:56:51.1152 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fd4b1729-b18d-46d2-9ba0-2717b852b252 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Nt5OXJoL67/Mn7UEBicdgL/C7lYafyQ8FOTHsYdhDfeA5hxlRn8s35M7+zvAaeQpgnnMxz4TONnaZ33oxjcPs56QoN7SUr7z1h47+IRkMSU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP123MB6574 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUK97A341 smtp.mailfrom=tomasz.mon@camlingroup.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: camlingroup.com Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org From: Lech Perczak Export only the GPIOs that are not shared with hardware modem control lines. Introduce new device parameter indicating whether modem control lines are available. Signed-off-by: Lech Perczak Signed-off-by: Tomasz Moń --- drivers/tty/serial/sc16is7xx.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index c62531b2efe2..21ae2c0b7bbe 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -306,6 +306,7 @@ struct sc16is7xx_devtype { char name[10]; int nr_gpio; int nr_uart; + int has_mctrl; }; #define SC16IS7XX_RECONF_MD (1 << 0) @@ -440,30 +441,35 @@ static const struct sc16is7xx_devtype sc16is74x_devtype = { .name = "SC16IS74X", .nr_gpio = 0, .nr_uart = 1, + .has_mctrl = 0, }; static const struct sc16is7xx_devtype sc16is750_devtype = { .name = "SC16IS750", - .nr_gpio = 8, + .nr_gpio = 4, .nr_uart = 1, + .has_mctrl = 1, }; static const struct sc16is7xx_devtype sc16is752_devtype = { .name = "SC16IS752", - .nr_gpio = 8, + .nr_gpio = 0, .nr_uart = 2, + .has_mctrl = 1, }; static const struct sc16is7xx_devtype sc16is760_devtype = { .name = "SC16IS760", - .nr_gpio = 8, + .nr_gpio = 4, .nr_uart = 1, + .has_mctrl = 1, }; static const struct sc16is7xx_devtype sc16is762_devtype = { .name = "SC16IS762", - .nr_gpio = 8, + .nr_gpio = 0, .nr_uart = 2, + .has_mctrl = 1, }; static bool sc16is7xx_regmap_volatile(struct device *dev, unsigned int reg) From patchwork Mon Feb 21 10:56:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomasz_Mo=C5=84?= X-Patchwork-Id: 544621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFD38C433F5 for ; Mon, 21 Feb 2022 11:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355778AbiBULRT (ORCPT ); Mon, 21 Feb 2022 06:17:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356099AbiBULPv (ORCPT ); Mon, 21 Feb 2022 06:15:51 -0500 Received: from eu-smtp-delivery-197.mimecast.com (eu-smtp-delivery-197.mimecast.com [185.58.85.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E2C3B63E4 for ; Mon, 21 Feb 2022 02:56:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=camlingroup.com; s=mimecast20210310; t=1645441016; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9IN5E8svo2s9/jUURPs22fmQ6amy9o1Ey56PjI/awko=; b=ILFObbSPrLnDVEpPqIcjtiX3zy1tsruyADnD1Z0SxrjH2x9f5Uqa5j49elq8vUapWQCbd2 ZZmPbPnKsXBcP2+hoXwNrMtEE5AK6fiPkVJ1O0suGTNLcQ3Oqi7/hbnwn26hQI23mW8mSL +rWMhv2LRA3OQUz1VHm2aD/fsYC4FRo= Received: from GBR01-LO2-obe.outbound.protection.outlook.com (mail-lo2gbr01lp2057.outbound.protection.outlook.com [104.47.21.57]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id uk-mta-186-6sEc884mMz64zYl4nT9zAg-4; Mon, 21 Feb 2022 10:56:55 +0000 X-MC-Unique: 6sEc884mMz64zYl4nT9zAg-4 Received: from CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:16b::6) by CWLP123MB6574.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:184::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.24; Mon, 21 Feb 2022 10:56:52 +0000 Received: from CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM ([fe80::6dad:8602:45c5:6747]) by CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM ([fe80::6dad:8602:45c5:6747%8]) with mapi id 15.20.4995.027; Mon, 21 Feb 2022 10:56:52 +0000 From: =?utf-8?q?Tomasz_Mo=C5=84?= To: linux-serial@vger.kernel.org CC: Phil Elwell , Daniel Mack , Jiri Slaby , Greg Kroah-Hartman , =?utf-8?q?Krzysztof_Drobi?= =?utf-8?q?=C5=84ski?= , Lech Perczak , =?utf-8?q?Tomasz_Mo=C5=84?= Subject: [PATCH 5/6] sc16is7xx: Handle modem status lines Date: Mon, 21 Feb 2022 11:56:17 +0100 Message-ID: <20220221105618.3503470-6-tomasz.mon@camlingroup.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220221105618.3503470-1-tomasz.mon@camlingroup.com> References: <20220221105618.3503470-1-tomasz.mon@camlingroup.com> X-ClientProxiedBy: LO4P123CA0469.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a8::6) To CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM (2603:10a6:400:16b::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 36dc41ba-a9cc-4787-d5b4-08d9f528de0f X-MS-TrafficTypeDiagnostic: CWLP123MB6574:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: 2bh9EqyvekNanNcJfwx9CIGSqwR3yVirHojSPjMVOBl4c0vioU8lGaOdYxcZm5JltlJkyLeXOhabJOPSTlnLDcmbC/Y42H4YbiSo2jn4wAnkUVzfT1vmea7K0FoXMmCg635xmb/+11ffvFouTKvHNvSxy2cbHiAhzO7Mtt2uOof1u3ctOjHRMm0QlTc1+fJLVIUUXEY7/Jjyht4hXYLCnggdEM5xqiUXXMCDbTw8jHdmloG4ND8rpcjfpwSL/JUl8USMwAwYxJ/atpWvVqZ78fL08jje2UtI0R/puGfJGk0WtfUuO4RM8z8GMe5ivp3M7BqW//V1SJwuTXpXo90LmpMJ16JGyBiKbmk9NXSCd11JJknC/dpzq7euZGr6O1HsWYfNKyLyP2MMeca8UdBG+L3PrgZXDcQcwCsE/qUxMUHMYBONXM1LxgBiwo53gYb0vYVStRZAInX8hbhyCr/jHZ+AiVK8AgL5InjdmVWa5m7xUJoh7X6QfVZnq7M4IvuQK5i7cGGikN8GV7ZPSVKqz5emgbKzJnKch+g3s+0afrXJZ0i272MMTE7RWObNfBVKUdl/Gj9SR6F68WyHT4Z6eqUyS0K5xppYG31aXGTb8c0kjoAVeKdF58UDKxgF97fTBBVyWHr9WdRRvCRh95YxQXGv9LGGSg5xr9wiaR+63+bswB9loVZLjK7Muu39EolQVXAQTNiAm51LCvi7iVX/pZq/Mpf2b1fNdsNCkBeOupk= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230001)(366004)(107886003)(52116002)(6666004)(6512007)(6506007)(5660300002)(508600001)(8936002)(38350700002)(38100700002)(36756003)(2906002)(86362001)(4326008)(8676002)(6486002)(54906003)(2616005)(83380400001)(66946007)(66556008)(66476007)(6916009)(316002)(26005)(186003)(1076003)(326664003); DIR:OUT; SFP:1101 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wtT1dFveJpcfsrPt87n0uSij8LgZsgrtoX5dXScQuyggM2DiktZBADYDMDteLdlDUdgDfkPeenR+eeGvceaczywLcqBA5QWRkgkqKgmV9TeokrEsc76nx3ZZcLtQdx83MnvLy7qo5ZPIdDV18KcZtnapEFWDfa79744CrmTXvJZseJXHzSYED/YBiIxV2PHJ2pp0J5AG5NJ91fPafmBpVpHmP+BzrKPGYsvjr9U4v8GYiYT9FxXUIugynPoA33HIqbrgqQ6tdJTsXPHRnTn68YM3u1tjdv8DlEH7+Nk3Adp1dS08T2B3jVCOtWcAaBQ/U/wCRhVcol5yC3QYjDpLsQaFR2PgI73VnsBP0XPoXdmhpsZvKMXPcoYjOsn32k9uzIlMy+UydgvyaaG/RFZGnBDIMK2ujgJ2ROst1+Inq6wog3uuC/Yzy09liJ5E+72J5KgbV9vyDqlK94wKuScSEx2sdGuBd+m+FIud44RHbbbF4HEaei1vOK91iV8VU/tbFCKEvOYMDdagLcjannqoPyKOVi6vV6LzmXNhejAuLII/9QpgwzvfNgRor6/Tsd7LMFgH1EIl2D/t/1AEFQDDxXFd4LoUdALDUcLzKBeqlG25k1iavMddFuJRyfpJARuvnOU47Ws/HERxUvuQQR2SAT7EQ1Ky6TJNwb9CHuLMOHFRzSKgtrqsJ3tSTR/nzIDzFRri9tmMm7yjIF0SeMX7wv/kwMK74ajPGHKf2FRNcarC2+qkwmqhjFiFivQtwL3Jo+T1gfXq1DKOzHK4fjCH3/gEGyEEWoF2f/ceqCJhmzXzW8p6xsNehlxa9stuO885N+3W1j31k75q6P9042Jl5loL/Q2JWHXzOIO6wgTpIs1nY7lToVnqfgpz8M/93cltVR8KVR+1mWLNBzv1teY8xxO9hg48HB5IZSzvaBQeJ5kijZ/r7nxAyEETTqoSdioItUcAzgR9x7Tdc+evS6/A/gs9lyA6b/aF5O3R13sxtEH6Gwm+sjiUOoO/hm43tgCA5dhOeWXgoNNz+4PZjVtcc5U0jbRJc1jtS9cBmt/oL9WiaALp9Dx7+f+FisyVoSXmyuaSjg1gj1yVzzeq/IQBMLPXk777CqJ6V88jP14vu5Np0Mj7YoyLjmPmfkTWau5HdojNFCOf72EPmhIo5MMtDkMY0sYQkdBu7s8J1HucpUrRx3oK0H+Du/16ezyMytpOzhwzznJVCi+FsJNQF8HSZ0E74m8iNGFErsrc0SMvvAFj68h0F/yAN5fJ1K+dxKleBU3xWpW8eByjqPoix1UYyGQvLtpUWbhsFSGF6uVYbRjh5cgCCE0Ui9BIek7lghXekG9ViSgYw1nGolVM0Kh8q4Utm3p7AOqPuAKIWMbVLQNjavdmqFhZmnIMXPQOc0oxeWmS+b7NTgUOpQmIDdHWbcHwSa+xu+qKDXGyevRwkqHyWqmjfZeqeHONGOuEOZEk9H/d5J9GXELpxg8mxsJJS/9ry5hLpWxbZd5GVl919l+zY4/mOVLlP8l2UGOtffCzRZaU2SqXZDyI1+C2lKYNlWc4AU0Uq/X3tROtGJSFXGTeZsoxx/W+W8AvouV+d3M41drYf0jZw6OlGx+CKlmdBBc2Qe7NIBxL1F37ylHS1OFMf7LTsAD+6WfubQTTcz4Epl3QDqj/ttJ5BS8cEsACQuQZHnasNQp/9FHGY/uj2XQ= X-OriginatorOrg: camlingroup.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36dc41ba-a9cc-4787-d5b4-08d9f528de0f X-MS-Exchange-CrossTenant-AuthSource: CWLP123MB5572.GBRP123.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Feb 2022 10:56:52.3818 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fd4b1729-b18d-46d2-9ba0-2717b852b252 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: peg+jPE7WDyscpk0wSPMfMs3bmvrmskzbEU13ezSX5bar2GxTdHRfmgKYJwY487mfWaBnEDNKOEiDLN2hKoWwNJSD6RpHiL4ike/tK6rrbo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP123MB6574 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUK97A341 smtp.mailfrom=tomasz.mon@camlingroup.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: camlingroup.com Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org The uart_handle_cts_change() and uart_handle_dcd_change() must be called with port lock being held. Acquire the lock after reading MSR register. Do not acquire spin lock when reading MSR register because I2C/SPI port functions cannot be called with spinlocks held. Update rng and dsr counters. Wake up delta_msr_wait to allow tty notice modem status change. Co-developed-by: Lech Perczak Signed-off-by: Lech Perczak Co-developed-by: Tomasz Moń Signed-off-by: Tomasz Moń --- drivers/tty/serial/sc16is7xx.c | 120 +++++++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 17e79af36604..5c247b4a01a9 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -324,8 +324,10 @@ struct sc16is7xx_one { u8 line; struct kthread_work tx_work; struct kthread_work reg_work; + struct kthread_delayed_work ms_work; struct sc16is7xx_one_config config; bool irda_mode; + unsigned int old_mctrl; }; struct sc16is7xx_port { @@ -705,12 +707,56 @@ static void sc16is7xx_handle_tx(struct uart_port *port) spin_unlock_irqrestore(&port->lock, flags); } +static unsigned int sc16is7xx_get_hwmctrl(struct uart_port *port) +{ + u8 msr = sc16is7xx_port_read(port, SC16IS7XX_MSR_REG); + unsigned int mctrl = 0; + + mctrl |= (msr & SC16IS7XX_MSR_CTS_BIT) ? TIOCM_CTS : 0; + mctrl |= (msr & SC16IS7XX_MSR_DSR_BIT) ? TIOCM_DSR : 0; + mctrl |= (msr & SC16IS7XX_MSR_CD_BIT) ? TIOCM_CAR : 0; + mctrl |= (msr & SC16IS7XX_MSR_RI_BIT) ? TIOCM_RNG : 0; + return mctrl; +} + +static void sc16is7xx_update_mlines(struct sc16is7xx_one *one) +{ + struct uart_port *port = &one->port; + struct sc16is7xx_port *s = dev_get_drvdata(port->dev); + unsigned long flags; + unsigned int status, changed; + + lockdep_assert_held_once(&s->efr_lock); + + status = sc16is7xx_get_hwmctrl(port); + changed = status ^ one->old_mctrl; + + if (changed == 0) + return; + + one->old_mctrl = status; + + spin_lock_irqsave(&port->lock, flags); + if ((changed & TIOCM_RNG) && (status & TIOCM_RNG)) + port->icount.rng++; + if (changed & TIOCM_DSR) + port->icount.dsr++; + if (changed & TIOCM_CAR) + uart_handle_dcd_change(port, status & TIOCM_CAR); + if (changed & TIOCM_CTS) + uart_handle_cts_change(port, status & TIOCM_CTS); + + wake_up_interruptible(&port->state->port.delta_msr_wait); + spin_unlock_irqrestore(&port->lock, flags); +} + static bool sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno) { struct uart_port *port = &s->p[portno].port; do { unsigned int iir, rxlen; + struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); iir = sc16is7xx_port_read(port, SC16IS7XX_IIR_REG); if (iir & SC16IS7XX_IIR_NO_INT_BIT) @@ -727,6 +773,11 @@ static bool sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno) if (rxlen) sc16is7xx_handle_rx(port, rxlen, iir); break; + /* CTSRTS interrupt comes only when CTS goes inactive */ + case SC16IS7XX_IIR_CTSRTS_SRC: + case SC16IS7XX_IIR_MSI_SRC: + sc16is7xx_update_mlines(one); + break; case SC16IS7XX_IIR_THRI_SRC: sc16is7xx_handle_tx(port); break; @@ -874,6 +925,30 @@ static void sc16is7xx_stop_rx(struct uart_port *port) sc16is7xx_ier_clear(port, SC16IS7XX_IER_RDI_BIT); } +static void sc16is7xx_ms_proc(struct kthread_work *ws) +{ + struct sc16is7xx_one *one = to_sc16is7xx_one(ws, ms_work.work); + struct sc16is7xx_port *s = dev_get_drvdata(one->port.dev); + + if (one->port.state) { + mutex_lock(&s->efr_lock); + sc16is7xx_update_mlines(one); + mutex_unlock(&s->efr_lock); + + kthread_queue_delayed_work(&s->kworker, &one->ms_work, HZ); + } +} + +static void sc16is7xx_enable_ms(struct uart_port *port) +{ + struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); + struct sc16is7xx_port *s = dev_get_drvdata(port->dev); + + lockdep_assert_held_once(&port->lock); + + kthread_queue_delayed_work(&s->kworker, &one->ms_work, 0); +} + static void sc16is7xx_start_tx(struct uart_port *port) { struct sc16is7xx_port *s = dev_get_drvdata(port->dev); @@ -893,10 +968,10 @@ static unsigned int sc16is7xx_tx_empty(struct uart_port *port) static unsigned int sc16is7xx_get_mctrl(struct uart_port *port) { - /* DCD and DSR are not wired and CTS/RTS is handled automatically - * so just indicate DSR and CAR asserted - */ - return TIOCM_DSR | TIOCM_CAR; + struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); + + /* Called with port lock taken so we can only return cached value */ + return one->old_mctrl; } static void sc16is7xx_set_mctrl(struct uart_port *port, unsigned int mctrl) @@ -920,8 +995,12 @@ static void sc16is7xx_set_termios(struct uart_port *port, struct ktermios *old) { struct sc16is7xx_port *s = dev_get_drvdata(port->dev); + struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); unsigned int lcr, flow = 0; int baud; + unsigned long flags; + + kthread_cancel_delayed_work_sync(&one->ms_work); /* Mask termios capabilities we don't support */ termios->c_cflag &= ~CMSPAR; @@ -1010,8 +1089,15 @@ static void sc16is7xx_set_termios(struct uart_port *port, /* Setup baudrate generator */ baud = sc16is7xx_set_baud(port, baud); + spin_lock_irqsave(&port->lock, flags); + /* Update timeout according to new baud rate */ uart_update_timeout(port, termios->c_cflag, baud); + + if (UART_ENABLE_MS(port, termios->c_cflag)) + sc16is7xx_enable_ms(port); + + spin_unlock_irqrestore(&port->lock, flags); } static int sc16is7xx_config_rs485(struct uart_port *port, @@ -1052,6 +1138,7 @@ static int sc16is7xx_startup(struct uart_port *port) struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); struct sc16is7xx_port *s = dev_get_drvdata(port->dev); unsigned int val; + unsigned long flags; sc16is7xx_power(port, 1); @@ -1102,16 +1189,25 @@ static int sc16is7xx_startup(struct uart_port *port) SC16IS7XX_EFCR_TXDISABLE_BIT, 0); - /* Enable RX interrupt */ - val = SC16IS7XX_IER_RDI_BIT; + /* Enable RX, CTS change and modem lines interrupts */ + val = SC16IS7XX_IER_RDI_BIT | SC16IS7XX_IER_CTSI_BIT | + SC16IS7XX_IER_MSI_BIT; sc16is7xx_port_write(port, SC16IS7XX_IER_REG, val); + /* Enable modem status polling */ + spin_lock_irqsave(&port->lock, flags); + sc16is7xx_enable_ms(port); + spin_unlock_irqrestore(&port->lock, flags); + return 0; } static void sc16is7xx_shutdown(struct uart_port *port) { struct sc16is7xx_port *s = dev_get_drvdata(port->dev); + struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); + + kthread_cancel_delayed_work_sync(&one->ms_work); /* Disable all interrupts */ sc16is7xx_port_write(port, SC16IS7XX_IER_REG, 0); @@ -1175,6 +1271,7 @@ static const struct uart_ops sc16is7xx_ops = { .stop_tx = sc16is7xx_stop_tx, .start_tx = sc16is7xx_start_tx, .stop_rx = sc16is7xx_stop_rx, + .enable_ms = sc16is7xx_enable_ms, .break_ctl = sc16is7xx_break_ctl, .startup = sc16is7xx_startup, .shutdown = sc16is7xx_shutdown, @@ -1341,7 +1438,9 @@ static int sc16is7xx_probe(struct device *dev, s->p[i].port.uartclk = freq; s->p[i].port.rs485_config = sc16is7xx_config_rs485; s->p[i].port.ops = &sc16is7xx_ops; + s->p[i].old_mctrl = 0; s->p[i].port.line = sc16is7xx_alloc_line(); + if (s->p[i].port.line >= SC16IS7XX_MAX_DEVS) { ret = -ENOMEM; goto out_ports; @@ -1353,9 +1452,17 @@ static int sc16is7xx_probe(struct device *dev, sc16is7xx_port_write(&s->p[i].port, SC16IS7XX_EFCR_REG, SC16IS7XX_EFCR_RXDISABLE_BIT | SC16IS7XX_EFCR_TXDISABLE_BIT); + + /* Use GPIO lines as modem status registers */ + if (devtype->has_mctrl) + sc16is7xx_port_write(&s->p[i].port, + SC16IS7XX_IOCONTROL_REG, + SC16IS7XX_IOCONTROL_MODEM_BIT); + /* Initialize kthread work structs */ kthread_init_work(&s->p[i].tx_work, sc16is7xx_tx_proc); kthread_init_work(&s->p[i].reg_work, sc16is7xx_reg_proc); + kthread_init_delayed_work(&s->p[i].ms_work, sc16is7xx_ms_proc); /* Register port */ uart_add_one_port(&sc16is7xx_uart, &s->p[i].port); @@ -1439,6 +1546,7 @@ static void sc16is7xx_remove(struct device *dev) #endif for (i = 0; i < s->devtype->nr_uart; i++) { + kthread_cancel_delayed_work_sync(&s->p[i].ms_work); uart_remove_one_port(&sc16is7xx_uart, &s->p[i].port); clear_bit(s->p[i].port.line, &sc16is7xx_lines); sc16is7xx_power(&s->p[i].port, 0);