Received: by 2002:ab2:644:0:b0:1ec:cbc4:63fb with SMTP id 4csp1145152lqn; Mon, 26 Feb 2024 08:56:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXPYmcU+AlFwU9nC59QuLgBfzDZyKOL7mk4ruBHjT8ZU8NZNoaOf25GJiQY0PcsEn8ZiNISbmuzMNU0xAkdL69Qas+tS+vevb3bP0o1/g== X-Google-Smtp-Source: AGHT+IEGQC3SUt1QuDaTeB+KSttyXAY02jNyoqwrZ/dGddBsWahuH4UanWei3mXFzCR6PfnuAa6G X-Received: by 2002:a1f:dac1:0:b0:4c9:3426:2ce3 with SMTP id r184-20020a1fdac1000000b004c934262ce3mr4158874vkg.7.1708966583935; Mon, 26 Feb 2024 08:56:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708966583; cv=pass; d=google.com; s=arc-20160816; b=wlBFbSx+wtAUk51EZPjYMU+m3unisDEFVcuFm0UqTjw+8HyE92I45zoP1JcVrnCPF0 5y5EVIBEeCfFt4EZdaOtbjwe1lWb37CykDBG5KgcaLtmaWUYktcqo0FvijZOzXBR+hvS YE21PDC+VYzP4jV/3zObEED1KYfg/xSVPTHEP6d9zHkwUkwIKMhm+llgrd349S2ZDqPI woxmxLHqTxnvLuo5QaQyfRJFE7ObiDG8xsaSUAz3thPszuYqpW/wHhIK9vOqe1/drRkS gwRCrkQHA3EWQft3bIDqYgeokI4NSWYbZZqBcbO1Hw0IDqiyzKa+50QIKN1ZIOf4E98M 7TlA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SZMmT6FmPBWoUrdH2eDLCNYypdqIO9JdHa/iodwva98=; fh=hD87NRI2uXFKH7lntJG4G4naYHSrGp3lxTKSbIyEdj8=; b=i/EHgRdN4C4Iq2RvCfdMj3OFWHsf3TkAbhWPIb+BoGSt7nZm4x3EjUs+14idgkRvjR fYwSDzG9A+4yin5mobF9+5BSxAYkaPDXyF5Audl5beZN+Ayt5JyjGDRl9BPPCSWmvngY xG8DkPpbVjYXpOEaBTOE3QkrKObAgm/+Nt55YCQr85Pa/WcFA4PDKP0JZWJER8YurSAi zEDZ3kSZL8dxWJQJweL7nf0ST66oA/X+UNfBGezs1kcuD/YmU9iXSfvMD9SuXuodXZov XVGuzHsTUXJyAO7qaCTRrGS1Pf2i2CXa9XT90VWgdXOxNq32KG1AFVVW8k/RwZzJ7+LU bPgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Eyi+TgaB; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-81956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r2-20020a056214212200b0068caf39560dsi5820830qvc.429.2024.02.26.08.56.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 08:56:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Eyi+TgaB; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-81956-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81956-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9B0561C22382 for ; Mon, 26 Feb 2024 16:56:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7826B130E21; Mon, 26 Feb 2024 16:53:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Eyi+TgaB" Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 2020312EBE2; Mon, 26 Feb 2024 16:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708966425; cv=none; b=hVyexr09J2LAV54onaNrwEYEDcRpv+YahOx+vt6QLHkuiPb8puWR6/voWwpN6MRKrvwZK3TGNgUogJD3dQSNUzI3wYCWF0Ihc8E4WX3DUYMW5dQM2OT49jigG6kjxoGMBWaEiSvOjm5IP0k5Con5SkCqppSOcX9r8nry0B8ZqHo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708966425; c=relaxed/simple; bh=bDDSQ59Hx/k13de0sfVOys3VHSzqY9HF+wtdkABTdf8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o+6JSrSHV82I4hQOS8N0G+n+amr2uhWV/EIAUxmXSyBwkvPzGYrS8f8+2I2lRWV+wC7K8jZZfIK/klmdFhOk6JPXJ7REdMGabs6BR0nfNbI3U6yYbfgZ0KHFxFSoQyp9ZOS2JoVcjoOshNmteYk3tzYCZ5YQj3PqC8PyK9eb3pc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=Eyi+TgaB; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QFooRK021801; Mon, 26 Feb 2024 16:53:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=SZMmT6FmPBWoUrdH2eDLCNYypdqIO9JdHa/iodwva98=; b=Eyi+TgaBC7uP/GuikkwmdKrAIa9gJzucp7bap4m32HZVS7rQlZ7u6w7T/0DJmrQl7AWX N4A/S9IgjWC3VsSIy3LNsGAPk40QHTUg1OldPzUNRkZLYp2lWS8w+BvLQvmLxPy6IRTR zsP166I6f0QHbtNj7/gOu8G87cRaltXEOThHSnNoWOLrtzalPxDcoAWaHKI1tcI/BcUi MyqMIQkXhSXlcKpL4PPvnFnylNPQZFH+ztpSpJ+76VZZD1cD2frqs6G7+Caz34Cz8dAw cnOCnz+bKdvH4VbJC9Mwbvb11radvvBMUgaQcL9hmvW2b6yL6SG7xZLvlNgSTmQc+hST 5Q== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wgvp6bjw9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Feb 2024 16:53:30 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41QFL5NR012348; Mon, 26 Feb 2024 16:53:28 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([172.16.1.8]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wfwg21xvp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Feb 2024 16:53:28 +0000 Received: from smtpav05.wdc07v.mail.ibm.com (smtpav05.wdc07v.mail.ibm.com [10.39.53.232]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41QGrQqa66519432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 16:53:28 GMT Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E8DF858059; Mon, 26 Feb 2024 16:53:25 +0000 (GMT) Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 390E658043; Mon, 26 Feb 2024 16:53:25 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.57.130]) by smtpav05.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 26 Feb 2024 16:53:25 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, andi.shyti@kernel.org, eajames@linux.ibm.com, alistair@popple.id.au, joel@jms.id.au, jk@ozlabs.org, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, lakshmiy@us.ibmcom Subject: [PATCH v2 04/31] fsi: Expose master-specific local bus clock divider Date: Mon, 26 Feb 2024 10:52:54 -0600 Message-Id: <20240226165321.91976-5-eajames@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240226165321.91976-1-eajames@linux.ibm.com> References: <20240226165321.91976-1-eajames@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 6tXFYz9SkgrATz-73cPZW7zxHABo1ANL X-Proofpoint-GUID: 6tXFYz9SkgrATz-73cPZW7zxHABo1ANL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 adultscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 malwarescore=0 bulkscore=0 suspectscore=0 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260128 Instead of a hardcoded local bus clock divider, allow master drivers to select their local bus clock divider. Also expose master clock frequencies in the structure. This will allow FSI engine drivers to set and calculate their bus (I2C, SPI, etc) frequencies. Signed-off-by: Eddie James --- drivers/fsi/fsi-core.c | 27 ++++++++++++++++++++------- drivers/fsi/fsi-master-hub.c | 1 + drivers/fsi/fsi-master.h | 2 ++ drivers/fsi/fsi-slave.h | 1 + include/linux/fsi.h | 1 + 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c index 8823e8e56dab..9610b5948550 100644 --- a/drivers/fsi/fsi-core.c +++ b/drivers/fsi/fsi-core.c @@ -109,6 +109,12 @@ int fsi_device_peek(struct fsi_device *dev, void *val) return fsi_slave_read(dev->slave, addr, val, sizeof(uint32_t)); } +unsigned long fsi_device_local_bus_frequency(struct fsi_device *dev) +{ + return dev->slave->master->clock_frequency / dev->slave->master->lbus_divider; +} +EXPORT_SYMBOL_GPL(fsi_device_local_bus_frequency); + static void fsi_device_release(struct device *_device) { struct fsi_device *device = to_fsi_dev(_device); @@ -209,15 +215,15 @@ static inline uint32_t fsi_smode_sid(int x) return (x & FSI_SMODE_SID_MASK) << FSI_SMODE_SID_SHIFT; } -static uint32_t fsi_slave_smode(int id, u8 t_senddly, u8 t_echodly) +static uint32_t fsi_slave_smode(int id, int div, u8 t_senddly, u8 t_echodly) { return FSI_SMODE_WSC | FSI_SMODE_ECRC | fsi_smode_sid(id) | fsi_smode_echodly(t_echodly - 1) | fsi_smode_senddly(t_senddly - 1) - | fsi_smode_lbcrr(0x8); + | fsi_smode_lbcrr(div - 1); } -static int fsi_slave_set_smode(struct fsi_slave *slave) +static int fsi_slave_set_smode(struct fsi_slave *slave, int lbus_divider) { uint32_t smode; __be32 data; @@ -225,7 +231,8 @@ static int fsi_slave_set_smode(struct fsi_slave *slave) /* set our smode register with the slave ID field to 0; this enables * extended slave addressing */ - smode = fsi_slave_smode(slave->id, slave->t_send_delay, slave->t_echo_delay); + smode = fsi_slave_smode(slave->id, lbus_divider, slave->t_send_delay, + slave->t_echo_delay); data = cpu_to_be32(smode); return fsi_master_write(slave->master, slave->link, slave->id, @@ -281,7 +288,7 @@ static int fsi_slave_handle_error(struct fsi_slave *slave, bool write, slave->t_send_delay = send_delay; slave->t_echo_delay = echo_delay; - rc = fsi_slave_set_smode(slave); + rc = fsi_slave_set_smode(slave, master->lbus_divider); if (rc) return rc; @@ -773,7 +780,7 @@ static ssize_t slave_send_echo_store(struct device *dev, slave->t_send_delay = val; slave->t_echo_delay = val; - rc = fsi_slave_set_smode(slave); + rc = fsi_slave_set_smode(slave, master->lbus_divider); if (rc < 0) return rc; if (master->link_config) @@ -1028,7 +1035,7 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id) "can't set slbus on slave:%02x:%02x %d\n", link, id, rc); - rc = fsi_slave_set_smode(slave); + rc = fsi_slave_set_smode(slave, master->lbus_divider); if (rc) { dev_warn(&master->dev, "can't set smode on slave:%02x:%02x %d\n", @@ -1288,6 +1295,12 @@ int fsi_master_register(struct fsi_master *master) if (!dev_name(&master->dev)) dev_set_name(&master->dev, "fsi%d", master->idx); + if (master->flags & FSI_MASTER_FLAG_SWCLOCK) + master->clock_frequency = 100000000; // POWER reference clock + + if (!master->lbus_divider) + master->lbus_divider = FSI_SMODE_LBCRR_DEFAULT; + master->dev.class = &fsi_master_class; mutex_lock(&master->scan_lock); diff --git a/drivers/fsi/fsi-master-hub.c b/drivers/fsi/fsi-master-hub.c index 36da643b3201..111bf7a11458 100644 --- a/drivers/fsi/fsi-master-hub.c +++ b/drivers/fsi/fsi-master-hub.c @@ -230,6 +230,7 @@ static int hub_master_probe(struct device *dev) hub->master.dev.release = hub_master_release; hub->master.dev.of_node = of_node_get(dev_of_node(dev)); + hub->master.lbus_divider = 1; hub->master.idx = fsi_dev->slave->link + 1; hub->master.n_links = links; hub->master.read = hub_master_read; diff --git a/drivers/fsi/fsi-master.h b/drivers/fsi/fsi-master.h index 967622c1cabf..26e636ad9ef6 100644 --- a/drivers/fsi/fsi-master.h +++ b/drivers/fsi/fsi-master.h @@ -120,6 +120,8 @@ struct fsi_master { struct device dev; + unsigned long clock_frequency; + int lbus_divider; int idx; int n_links; int flags; diff --git a/drivers/fsi/fsi-slave.h b/drivers/fsi/fsi-slave.h index dca9db0a42e5..42af2fae0329 100644 --- a/drivers/fsi/fsi-slave.h +++ b/drivers/fsi/fsi-slave.h @@ -47,6 +47,7 @@ #define FSI_SMODE_SD_DEFAULT 16 /* Default send delay */ #define FSI_SMODE_LBCRR_SHIFT 8 /* Clk ratio shift */ #define FSI_SMODE_LBCRR_MASK 0xf /* Clk ratio mask */ +#define FSI_SMODE_LBCRR_DEFAULT 8 /* Default clk ratio */ /* * SISS fields diff --git a/include/linux/fsi.h b/include/linux/fsi.h index 3df8c54868df..e0309bf0ae07 100644 --- a/include/linux/fsi.h +++ b/include/linux/fsi.h @@ -24,6 +24,7 @@ extern int fsi_device_read(struct fsi_device *dev, uint32_t addr, extern int fsi_device_write(struct fsi_device *dev, uint32_t addr, const void *val, size_t size); extern int fsi_device_peek(struct fsi_device *dev, void *val); +extern unsigned long fsi_device_local_bus_frequency(struct fsi_device *dev); struct fsi_device_id { u8 engine_type; -- 2.39.3