From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8211AC32771 for ; Wed, 21 Sep 2022 11:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-ID:In-Reply-To: References:Message-ID:Date:Subject:CC:To:From:Reply-To:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IIJcRMefhfTkWQYmyNKmK4xjXZRIJ6lMP/ZB/Uy2Ock=; b=YDmvjDE+18JQaA JpHhnG640Wt8rEMr5uXh4xzlUWwR2P7FT11Q/OofT7jw059/qd9jNQx0rQ/K3ythWvWwMLD8NAMzF ICZF/dgHaKUhsK+4yKNdedKuaaPcl8+1D1+XzVqk5e4qerjSyf26PPArkAax46Q10BwlpJLlk/h2a 5H2e7lXvXHtXg9pv/GACigWLz1T52e2iGTDpvZEK7EHTPpFvL6YzOfHwcTlB3ts62N3bTQPtjCT0u JF+lDsw4u5iVmFZsWQxjGrOve3cl++wZkpIK5tc18KKnU+/vD1fGvgBiEOM7KB9ut2UoU+9OHTjOu 9jA60hxT3FfWMZ/3NECQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oayEi-00BBPH-3k; Wed, 21 Sep 2022 11:49:52 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oayEd-00BBLe-Mi for linux-arm-kernel@lists.infradead.org; Wed, 21 Sep 2022 11:49:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1663760987; x=1695296987; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=nzNYvcOAd+V2bxmKPLaPpyS3vQWjlJkynrLAsFXAJiQ=; b=Qna7o5QEpC5xtWWhUgd3oBniUrEqajqnsosXLwz1PoSUiR7dk4p8teX3 tTb0R/H7Cyh0jNDFr7mLTm0DkTIzEgVmjVdAgFtiDVL7ISrzQmxNtEpb6 8ipHxEqX0DIxZUOA3RrDi0Olyrd6/wyU6fyCn8VLIRJLhjTZwPzXKPrCd vQGISeUQMkuMa1ZC3GpdO3UEs9FwHBGAgg6RnxssWzOJx1b5L4xLKRySs ikdSavIizD58Fus24/CIYeGlaXKMXGTJ62sB0M9LuBjTssn3K+aXEixBN xJSrDFnrn5RX+00Ue5305xdmM/x1xDgj+Wtll3Zp5ITzg4rur301Yj4Nw w==; X-IronPort-AV: E=Sophos;i="5.93,333,1654585200"; d="scan'208";a="191798026" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Sep 2022 04:49:41 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Wed, 21 Sep 2022 04:49:41 -0700 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12 via Frontend Transport; Wed, 21 Sep 2022 04:49:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HvciedJRxOnBB5ttQSk4NEkEmjUMlktWobWWYDJ1FR/Wecy9/4p6XSzeni1ef3J+9+2BiyYKWMiKMfI3HTTIjmVx4kwGOXVzitEJ2Xdkt0TlNcv3GEEQ4IJwAHYUFWPUcyML4kLO5AxLBlGtpZA+NAivc92dzKHCjKt45kN5VtHbfFB54Ifmo+c0FZFnK4gguDFll06oAa8O6zVvg8LJc6GW7NTpRtpk5Io+i4hOWr1kJuO5R1gQymQeLue6UJ/f9WW5Irr1f+eMi445ta28WzhKZfrgc+6aLo8Z+UXBw5Ts/nlTNMm9y/eYTqFR3N1xdk58e5H9id8wg53GqAHuJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nzNYvcOAd+V2bxmKPLaPpyS3vQWjlJkynrLAsFXAJiQ=; b=l4xgbgR7c90Awzhrk1dy2T04Nr3PBtB3zhePoixLOhMoYmsWo/WM0G4Bc1uxDrp0WxYhoe0YH4PuuaD62n1dkUKAA2oEpWXfj38QK1NYXVwAoxKS8f5izOlYtlzF2UINIiQFNQurM4HKqBH2BEShd5gCuJ6HUovAR2BHvVdMY+E5/689Aa4JwUYrDMOcw46KNjUv+FdPzMniHJi6OHgK559xPydQIUEZVvQEP+u3yl6abYJUkK1A7diAXY3WLltF6rynk33BIxsLYlbBAkzCtoMhYAU+MzK33zh8zricC9/XwKADFiBuhGQlKopNIAbrIHCvsF6hJpQvqYfqu2hDWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector2-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nzNYvcOAd+V2bxmKPLaPpyS3vQWjlJkynrLAsFXAJiQ=; b=pmzb9GEL1U9HXIXkgNjOkUSATsNMN4NkRlMY2pnHs0ueraYxqJ89XpQAe/Ath9LoRdZwp/8qNLSnhxVXp9zJ/rvqT56P/IXkTAu8VKkDLyk4NveikWIxNF8KIL378QORVd2GSulhdC2u9xgytRA+yscYCm4zE5go5kFU7EXFdCE= Received: from BYAPR11MB2758.namprd11.prod.outlook.com (2603:10b6:a02:c9::11) by CH0PR11MB5332.namprd11.prod.outlook.com (2603:10b6:610:bf::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.16; Wed, 21 Sep 2022 11:49:34 +0000 Received: from BYAPR11MB2758.namprd11.prod.outlook.com ([fe80::2cfd:fc73:ba36:ae64]) by BYAPR11MB2758.namprd11.prod.outlook.com ([fe80::2cfd:fc73:ba36:ae64%4]) with mapi id 15.20.5654.016; Wed, 21 Sep 2022 11:49:33 +0000 From: To: , , , , , , , , , , CC: , , , , Subject: Re: [PATCH v4 9/9] tty: serial: atmel: Make the driver aware of the existence of GCLK Thread-Topic: [PATCH v4 9/9] tty: serial: atmel: Make the driver aware of the existence of GCLK Thread-Index: AQHYzDqe0wl2uU+iSEmCXg4v70M/fK3pY9qAgAAKDACAAFoUAA== Date: Wed, 21 Sep 2022 11:49:33 +0000 Message-ID: References: <20220919150846.1148783-1-sergiu.moga@microchip.com> <20220919150846.1148783-10-sergiu.moga@microchip.com> <342f5733-25df-9409-2a15-47b3f801a4a7@microchip.com> <2894e7db-78b1-59ee-ad5f-e45c8597e9cf@microchip.com> In-Reply-To: <2894e7db-78b1-59ee-ad5f-e45c8597e9cf@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microchip.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BYAPR11MB2758:EE_|CH0PR11MB5332:EE_ x-ms-office365-filtering-correlation-id: bc4d4426-e714-40a1-ecaa-08da9bc75a12 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 92abCt3Sh3ShmOzd9Cgt3M7tT4F4Xj4F+xhsBw2C3S9Lc4v6JkkyQNwV8R6Hz87CSaPGn1DQFBNXrTz1LjlAzobdliGhFHxFta6CLGq+nF9VMM3JhkFkLPBv8wciBkVFE0tczHxfNMY1QLNURPZnvjb1ZyuJGbS7TciJHIji063u1NOou8fd6gKv1BgEOlR/FuZ2DOfx+Auhta3eLhB6KLIkn8EcFIeOtfD46VpJb+m7VQyVE2qAfdK04MHqLT2pY3diDXrzGd6F5BeGmHbYu3L5CssShTImWjn+eyuv1jz3naH7ooRxof8CrW0B8V6rg+PCx+fbpI7ldVIXMCImloJDKFxcFvfojxD7F7+V7ge/iV+t+MeCkPs6cUxkSHNGW3z0VHRJr2XnEhubGbyvx7UuaMpL/UXoZ7lVBrWim5a7RyiZcTqSoKq8FbtCuBdX1p/iEumeOTPJbxn5kalXvmdIvl4uKvtE4c8oELN2RrbPRdupmgBTpM/vUJOrChH2rYJp4uOzK43kU2n8GQxlPeYJMchb5b5NRaNB9Jz0yN9LitDRUDLANkVO8oZFY+IoadqsuHVjgKGFEj0usTOuz0a8WQ0NUlqtJu0DNhqS5Qh7z8865siCruvKfDgZ8TNoWBq3TbTPWM3+v5IUJBw8SrwdMCvxb5uLOxU4EEoLVJFzC4siAMkWhg19UNJmbL6jtuoDm9ILbF0LDwKTf1KkgYkF4hLE7cjVbxkiddsuO66zxgwHKu1eWdKWKK1CPE/iufwTq7tnBxO1JjDioeuzl+kytl/s9BZF8NbomqtUn1E1OhbmeAYduivNmiYEvBAE x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR11MB2758.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(376002)(136003)(346002)(366004)(39860400002)(396003)(451199015)(6506007)(53546011)(83380400001)(41300700001)(186003)(2616005)(36756003)(6512007)(26005)(86362001)(31696002)(31686004)(921005)(38070700005)(38100700002)(122000001)(64756008)(66556008)(66476007)(66946007)(8936002)(66446008)(8676002)(4326008)(91956017)(316002)(5660300002)(7416002)(76116006)(110136005)(54906003)(2906002)(6636002)(6486002)(478600001)(71200400001)(45980500001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?d1poaE5KZ05KT05NaG9PV1lLYnBRUGtLVjFheDBVMVd0WkN6cEtDZ1RJekhR?= =?utf-8?B?NmI0ankyeE1IWElrK3h3V0c5ektnc2s2cXN0eUs1MG5DSkEzQ29PY1V5R0ly?= =?utf-8?B?d3grbmxxYWRkb2pQNzg2RDN5Q2ViYU5QUElaWEh1OW5WSXVXTnJTTXRIVElO?= =?utf-8?B?Y29lS3FORE1KTDlwUEpuV2g3N2o1Nk5IRWdNM0JraWRJZks3VkNpN1Jkc2NN?= =?utf-8?B?aVhaWmNQWHdNQi9jUjl3c1RSMzJaOTA0TUJ6bzJ6QTRmU2tQME14Z3ZtaGVM?= =?utf-8?B?OXNucDNjUGo4OHEzWUFnd0t2TzdHMXdkUy85TE9rbzJDQmowQ2JWTk1ucHBW?= =?utf-8?B?NFZFMDlGQldpeFE2VDlhcG1odVJibUgrWWRjVTNIYjFPemNPZUVNTktxTkI0?= =?utf-8?B?YWgwbGNEZ3oxbmpEeFpiSXFRbGlUWXdGdGc5UWhkMVFsODF4Y3MzY1U4aFdX?= =?utf-8?B?VnZlQlN2UmkzUDZjL1B5WXZJN2ZtWGxTUGNpZnJNNTd3b2ZTU2pPVnRCTGlJ?= =?utf-8?B?Tk1KYnFQSEU5NzdmZjQyZXl2QXpkTExacStvTTBQc1B2MS8xQW85MzRCMXQ0?= =?utf-8?B?dzBTNnZLYjI0M2h0OWZIR1F4TWFUR0hRMjRhaXFNOFpBTDNpZDlncGRqWnEz?= =?utf-8?B?VFUrTjdjQVdTT203WjB0UnFoaTFsZnhkanJkd3JrQVg4MWpUWXNxcUgwdXRj?= =?utf-8?B?c2Npck1ORStWRVZLbnhoMGxEOGdheGhJSzFLb2Jqd1BxZWdYb01DWnhvU3p3?= =?utf-8?B?K2JKOWdsYVZWSmxOT3QxUDZ3ZHpYeldtQzBQY3JxSnlYeWMyZEdxR3M0dDU0?= =?utf-8?B?aTdxeS9sc2g2WkF5VCs5bEZJWjZsRmJOZGlFWVFQRDZqZFhJNmhJSHpvVGg3?= =?utf-8?B?TWphNmNjMWI1OFM3OVZIYUpjWVpjZEFCNy9GY2NadkFialYyVWlrUDQzTnlB?= =?utf-8?B?dGgxT0w1T1dVSG9MTWVFSzRMdFMrZk5wTE9SRy9lTFZ5OUFKaW1YdE5WeUFs?= =?utf-8?B?bFMvUE80Y0xXMDd5N3pDL2FmQU12M3p0Qmc0WjU2OFE1TUZuUkk3ODBzeUl5?= =?utf-8?B?UllvOUVRRU9vUGVXQjEvZXUzcGdTalNoMnF6NFpYQmdCVk1vRGJCdGFUWm11?= =?utf-8?B?YWdUenp5WFFFVmNQcWJQVjZrS082TUNlWXlIRDVUU0ZxN0s2UFpwQ0VCaGd1?= =?utf-8?B?NkNUTWdnODVrZWxwRUo5U2tiaVY4Tmt3VDBCWFZVSk8xWkVid3FOd1M2N3E1?= =?utf-8?B?aHU0eWw0eCt0amltU1E1dmkwZDJLZlZkZHM3RGdNcTkrNGd0M1M2aEFyMkpr?= =?utf-8?B?NEt5bElPQjFUS1J1SGE4MFE1YmRLem9LemxoWEFIMDdVazhRVUJQcXFybnVJ?= =?utf-8?B?UmsyaDRmMEJ6N29KbENUODljMW12YlFrMXg0bHdOSEx6WnNxV0RKSVo4YnFO?= =?utf-8?B?YllDNzdYZXRkRDhjRHltY21yUm1mUEVBV21oeE9WcFhSUWJhZTVhK3Y2SXJL?= =?utf-8?B?OGZaQW5KZFE0aWgrOXBieUpJMkY5akRLVjAvSThla1RwZis2QmdCYlowa0tu?= =?utf-8?B?QnkzYWR0enZNQklMUnRRNXBMWWh2UUM3QUJIc0JRbnVCVCtVam93V2FnejZ1?= =?utf-8?B?ak1Qd3J0cGQ0UUJnUVAzcklHYlRIR0FHWHhTQVQ5bUhzMTZwYVUwcHJ4Z21i?= =?utf-8?B?SU9wdEx4Y3dkTE1PdjZEY2xWVnRjK1pBd3M3QjgyalFDT3JxYXo4MTMyalFJ?= =?utf-8?B?QStiM0V4bzhpMEl4c1IxQm9tQ1AwM0VPbXF6d3hYZno2a3NpRW95Q3dQSS9Z?= =?utf-8?B?MlI1VVZWeEV2Tm5kTTJIR1FVenpGVjAxOUFzM2wrMC9KZGRHMHFlOXFnZ3oy?= =?utf-8?B?aXNJUlRzRkZqRnZ0Q0M2SWx5T1BnY0E1VWw0bVpXOXVrQlBpMWJWakUyQnFn?= =?utf-8?B?RjBwNlZPSktveUl4NXV4aVkrY1JHUnBxd3ZJdDZjS2ZtMG9Wa1dpVHpsVVBW?= =?utf-8?B?Wk1hNkZrenVPT0lKZVhoczI2aURoKzlwaXI2Vk15eDBuTFNDZUc5eXFkaGFq?= =?utf-8?B?OG1WeGFjU3Z1b1hIQjFWTVB1dmpLWi8rWU05alpCM1IzTDV4TkE4dGZMVFcr?= =?utf-8?Q?6uDL3Hlq+qzMVTkPG9151L0rl?= Content-ID: <1DDB29EFD1F81F43BB1BB6B77BA2A274@namprd11.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB2758.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc4d4426-e714-40a1-ecaa-08da9bc75a12 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Sep 2022 11:49:33.8177 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: CpGr7x6fA2pmrw/DVdy8RD/goOariEY4HHiOAsMUlLdn/aMDFyA3ZlAKn5rTk+iCDAG4vzITS6gb+pQxt/WJACxEJ7u0QKkQB3f6vAzHgJc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5332 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220921_044948_072581_4B3119F7 X-CRM114-Status: GOOD ( 21.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 21.09.2022 09:27, Claudiu Beznea - M18063 wrote: > On 21.09.2022 08:51, Claudiu Beznea - M18063 wrote: >> On 19.09.2022 18:08, Sergiu Moga wrote: >>> Previously, the atmel serial driver did not take into account the >>> possibility of using the more customizable generic clock as its >>> baudrate generator. Unless there is a Fractional Part available to >>> increase accuracy, there is a high chance that we may be able to >>> generate a baudrate closer to the desired one by using the GCLK as the >>> clock source. Now, depending on the error rate between >>> the desired baudrate and the actual baudrate, the serial driver will >>> fallback on the generic clock. The generic clock must be provided >>> in the DT node of the serial that may need a more flexible clock source. >>> >>> Signed-off-by: Sergiu Moga >> >> Reviewed-by: Claudiu Beznea > > Actually, I'm taking this back at the moment. > >> >> >>> --- >>> >>> >>> v1 -> v2: >>> - take into account the different placement of the baudrate clock source >>> into the IP's Mode Register (USART vs UART) >>> - don't check for atmel_port->gclk != NULL >>> - use clk_round_rate instead of clk_set_rate + clk_get_rate >>> - remove clk_disable_unprepare from the end of the probe method >>> >>> >>> >>> v2 -> v3: >>> - add the error rate calculation function as an inline function instead of >>> a macro definition >>> - add `gclk_fail` goto >>> - replace `goto err` with `goto err_clk_disable_unprepare;` >>> >>> >>> >>> v3 -> v4: >>> - Nothing, this was previously [PATCH 14] >>> >>> >>> drivers/tty/serial/atmel_serial.c | 59 ++++++++++++++++++++++++++++++- >>> 1 file changed, 58 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c >>> index c983798a4ab2..426f9d4f9a5a 100644 >>> --- a/drivers/tty/serial/atmel_serial.c >>> +++ b/drivers/tty/serial/atmel_serial.c >>> @@ -15,6 +15,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> #include >>> #include >>> #include >>> @@ -110,6 +111,7 @@ struct atmel_uart_char { >>> struct atmel_uart_port { >>> struct uart_port uart; /* uart */ >>> struct clk *clk; /* uart clock */ >>> + struct clk *gclk; /* uart generic clock */ >>> int may_wakeup; /* cached value of device_may_wakeup for times we need to disable it */ >>> u32 backup_imr; /* IMR saved during suspend */ >>> int break_active; /* break being received */ >>> @@ -229,6 +231,11 @@ static inline int atmel_uart_is_half_duplex(struct uart_port *port) >>> (port->iso7816.flags & SER_ISO7816_ENABLED); >>> } >>> >>> +static inline int atmel_error_rate(int desired_value, int actual_value) >>> +{ >>> + return 100 - (desired_value * 100) / actual_value; >>> +} >>> + >>> #ifdef CONFIG_SERIAL_ATMEL_PDC >>> static bool atmel_use_pdc_rx(struct uart_port *port) >>> { >>> @@ -2117,6 +2124,8 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state, >>> * This is called on uart_close() or a suspend event. >>> */ >>> clk_disable_unprepare(atmel_port->clk); >>> + if (__clk_is_enabled(atmel_port->gclk)) >>> + clk_disable_unprepare(atmel_port->gclk); >>> break; >>> default: >>> dev_err(port->dev, "atmel_serial: unknown pm %d\n", state); >>> @@ -2132,7 +2141,9 @@ static void atmel_set_termios(struct uart_port *port, >>> { >>> struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); >>> unsigned long flags; >>> - unsigned int old_mode, mode, imr, quot, baud, div, cd, fp = 0; >>> + unsigned int old_mode, mode, imr, quot, div, cd, fp = 0; >>> + unsigned int baud, actual_baud, gclk_rate; >>> + int ret; >>> >>> /* save the current mode register */ >>> mode = old_mode = atmel_uart_readl(port, ATMEL_US_MR); >>> @@ -2302,6 +2313,46 @@ static void atmel_set_termios(struct uart_port *port, >>> cd = min_t(unsigned int, cd, ATMEL_US_CD); >>> } >>> >>> + /* >>> + * If there is no Fractional Part, there is a high chance that >>> + * we may be able to generate a baudrate closer to the desired one >>> + * if we use the GCLK as the clock source driving the baudrate >>> + * generator. >>> + */ >>> + if (!atmel_port->has_frac_baudrate) { >>> + if (__clk_is_enabled(atmel_port->gclk)) >>> + clk_disable_unprepare(atmel_port->gclk); >>> + gclk_rate = clk_round_rate(atmel_port->gclk, 16 * baud); >>> + actual_baud = clk_get_rate(atmel_port->clk) / (16 * cd); >>> + if (gclk_rate && abs(atmel_error_rate(baud, actual_baud)) > >>> + abs(atmel_error_rate(baud, gclk_rate / 16))) { > > If this condition fails and you previously used GCLK for clock generation > you should remove bits ATMEL_US_USCLKS or ATMEL_UA_BRSRCCK from mode > variable, to avoid configuring MR with GCLK support and clock not being > properly setup. > This will not happen, since the code block placed at the very start of atmel_set_termios() /* reset the mode, clock divisor, parity, stop bits and data size */ mode &= ~(ATMEL_US_USCLKS | ATMEL_US_CHRL | ATMEL_US_NBSTOP | ATMEL_US_PAR | ATMEL_US_USMODE); will still clear the ATMEL_UA_BRSRCCK bitfield since it is the same as the ATMEL_US_NBSTOP bitfield. It is ugly and it has been working so far just through the coincidence of the bitfields placement. I did not want to change those lines as I did not really think of them as worth being part of this patch series (PATCH 8 of this series is an exception as it does introduce the needed is_usart boolean). I will send a patch regarding this, but separately since it is more like a pure cleanup related PATCH, in my opinion. >>> + clk_set_rate(atmel_port->gclk, 16 * baud); >>> + ret = clk_prepare_enable(atmel_port->gclk); >>> + if (ret) >>> + goto gclk_fail; >>> + >>> + if (atmel_port->is_usart) { >>> + mode &= ~ATMEL_US_USCLKS; >>> + mode |= ATMEL_US_USCLKS_GCLK; >>> + } else { >>> + mode &= ~ATMEL_UA_BRSRCCK; >>> + mode |= ATMEL_UA_BRSRCCK_GCLK; >>> + } >>> + >>> + /* >>> + * Set the Clock Divisor for GCLK to 1. >>> + * Since we were able to generate the smallest >>> + * multiple of the desired baudrate times 16, >>> + * then we surely can generate a bigger multiple >>> + * with the exact error rate for an equally increased >>> + * CD. Thus no need to take into account >>> + * a higher value for CD. >>> + */ >>> + cd = 1; >>> + } >>> + } >>> + >>> +gclk_fail: >>> quot = cd | fp << ATMEL_US_FP_OFFSET; >>> >>> if (!(port->iso7816.flags & SER_ISO7816_ENABLED)) >>> @@ -2897,6 +2948,12 @@ static int atmel_serial_probe(struct platform_device *pdev) >>> if (ret) >>> goto err; >>> >>> + atmel_port->gclk = devm_clk_get_optional(&pdev->dev, "gclk"); >>> + if (IS_ERR(atmel_port->gclk)) { >>> + ret = PTR_ERR(atmel_port->gclk); >>> + goto err_clk_disable_unprepare; >>> + } >>> + >>> ret = atmel_init_port(atmel_port, pdev); >>> if (ret) >>> goto err_clk_disable_unprepare; >> > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel