From patchwork Thu Oct 24 10:09:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Chung X-Patchwork-Id: 838733 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C97E01C07CE; Thu, 24 Oct 2024 10:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729764993; cv=none; b=Bp0U8eg18HoEqZ7EvfgdVaOfS4qnqwT/xFTL6/FU0DdjnFOI7COX7cIyoVD+hF99my5SOmdpBYXiE1ZsTlAaze+g1vrXEGsnk/QLel9vtAqI9Zu32CKH6UJAjlKuMp0yZWHRymIQ9113psXetJbJmPuTJil1vKTQxfYLulglC8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729764993; c=relaxed/simple; bh=prDuoEvRrgVoG8NR5+RJGRrWU4jn+L4AE+H+VIiOJwQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FNveBG/YqZzLK414bc1s5+UTmciILcnwvyhHhIvdC5RvXmNDRYjw2Qq9V5g+LrM6RX3mFQdGsAlZZLXbeQIr5apjM9Fk0MVbMdiUVtRVDSpxdYj7YyjnC8juNXwsLSmUnc9mE/7eToLQwCplj2a5JYbzZICZEFbKauF4ioBR9Yk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VZzrWqlZ; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VZzrWqlZ" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20caea61132so5093395ad.2; Thu, 24 Oct 2024 03:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729764991; x=1730369791; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ADaRPP2N6eMb9N9MQ8ISB17ihorm+QRS3v9Yoij6m80=; b=VZzrWqlZbznUbonhBkNN3IPJtDTSRC0Cl7LGW7ckjoIvIGlDRDQkyWCdRMH+YtOCfw rIo+qrp7mvGOKatETSJykHPlx5tdPjPipH20qLLPfrBBG+3CRHmDuBa8aGaPlh4LnIdG j7dPkyQQAdEDs2eYNNhEVjTKMectoJDpjDPqss7vnjW75yJFm0dxvQ4/wOAVBmp8gUq4 HTYdYyb8YOJ2j3H1j2Rc/V48CioLj1ws81E5DVO4vzMKzUvfQqc+/KVSDtZRZRj1S06X UmcT/DYvbfqHFRQvG17nzXjkWpBw5rBuVTiLI9KNs8tFnHsGpIW0i03I/GBeQ3JUDM3j j4oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729764991; x=1730369791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ADaRPP2N6eMb9N9MQ8ISB17ihorm+QRS3v9Yoij6m80=; b=q2yqQIkYe2TponXpea8jDEAbtG+8vNci86PGY/PhWz7snl8m2bNWJXaubIOsyVymj0 DG5qgAhQLx8b6oun/E7z2JNhMUo5DfrMRB/bXbkg0m11NmW4ss2Ng4N69HW3fRi/74ze m1I18t1BLHB4AiWbI7Q3/C2xVWhHrlfLrG+UcJimcQf4eUdxgp2z5NYdHBK4dyX4RoHZ 0jmH9HbBrGM9IqenbHo4NovEoNshf1P0kgZc8jF6iHkWpmQ3bMx1u8Zta/QQMTNdu5cU bzxbYdzB/gH2oknVH/uPxjQHgakmBp1qM5Vv0OOZohfZ4glrcvziLwSIPx+Eafl4ER7Q D63g== X-Forwarded-Encrypted: i=1; AJvYcCVzTr7s3PmmcBSOtLT/xCvO9q31d0mceQClXj6w9mS6L1nH/JBtYiO3OIhbrYHru5Ms5n+L9KEA4oy3E7g=@vger.kernel.org, AJvYcCWteex8FvlaDSLagiP7L8JZ493Dy1El4/p0IRfG0fmTJmO2+SUumbM7vzfSVBDvGOlsSSpbLeYFvxZ8@vger.kernel.org X-Gm-Message-State: AOJu0YzK26dEqz+tej1bpMpMqv9qaxjvhBEoKZtld4Oo2MR/xglotEbQ WgE3JoohUsiEGdaemBigvHqBAKn+izN4hkZnlvSlmfrhfYgIrUBo X-Google-Smtp-Source: AGHT+IGwbM87/SOguzDFw1X6H7yv2QvfQTwEzTsWVx7fqscA4rMpbpeQCWxfMi8q3DCe0M+2WfsZNg== X-Received: by 2002:a17:902:e54a:b0:20c:8907:902 with SMTP id d9443c01a7336-20fa9eb5a9bmr70736545ad.49.1729764990945; Thu, 24 Oct 2024 03:16:30 -0700 (PDT) Received: from asix-MS-7816.. ([2403:c300:5606:d914:fec1:9dc9:d21d:9b02]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0bd376sm69782065ad.132.2024.10.24.03.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 03:16:30 -0700 (PDT) From: Tony Chung To: gregkh@linuxfoundation.org Cc: johan@kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Tony Chung Subject: [PATCH 1/3] drivers: usb: serial: mos7840: Add defines for clock select register offset Date: Thu, 24 Oct 2024 18:09:01 +0800 Message-Id: <20241024100901.69883-2-tony467913@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241024100901.69883-1-tony467913@gmail.com> References: <20241024100901.69883-1-tony467913@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This patch adds define for CLOCK_SELECT_REG1 & CLOCK_SELECT_REG2 offsets. These two registers can select clock source between 30M/96M/External. Signed-off-by: Tony Chung --- drivers/usb/serial/mos7840.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index ca3da79af..362875a53 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -144,6 +144,9 @@ #define SERIAL_LCR_DLAB ((__u16)(0x0080)) +#define CLOCK_SELECT_REG1 ((__u16)(0x13)) +#define CLOCK_SELECT_REG2 ((__u16)(0x14)) + /* * URB POOL related defines */ From patchwork Thu Oct 24 10:09:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Chung X-Patchwork-Id: 838307 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB00E1B0F2B; Thu, 24 Oct 2024 10:16:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729765018; cv=none; b=jJd+4sYm91QI9s5cba22XX2DkjOGWZHjeSaW1qUoqOln38Ji3RSbin7quXa2zcBGmN0bbU0xqfMIt1MbzXS0O4SoCXELUubUDTj0lwNo3qoWV56Umik5Lz7b8PMPsRXRD/vDhEkhej5iGjBXfRo0mbzJpE+N/zfSTZoHzt7zqmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729765018; c=relaxed/simple; bh=qmPDOcWi4GZ2WL2qnJgzDrV08NLOO3YnKWxWoOl+R9w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EjajhMZAOit2eP89nSU94x4vwyG2gpUFt5lDCfA7qymkoOqbbKZgeWjPtZacEiBxvZjs+3BaUTgPSEM8GAkmJ9JdYrqn1ZtQrt/9XakIgwX41bDKpJpGO+rlmbropNGGAxyqkRHp+vFX0N86LD7z2wpeEq1vgIF9DhPgRGdIKYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=h+UySiUl; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="h+UySiUl" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-20c7ee8fe6bso5192945ad.2; Thu, 24 Oct 2024 03:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729765016; x=1730369816; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pvZ1ZhPe43+xA+24X/t0+zXdfah6Ns/POWttndJQ8qQ=; b=h+UySiUlyGPGbUci6A18FH9skJBdR6NFSBV4cnpc0KIbVYCbx75B7ZDN4cMzRPbyo+ 6YDPBTl7+7iU8pzmzTwGbN4Jp4JrrQWCN3qn9TSYEsc/+8XmwCEm/SIIbr+l6B3L54Am 1V+hp9o4ZmZEdOKqma2C1eIbFe/X8wLS86F/aVYoLr28XN8/M9eKxYFaEXfuhx3b+QCq MNLaPCfPd3cifsDjqwRIQyGBzqR8eulKR5jwkJHP6hvJfOQE41Ne/qpNlxeBISRm693v ek2d/IhOjhMw6CO26rzY/odgNw4azJl6wqcuXxfbwmuFO4nLUHKImmcnaUCdJWMA7IhY brig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765016; x=1730369816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pvZ1ZhPe43+xA+24X/t0+zXdfah6Ns/POWttndJQ8qQ=; b=L5D7QTWsqafR5HXlfa7+ueVOHo4oZBNpNDBmEh74y+BLaulsrj6pe/GzP7i+Q2+Axl yZH73Y+06ZJWSKFBXf/rnoQt9b73BYSd559TPdCLZOq1eC46WSlOcQF6IOKQZSZhW5OF NCbu0CzF1uolPv2c3Q3RoYJfBvLECOu93dTR2+5t789WNWnHhH+MPpUhAlHlHctj5PfD V7SXKsJXTS2P30yXziykNYCtzWA1IQJOZrPlYbJnY899+7Zkq+bHvAMmS1jUpo3p5VWT eoEfAwBtLO/0bJj5velo75g7jiXYcLaM+LpIK/q+CJk1L1nPQTw2xx/+I4rVWtpj6ScG YBVw== X-Forwarded-Encrypted: i=1; AJvYcCUbVFqtc2sx62V0xJqpLGd7U+nuTk8rbm0UVF9+TKyGn8RXrLV7M4eEVpHDUKOZaVVMC9NzhBEvE1Ir@vger.kernel.org, AJvYcCXn3MH5hlandLPZeIJYIUjoznPRCOoricsndtjW3JiLfuOeoPY+SFjtFutYrYS3xIlDbPfJ5lRrhwIXKng=@vger.kernel.org X-Gm-Message-State: AOJu0YxZQavFZ4dWVChcy35Ncp6AQnvmbx6EPHblF9U81vawQHw/5D9x 80uRt7p2x9TyTO0q+a4rSzAalgQDmW654lUk29dishiLs8JsoV7K940NrP1iucc= X-Google-Smtp-Source: AGHT+IFDHMJxcGzxyDj6XM0QRJdQj9V+xj/hmPYE0tIDSciLcrYoMRr4/vtKEHT6Z4MU+Y+MWNWu9w== X-Received: by 2002:a17:903:22c1:b0:20c:a04f:927d with SMTP id d9443c01a7336-20fb99d3784mr15869935ad.33.1729765015805; Thu, 24 Oct 2024 03:16:55 -0700 (PDT) Received: from asix-MS-7816.. ([2403:c300:5606:d914:fec1:9dc9:d21d:9b02]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0bd376sm69782065ad.132.2024.10.24.03.16.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 03:16:55 -0700 (PDT) From: Tony Chung To: gregkh@linuxfoundation.org Cc: johan@kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Tony Chung Subject: [PATCH 2/3] drivers: usb: serial: mos7840: added optimized register setups for common baudrates. Date: Thu, 24 Oct 2024 18:09:03 +0800 Message-Id: <20241024100901.69883-3-tony467913@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241024100901.69883-1-tony467913@gmail.com> References: <20241024100901.69883-1-tony467913@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 added optimized register setups for common baudrates. Signed-off-by: Tony Chung --- drivers/usb/serial/mos7840.c | 114 ++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 362875a53..acc16737b 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -1063,11 +1063,116 @@ static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port, { dev_dbg(&port->dev, "%s - %d\n", __func__, baudRate); - if (baudRate <= 115200) { + // divisor = (256*DLM)+DLL + // baudrate = InputCLK/(16*Divisor) + if (baudRate == 50) { + *divisor = (256*0x09)+0x04; // DLM=0x09, DLL=0x04 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 75) { + *divisor = (256*0x06)+0x02; // DLM=0x06, DLL=0x02 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 110) { + *divisor = (256*0x04)+0x19; // DLM=0x04, DLL=0x19 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 134) { + *divisor = (256*0x03)+0x5d; // DLM=0x03, DLL=0x5d + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 150) { + *divisor = (256*0x03)+0x01; // DLM=0x03, DLL=0x01 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 300) { + *divisor = (256*0x01)+0x81; // DLM=0x01, DLL=0x81 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 600) { + *divisor = 0xc0; // DLM=0, DLL=0xc0 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 1200) { + *divisor = 0x60; // DLM=0, DLL=0x60 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 1800) { + *divisor = 0x40; // DLM=0, DLL=0x40 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 2400) { + *divisor = 0x30; // DLM=0, DLL=0x30 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 4800) { + *divisor = 0x18; // DLM=0, DLL=0x18 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 7200) { + *divisor = 0x10; // DLM=0, DLL=0x10 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 9600) { + *divisor = 0x0c; // DLM=0, DLL=0x0c + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 14400) { + *divisor = 0x08; // DLM=0, DLL=0x08 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 19200) { + *divisor = 0x06; // DLM=0, DLL=0x06 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 28800) { + *divisor = 0x04; // DLM=0, DLL=0x04 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 38400) { + *divisor = 0x03; // DLM=0, DLL=0x03 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 57600) { + *divisor = 0x02; // DLM=0, DLL=0x02 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 115200) { + *divisor = 0x01; // DLM=0, DLL=0x01 + *clk_sel_val = 0x0; // clock source = 1.846153846M + } else if (baudRate == 230400) { + *divisor = 0x01; // DLM=0, DLL=0x01 + *clk_sel_val = 0x10; // clock source = 3.692307692M + } else if (baudRate == 460800) { + *divisor = 0x01; // DLM=0, DLL=0x01 + *clk_sel_val = 0x30; // clock source = 7.384615384M + } else if (baudRate == 806400) { + *divisor = 0x01; // DLM=0, DLL=0x01 + *clk_sel_val = 0x40; // clock source = 12.923076922M + } else if (baudRate == 921600) { + *divisor = 0x01; // DLM=0, DLL=0x01 + *clk_sel_val = 0x50; // clock source = 14.769230768M + } else if (baudRate == 25000) { + *divisor = 0x78; // DLM=0, DLL=0x78 + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 50000) { + *divisor = 0x3c; // DLM=0, DLL=0x3c + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 75000) { + *divisor = 0x28; // DLM=0, DLL=0x28 + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 100000) { + *divisor = 0x1e; // DLM=0, DLL=0x1e + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 250000) { + *divisor = 0x0c; // DLM=0, DLL=0x0c + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 300000) { + *divisor = 0x0a; // DLM=0, DLL=0x0a + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 500000) { + *divisor = 0x06; // DLM=0, DLL=0x06 + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 600000) { + *divisor = 0x05; // DLM=0, DLL=0x05 + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 1000000) { + *divisor = 0x03; // DLM=0, DLL=0x03 + *clk_sel_val = 0x70; // clock source=48M + } else if (baudRate == 3000000) { + *divisor = 0x01; // DLM=0, DLL=0x01 + *clk_sel_val = 0x70; // clock source=48M + + } else if (baudRate == 1500000) { + *divisor = 0x01; // DLM=0, DLL=0x01 + *clk_sel_val = 0x60; // clock source=24M + + } else if (baudRate <= 115200) { *divisor = 115200 / baudRate; *clk_sel_val = 0x0; - } - if ((baudRate > 115200) && (baudRate <= 230400)) { + } else if ((baudRate > 115200) && (baudRate <= 230400)) { *divisor = 230400 / baudRate; *clk_sel_val = 0x10; } else if ((baudRate > 230400) && (baudRate <= 403200)) { @@ -1088,6 +1193,9 @@ static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port, } else if ((baudRate > 1572864) && (baudRate <= 3145728)) { *divisor = 3145728 / baudRate; *clk_sel_val = 0x70; + } else { + dev_dbg(&port->dev, "func: %s -baudrate %d not supported.\n", __func__, baudRate); + return -1; } return 0; } From patchwork Thu Oct 24 10:09:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Chung X-Patchwork-Id: 838732 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A75541BD028; Thu, 24 Oct 2024 10:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729765066; cv=none; b=UE8XJDDrDIAJlqa5xIWR5Hz2HMj3DzgwBjm9GCQ3NJfSdNUJWAmJu4VlknaOjqV+4ZsdFOIDuiFdLAvhQ1dObnoTFdrnSkTqiYaZ6wQlI/hGNFUeHw65Ai7IcJdO5yvh0vCbdz2/foNNl0YXUEO+S+RA0bfIbkwwqoNFKTqI0N4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729765066; c=relaxed/simple; bh=c8Jg98xcpFACVY6GOIH4a4vVaCnNTNjpk0qmHzOUfHU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mXCqjgL89Oofm6mNg2I9J3XdZOlFyMumiLdNs428r7UMjS1f5XuUfGsQpKsOInFfChSCrFv6AzzR9nFZEWU2RJy93dwyOqfeTkUm3R2kjClpcCeAwr0QK8yAclV7Thh96oSZNY7sP6l9nNGQQ7sYstN0eZ5dU2i0pChsSXATgag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FTFYgM4s; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FTFYgM4s" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20cf6eea3c0so5334725ad.0; Thu, 24 Oct 2024 03:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729765063; x=1730369863; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SMncn0KiFbXEwxO5HGVMTGntCAI1pNF6ZkKXsjmzxls=; b=FTFYgM4sBaYJhVvQ7whjlURP9KNZzg8haue8D63Ga4UifYZzg/FtmLwH6upQSaejw0 sncESwiVFQtqUwuN52aMZRRlmbGuRLvZMou9FJFrwWgrFCuaDStzChn77FszzlUt1EFE W+c+eHRLIJvUqVjnBGEAzaj/9IZImaEW2eBSZi2uOwHyqClSpsX7xKeF4zSJKflTmXRw Vpc7F5QtyAtQ+G8ehT16TKAH6g87DyxHC+Mv9yU89aE14WwGoopKwCNOTDgsDLxBnC8M fvyZKwNVJ4OTESTJZ0/8ipSGalyYQJDbN7ManRajNP2GP2xnNjVuWFBgKBqDdhA4EpOk DFaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729765063; x=1730369863; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SMncn0KiFbXEwxO5HGVMTGntCAI1pNF6ZkKXsjmzxls=; b=uEk8ZqT9UTEG3Z1cSamMYs1CnfsKZptqzEDCfBbq6PA4tuIuje4nYbQTIEgCYj3JGK 83AdVGzICdbexcKVEexXVGipUzPsuQK8Z2xVPbs2sznjOb2AwwPkVZWeO3h7QdTjzLZr qCPvMTmtVmqm7eVcDsKIS0sYVIRrLILv3FhR0oHZvO0aPGSbqGjW8zeyv/0yL+Xu3/7R lQZrtURkqtxFcPcvHct0AM7lQlQ8psGkRQTh/9GKo5oUwrNChnEhwrttX9ND3lsPG8ZO zzaq6ypAdhLlzvE1WeBO8nl8Ay1clCXi52qhw7r9RMq4i8+uSJGZ5JiRIsdHlEP8OQmV oZ6A== X-Forwarded-Encrypted: i=1; AJvYcCVCDGU1jvB82jzYI21i5zHfFkJ3h1/dJILKMKshjUqNjCbOc026wEwJOVEH3VM52Nb9w8aW+ii8Qefv@vger.kernel.org, AJvYcCXPjwd7xt9LzhncN107kBeJmk3YzXq4NHMPQBpm3oICpXw663KgOWna8RIERmNPH6NCxDgO88OdSCQcpZs=@vger.kernel.org X-Gm-Message-State: AOJu0YzoJaZKprrkWHqgvb+nkxSrW86jXVNDePsMGFCW8bI8JRfAowWQ 8e20mJRm5pIkzKPfLaLrTIeyoPKBO8ZFx9E798gdvy641fqBfDtB X-Google-Smtp-Source: AGHT+IE0ZZptJeQNZ2yXYdqjWFys5LQ0dbKILrWDy93GpnNpyjTIxetByYZKitPhqyz8t3FSH+xpaA== X-Received: by 2002:a17:902:d2d0:b0:20c:6b11:deef with SMTP id d9443c01a7336-20fb9addb15mr12813925ad.48.1729765062847; Thu, 24 Oct 2024 03:17:42 -0700 (PDT) Received: from asix-MS-7816.. ([2403:c300:5606:d914:fec1:9dc9:d21d:9b02]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e7f0bd376sm69782065ad.132.2024.10.24.03.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 03:17:42 -0700 (PDT) From: Tony Chung To: gregkh@linuxfoundation.org Cc: johan@kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Tony Chung Subject: [PATCH 3/3] driver: usb: serial: mos7840: add more baudrate options Date: Thu, 24 Oct 2024 18:09:05 +0800 Message-Id: <20241024100901.69883-4-tony467913@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241024100901.69883-1-tony467913@gmail.com> References: <20241024100901.69883-1-tony467913@gmail.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Adds more baud rate options using 96M/30M/External clock sources. To use these clock sources, set through Clk_Select_Reg1 and Clk_Select_Reg2. Signed-off-by: Tony Chung --- drivers/usb/serial/mos7840.c | 156 ++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index acc16737b..70ee4a638 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -1169,6 +1169,37 @@ static int mos7840_calc_baud_rate_divisor(struct usb_serial_port *port, *divisor = 0x01; // DLM=0, DLL=0x01 *clk_sel_val = 0x60; // clock source=24M + /* below are using 96M or 30M clock source + * will determine the clock source later + * in function mos7840_send_cmd_write_baud_rate + */ + } else if (baudRate == 6000000) { + *divisor = 0x01; // DLM=0, DLL=0x01 + *clk_sel_val = 0x80; // DUMMY val, clock source = 96M + } else if (baudRate == 2000000) { + *divisor = 0x03; // DLM=0, DLL=0x03 + *clk_sel_val = 0x80; // DUMMY val, clock source = 96M + } else if (baudRate == 403200) { + *divisor = 0x0f; // DLM=0, DLL=0x0f + *clk_sel_val = 0x80; // DUMMY val, clock source = 96M + } else if (baudRate == 225000) { + *divisor = 0x1b; // DLM=0, DLL=0x1b + *clk_sel_val = 0x80; // DUMMY val, clock source = 96M + } else if (baudRate == 153600) { + *divisor = 0x27; // DLM=0, DLL=0x27 + *clk_sel_val = 0x80; // DUMMY val, clock source = 96M + + } else if (baudRate == 10000) { + *divisor = 0xbb; // DLM=0, DLL=0xbb + *clk_sel_val = 0x80; // DUMMY val, clock source = 30M + } else if (baudRate == 125000) { + *divisor = 0x0f; // DLM=0, DLL=0x0f + *clk_sel_val = 0x80; // DUMMY val, clock source = 30M + } else if (baudRate == 625000) { + *divisor = 0x03; // DLM=0, DLL=0x03 + *clk_sel_val = 0x80; // DUMMY val, clock source = 30M + + } else if (baudRate <= 115200) { *divisor = 115200 / baudRate; *clk_sel_val = 0x0; @@ -1246,11 +1277,134 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port, } - if (1) { /* baudRate <= 115200) */ + if (1) { clk_sel_val = 0x0; Data = 0x0; status = mos7840_calc_baud_rate_divisor(port, baudRate, &divisor, &clk_sel_val); + if (status < 0) { + dev_dbg(&port->dev, "%s failed in set_serial_baud\n", __func__); + return -1; + } + + /* Write clk_sel_val to SP_Reg or Clk_Select_Reg*/ + // check clk_sel_val before setting the clk_sel_val + if (clk_sel_val == 0x80) { + // clk_sel_val is DUMMY value -> Write the corresponding value to Clk_Select_Reg + // 0x01:30M, 0x02:96M, 0x05:External Clock + if (baudRate == 125000 || baudRate == 625000 || baudRate == 10000) { + clk_sel_val = 0x01; + } else if (baudRate == 153600 || baudRate == 225000 || baudRate == 403200 || + baudRate == 2000000 || baudRate == 6000000) { + clk_sel_val = 0x02; + } else { + clk_sel_val = 0x05; // externel clk for custom case. + } + + // needs to set clock source through + // Clk_Select_Reg1(offset 0x13) & Clk_Select_Reg2(offset 0x14) + // Clk_Select_Reg1 for port1,2 Clk_Select_Reg2 for port3,4 + if (mos7840_port->port_num <= 2) { + status = mos7840_get_reg_sync(port, CLOCK_SELECT_REG1, &Data); + if (status < 0) { + dev_dbg(&port->dev, "reading Clk_Select_Reg failed in set_serial_baud\n"); + return -1; + } + if (mos7840_port->port_num == 1) { + Data = (Data & 0xf8) | clk_sel_val; + status = + mos7840_set_reg_sync(port, CLOCK_SELECT_REG1, Data); + } else if (mos7840_port->port_num == 2) { + Data = (Data & 0xc7) | (clk_sel_val<<3); + status = + mos7840_set_reg_sync(port, CLOCK_SELECT_REG1, Data); + } + if (status < 0) { + dev_dbg(&port->dev, "setting Clk_Select_Reg failed\n"); + return -1; + } + } else if (mos7840_port->port_num <= 4) { + status = mos7840_get_reg_sync(port, CLOCK_SELECT_REG2, &Data); + if (status < 0) { + dev_dbg(&port->dev, "reading Clk_Select_Reg failed in set_serial_baud\n"); + return -1; + } + if (mos7840_port->port_num == 3) { + Data = (Data & 0xf8) | clk_sel_val; + status = + mos7840_set_reg_sync(port, CLOCK_SELECT_REG2, Data); + } else if (mos7840_port->port_num == 4) { + Data = (Data & 0xc7) | (clk_sel_val<<3); + status = + mos7840_set_reg_sync(port, CLOCK_SELECT_REG2, Data); + } + if (status < 0) { + dev_dbg(&port->dev, "setting Clk_Select_Reg failed\n"); + return -1; + } + } + } else { + // clk_sel_val is not DUMMY value -> Write the corresponding value to SP_Reg + + /* First, needs to write default value to + * Clk_Select_Reg1(offset 0x13) & Clk_Select_Reg2(offset 0x14) + * Clk_Select_Reg1 for port1,2 Clk_Select_Reg2 for port3,4 + */ + if (mos7840_port->port_num <= 2) { + status = mos7840_get_reg_sync(port, CLOCK_SELECT_REG1, &Data); + if (status < 0) { + dev_dbg(&port->dev, "reading Clk_Select_Reg failed in set_serial_baud\n"); + return -1; + } + if (mos7840_port->port_num == 1) { + Data = (Data & 0xf8) | 0x00; + status = + mos7840_set_reg_sync(port, CLOCK_SELECT_REG1, Data); + } else if (mos7840_port->port_num == 2) { + Data = (Data & 0xc7) | (0x00<<3); + status = + mos7840_set_reg_sync(port, CLOCK_SELECT_REG1, Data); + } + if (status < 0) { + dev_dbg(&port->dev, "setting Clk_Select_Reg failed\n"); + return -1; + } + } else if (mos7840_port->port_num <= 4) { + status = mos7840_get_reg_sync(port, CLOCK_SELECT_REG2, &Data); + if (status < 0) { + dev_dbg(&port->dev, "reading Clk_Select_Reg failed in set_serial_baud\n"); + return -1; + } + if (mos7840_port->port_num == 3) { + Data = (Data & 0xf8) | 0x00; + status = + mos7840_set_reg_sync(port, CLOCK_SELECT_REG2, Data); + } else if (mos7840_port->port_num == 4) { + Data = (Data & 0xc7) | (0x00<<3); + status = + mos7840_set_reg_sync(port, CLOCK_SELECT_REG2, Data); + } + if (status < 0) { + dev_dbg(&port->dev, "setting Clk_Select_Reg failed\n"); + return -1; + } + } + // select clock source by writing clk_sel_val to SPx_Reg + status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, + &Data); + if (status < 0) { + dev_dbg(&port->dev, "reading spreg failed in set_serial_baud\n"); + return -1; + } + Data = (Data & 0x8f) | clk_sel_val; + status = mos7840_set_reg_sync(port, mos7840_port->SpRegOffset, + Data); + if (status < 0) { + dev_dbg(&port->dev, "Writing spreg failed in set_serial_baud\n"); + return -1; + } + } + status = mos7840_get_reg_sync(port, mos7840_port->SpRegOffset, &Data); if (status < 0) {