From patchwork Tue May 21 15:25:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 798043 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 C018A1442EF for ; Tue, 21 May 2024 15:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716305203; cv=none; b=QH70mg3TB7nvxfEB/Tqb3fcnGK0pjuck02lGGhi3OJUs5DVEJ5r+nfTI1Jhfe+d64IDG7NGSp6WdYitcIHMKvS+DxhgHfOeaLmnk6d10d7VMlHeGDt/l3yeiPZocxDAk0/H2gDR5L+PsJ8vFDiixuo6WFKcB36nQDkGQfLSKn8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716305203; c=relaxed/simple; bh=YbcpAnvKee2GOMccnSTVfLdSPbQ/cZoM9orq9m3+dek=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=TxpeTTX8v/TBgxejAnZClJklZIWdIY1AtL2sQnKzUDJ/Q1EQ2FtcGRciVmsgriiQPPQa/bIAwqsweeF2H1t45Usdq/AdMOeEZ7SCk+oPtbiaoDYznRg6/H2k+weVTeFXdpQbxM/mbfwXGZiQPyAQ/aJbUUl7gpI93/RiJ1Ftk0M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=BS/EnN8P; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="BS/EnN8P" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a5a5cb0e6b7so900250966b.1 for ; Tue, 21 May 2024 08:26:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1716305199; x=1716909999; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0SP7h2B6yJgGk4TH9IEQ7JI0U019rt16DjXGMkeKeb4=; b=BS/EnN8PmaRk1Jmat2BP1RZDEfPL7COEnqjTFsqKlLlt4brTZk8qLSb8L/AJOyr2en D5zuaIOZ8XiRsLtXzvyZRG0bxeaVbSa3pkywN91poW9SnbyEB1jfWY3Mdzfp5OUzIhNO VTkfAaY7P7IgvxhVLaOF2m0zHtvMPImKEXsBs1Ia+ScdvwZcFMLzyui7aYzLH8CoMbUP qxGWcK8IK5Y9GakY+U61BpLAXbHvL3nmsSv0LN7Hxc342JWP8/KCCw7uXLkFZKsuSXDe TF+Znt7g+fkyFnY9aSOIHNfpfeEVnS6uGL+lE6bHhueFQtdV6AXrB2snwKxK0pvFtVp9 FTwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716305199; x=1716909999; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0SP7h2B6yJgGk4TH9IEQ7JI0U019rt16DjXGMkeKeb4=; b=NQp7sehxUjmT8xZ55+1Qo/d3NTJzchpBUzqJL5iRA+o3ZOg66fF5MSKmB+42o3DB50 c4L4oWi4zgiMdZIs3qQF45Yd3/5sq3HKRQ4+cgKEra3Wy/DdZcWblJNfuqYrfKtOFw1X no1oYTRxmDLJnJlajHPai7lvcPccxYSDQqAFjnLjZK9nN7ucM9mfFIhvo9PjGdNzzP9L G+uT1cx20WoBKmwQoa0ye77yZifIyVJq5PG9WBG/JN0JOllMw85YMFcIF+N+vz09y1Vo 2YvgTC+FOPjwgcunPlsKHGZQ8xTIsdOF2XGZ8IcLHDXstjdXF5Dpbvi9WrcFiS2RKH5Z oNBQ== X-Forwarded-Encrypted: i=1; AJvYcCXsuk2FbPNSRY92EHfUkJ2do5niaUTVnot1743+bquT/p9VCeQdjDZD81nZ25gjNqB4divfGythJF6pOXHMgDqrptyCPRdxKq3Ccw== X-Gm-Message-State: AOJu0YwRnFh8OsKeN43ri3yjS4GOTrofgx8cdOG3xsWVOCwB32gvKt4M zdnBJow4YJgOas3SqEidlgbyVjrA1hgTzKt1ymJQ8E9QwhQyeHfEuzXmAZsiVYg= X-Google-Smtp-Source: AGHT+IHNXBESWf3UtYt88Rul5ND3zDlu4ztC4pHIbV9GB5hTd3riRS/EOXQgXNRtiuUfWmdtSDvAWg== X-Received: by 2002:a17:906:6882:b0:a5a:76e2:c2a8 with SMTP id a640c23a62f3a-a5a76e2c306mr1547537466b.23.1716305199086; Tue, 21 May 2024 08:26:39 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b180c7sm1638327666b.221.2024.05.21.08.26.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 08:26:38 -0700 (PDT) From: Patrick Rudolph To: Patrick Rudolph , Linus Walleij Cc: naresh.solanki@9elements.com, andy.shevchenko@gmail.com, broonie@kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] pinctrl: cy8c95x0: Use single I2C lock Date: Tue, 21 May 2024 17:25:57 +0200 Message-ID: <20240521152602.1097764-1-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently there are 3 locks being used when accessing the chip, one in the driver and one in each regmap. Reduce that to one driver only lock that protects all regmap and regcache accesses. Signed-off-by: Patrick Rudolph Reviewed-by: Andy Shevchenko Reviewed-by: Andy Shevchenko --- drivers/pinctrl/pinctrl-cy8c95x0.c | 32 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c index 981c569bd671..ca54d91fdc77 100644 --- a/drivers/pinctrl/pinctrl-cy8c95x0.c +++ b/drivers/pinctrl/pinctrl-cy8c95x0.c @@ -453,7 +453,6 @@ cy8c95x0_mux_reg_read(void *context, unsigned int off, unsigned int *val) u8 port = CY8C95X0_MUX_REGMAP_TO_PORT(off); int ret, reg = CY8C95X0_MUX_REGMAP_TO_REG(off); - mutex_lock(&chip->i2c_lock); /* Select the correct bank */ ret = regmap_write(chip->regmap, CY8C95X0_PORTSEL, port); if (ret < 0) @@ -463,11 +462,7 @@ cy8c95x0_mux_reg_read(void *context, unsigned int off, unsigned int *val) * Read the register through direct access regmap. The target range * is marked volatile. */ - ret = regmap_read(chip->regmap, reg, val); -out: - mutex_unlock(&chip->i2c_lock); - - return ret; + return regmap_read(chip->regmap, reg, val); } static int @@ -477,7 +472,6 @@ cy8c95x0_mux_reg_write(void *context, unsigned int off, unsigned int val) u8 port = CY8C95X0_MUX_REGMAP_TO_PORT(off); int ret, reg = CY8C95X0_MUX_REGMAP_TO_REG(off); - mutex_lock(&chip->i2c_lock); /* Select the correct bank */ ret = regmap_write(chip->regmap, CY8C95X0_PORTSEL, port); if (ret < 0) @@ -487,11 +481,7 @@ cy8c95x0_mux_reg_write(void *context, unsigned int off, unsigned int val) * Write the register through direct access regmap. The target range * is marked volatile. */ - ret = regmap_write(chip->regmap, reg, val); -out: - mutex_unlock(&chip->i2c_lock); - - return ret; + return regmap_write(chip->regmap, reg, val); } static bool cy8c95x0_mux_accessible_register(struct device *dev, unsigned int off) @@ -524,6 +514,7 @@ static const struct regmap_config cy8c95x0_muxed_regmap = { .num_reg_defaults_raw = MUXED_STRIDE * BANK_SZ, .readable_reg = cy8c95x0_mux_accessible_register, .writeable_reg = cy8c95x0_mux_accessible_register, + .disable_locking = true, }; /* Direct access regmap */ @@ -542,6 +533,7 @@ static const struct regmap_config cy8c95x0_i2c_regmap = { .cache_type = REGCACHE_FLAT, .max_register = CY8C95X0_COMMAND, + .disable_locking = true, }; static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip, @@ -559,6 +551,8 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip if (reg == CY8C95X0_PORTSEL) return -EINVAL; + mutex_lock(&chip->i2c_lock); + /* Registers behind the PORTSEL mux have their own regmap */ if (cy8c95x0_muxed_register(reg)) { regmap = chip->muxed_regmap; @@ -574,7 +568,7 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip ret = regmap_update_bits_base(regmap, off, mask, val, change, async, force); if (ret < 0) - return ret; + goto out; /* Update the cache when a WC bit is written */ if (cy8c95x0_wc_register(reg) && (mask & val)) { @@ -595,6 +589,8 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip regcache_cache_only(regmap, false); } } +out: + mutex_unlock(&chip->i2c_lock); return ret; } @@ -667,7 +663,9 @@ static int cy8c95x0_regmap_read(struct cy8c95x0_pinctrl *chip, unsigned int reg, unsigned int port, unsigned int *read_val) { struct regmap *regmap; - int off; + int off, ret; + + mutex_lock(&chip->i2c_lock); /* Registers behind the PORTSEL mux have their own regmap */ if (cy8c95x0_muxed_register(reg)) { @@ -682,7 +680,11 @@ static int cy8c95x0_regmap_read(struct cy8c95x0_pinctrl *chip, unsigned int reg, off = reg; } - return regmap_read(regmap, off, read_val); + ret = regmap_read(regmap, off, read_val); + + mutex_unlock(&chip->i2c_lock); + + return ret; } static int cy8c95x0_write_regs_mask(struct cy8c95x0_pinctrl *chip, int reg, From patchwork Tue May 21 15:25:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 798042 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 84F6814430D for ; Tue, 21 May 2024 15:26:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716305205; cv=none; b=oU1qHwoEbHJ32FXV117cdQIvZqLIPuwGbehQ7Oapw1EenNzv6G4MBSU4zj9GJeBbkIxR3aOBZhzHUolpRI7PM1hDkNze1tvpViIUFFgNPTqupXLNNrDQuavuQzv0LW1RhVYIi1TXBzZld7o0TrDWN/0SkwflaMskoGQOSxaofyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716305205; c=relaxed/simple; bh=cTHe3yMlR9xXw7lxXZ7eArbEWi0LYEzeSOzMMlbzFG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e0uUb+ajl+gRG1RmhcVF4UWMwfcKwk00f3J76g+8vdSfTgc6GjS6ExBkbl2efkByi6FptWKcPKk5J5rqzOLWLAD6CpacGziK4iJB8jk0BQqFvlNHhCprrwYMjCp3/kyXeRAn0SkfUUvx5Qict/UFo6PGb5gVFGAc51HnoSDyo8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=VDk1JRV0; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="VDk1JRV0" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-574f7c0bab4so11634355a12.0 for ; Tue, 21 May 2024 08:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1716305201; x=1716910001; 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=4rjLn6crkk+FZyvtitmZt9qDIbYFZ00Z0BFOR6L2o2c=; b=VDk1JRV08quZhxkgg7UIK46JjKqK+j0cX/GitHW+YcBkCXalnN9/7vSVhFMDPUiVIn DW+wcLlPl8VmtH0sYAXmKmHDEOESNh+kZH34yB/5C0NMMMu283YV8OMJTjT7tMx3gfN+ IdREOfCWbl8WT/kaga2M//LYczNL5jDvJpHXtLchHRaKUaOCI4hxp7ZO9EX3d3b3VeWu l6CMAfrtOIaFAZnyI8Tp3AlGg/cdY4y0V0CchoUbsRe8we9vX2s4sHDRtthat9zYkhMX O7XZOMihBdfpI6ZwH9d7xtV0Fsk+gvM5uK2yDxRDLGw/s0iCrclbYirhD2hwWuWbfmDe +qcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716305201; x=1716910001; 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=4rjLn6crkk+FZyvtitmZt9qDIbYFZ00Z0BFOR6L2o2c=; b=h248zSCk33JNo/f1VlnLszVYSAkaLPVYov9ZpulV/G53T+Xi6Xxq0iQDU5QIZHByUq fzBNRJZRhVciu0s+x2Dkuol/Ak9YWgHdVRE/J1ZVaS3yTMB+InKvSKjnEUiTBg0uCPo1 7/EbmjK+tHWYj0JBCJkpNUjBs5iv9oYceedUJlURDzlNlkb77sLRExpl0bVi4vuIftqs Hkc/LDMG8SP2f6uqa3XnuxGRe92K8PDpfpazHs8PAgC3IBvEd7ZSfA3XqYTkhxo8E3a5 2NFLTVY8fvho3MHIgHIEn7oJjyCXb7esQ2ww2wOagCwuIV9EwjmtVS6dkKWv88jI1sRR Kk9A== X-Forwarded-Encrypted: i=1; AJvYcCXb7A2tEpX5fHnouyrTjmfAS29Dk97BZTsvYcW1VRt/eB1eQtof7P0mMwAH1mMr8/3elVQPGOAIez3roGVx0pD+tAf/BmN7FcKh5A== X-Gm-Message-State: AOJu0YzjW2FjQ8C7hMJUpSFAXodU8uujrSfgTzs2pjx17P+Y0ZqT17aK dFNznUUA6d7q6g/LvDCM3OCz7yayfsWV/g2Uqyw3Og370rMeqwMsbk9E9AyDrI2/EDUvXNfEkoV 8 X-Google-Smtp-Source: AGHT+IFbzN83Lvjgry3fYhyDeN6yz/WEJGyQWb1CTLP6cXz+H50bserwMnATmoFQKxpesjnBptrf6w== X-Received: by 2002:a17:906:3a9a:b0:a5a:7493:5b68 with SMTP id a640c23a62f3a-a5d5ecdc977mr785308366b.24.1716305200732; Tue, 21 May 2024 08:26:40 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b180c7sm1638327666b.221.2024.05.21.08.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 08:26:40 -0700 (PDT) From: Patrick Rudolph To: Patrick Rudolph , Linus Walleij Cc: naresh.solanki@9elements.com, andy.shevchenko@gmail.com, broonie@kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] pinctrl: cy8c95x0: Use regmap ranges Date: Tue, 21 May 2024 17:25:58 +0200 Message-ID: <20240521152602.1097764-2-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240521152602.1097764-1-patrick.rudolph@9elements.com> References: <20240521152602.1097764-1-patrick.rudolph@9elements.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of implementing a custom register paging mechanism in the driver use the existing regmap ranges feature. Signed-off-by: Patrick Rudolph Reviewed-by: Andy Shevchenko --- drivers/pinctrl/pinctrl-cy8c95x0.c | 179 +++++++++-------------------- 1 file changed, 53 insertions(+), 126 deletions(-) diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c index ca54d91fdc77..9570de598193 100644 --- a/drivers/pinctrl/pinctrl-cy8c95x0.c +++ b/drivers/pinctrl/pinctrl-cy8c95x0.c @@ -58,9 +58,14 @@ #define CY8C95X0_PIN_TO_OFFSET(x) (((x) >= 20) ? ((x) + 4) : (x)) -#define CY8C95X0_MUX_REGMAP_TO_PORT(x) ((x) / MUXED_STRIDE) -#define CY8C95X0_MUX_REGMAP_TO_REG(x) (((x) % MUXED_STRIDE) + CY8C95X0_INTMASK) -#define CY8C95X0_MUX_REGMAP_TO_OFFSET(x, p) ((x) - CY8C95X0_INTMASK + (p) * MUXED_STRIDE) +#define MAX_BANK 8 +#define BANK_SZ 8 +#define MAX_LINE (MAX_BANK * BANK_SZ) +#define MUXED_STRIDE (CY8C95X0_DRV_HIZ - CY8C95X0_INTMASK) +#define CY8C95X0_GPIO_MASK GENMASK(7, 0) +#define CY8C95X0_VIRTUAL (CY8C95X0_COMMAND + 1) +#define CY8C95X0_MUX_REGMAP_TO_OFFSET(x, p) \ + (CY8C95X0_VIRTUAL + (x) - CY8C95X0_INTMASK + (p) * MUXED_STRIDE) static const struct i2c_device_id cy8c95x0_id[] = { { "cy8c9520", 20, }, @@ -120,18 +125,11 @@ static const struct dmi_system_id cy8c95x0_dmi_acpi_irq_info[] = { {} }; -#define MAX_BANK 8 -#define BANK_SZ 8 -#define MAX_LINE (MAX_BANK * BANK_SZ) -#define MUXED_STRIDE 16 -#define CY8C95X0_GPIO_MASK GENMASK(7, 0) - /** * struct cy8c95x0_pinctrl - driver data * @regmap: Device's regmap. Only direct access registers. - * @muxed_regmap: Regmap for all muxed registers. * @irq_lock: IRQ bus lock - * @i2c_lock: Mutex for the device internal mux register + * @i2c_lock: Mutex to hold while using the regmap * @irq_mask: I/O bits affected by interrupts * @irq_trig_raise: I/O bits affected by raising voltage level * @irq_trig_fall: I/O bits affected by falling voltage level @@ -152,7 +150,6 @@ static const struct dmi_system_id cy8c95x0_dmi_acpi_irq_info[] = { */ struct cy8c95x0_pinctrl { struct regmap *regmap; - struct regmap *muxed_regmap; struct mutex irq_lock; struct mutex i2c_lock; DECLARE_BITMAP(irq_mask, MAX_LINE); @@ -331,6 +328,9 @@ static int cypress_get_pin_mask(struct cy8c95x0_pinctrl *chip, unsigned int pin) static bool cy8c95x0_readable_register(struct device *dev, unsigned int reg) { + if (reg >= CY8C95X0_VIRTUAL) + return true; + switch (reg) { case 0x24 ... 0x27: return false; @@ -341,6 +341,9 @@ static bool cy8c95x0_readable_register(struct device *dev, unsigned int reg) static bool cy8c95x0_writeable_register(struct device *dev, unsigned int reg) { + if (reg >= CY8C95X0_VIRTUAL) + return true; + switch (reg) { case CY8C95X0_INPUT_(0) ... CY8C95X0_INPUT_(7): return false; @@ -433,106 +436,33 @@ static bool cy8c95x0_quick_path_register(unsigned int reg) } } -static const struct reg_default cy8c95x0_reg_defaults[] = { - { CY8C95X0_OUTPUT_(0), GENMASK(7, 0) }, - { CY8C95X0_OUTPUT_(1), GENMASK(7, 0) }, - { CY8C95X0_OUTPUT_(2), GENMASK(7, 0) }, - { CY8C95X0_OUTPUT_(3), GENMASK(7, 0) }, - { CY8C95X0_OUTPUT_(4), GENMASK(7, 0) }, - { CY8C95X0_OUTPUT_(5), GENMASK(7, 0) }, - { CY8C95X0_OUTPUT_(6), GENMASK(7, 0) }, - { CY8C95X0_OUTPUT_(7), GENMASK(7, 0) }, - { CY8C95X0_PORTSEL, 0 }, - { CY8C95X0_PWMSEL, 0 }, -}; - -static int -cy8c95x0_mux_reg_read(void *context, unsigned int off, unsigned int *val) -{ - struct cy8c95x0_pinctrl *chip = context; - u8 port = CY8C95X0_MUX_REGMAP_TO_PORT(off); - int ret, reg = CY8C95X0_MUX_REGMAP_TO_REG(off); - - /* Select the correct bank */ - ret = regmap_write(chip->regmap, CY8C95X0_PORTSEL, port); - if (ret < 0) - goto out; - - /* - * Read the register through direct access regmap. The target range - * is marked volatile. - */ - return regmap_read(chip->regmap, reg, val); -} - -static int -cy8c95x0_mux_reg_write(void *context, unsigned int off, unsigned int val) -{ - struct cy8c95x0_pinctrl *chip = context; - u8 port = CY8C95X0_MUX_REGMAP_TO_PORT(off); - int ret, reg = CY8C95X0_MUX_REGMAP_TO_REG(off); - - /* Select the correct bank */ - ret = regmap_write(chip->regmap, CY8C95X0_PORTSEL, port); - if (ret < 0) - goto out; - - /* - * Write the register through direct access regmap. The target range - * is marked volatile. - */ - return regmap_write(chip->regmap, reg, val); -} - -static bool cy8c95x0_mux_accessible_register(struct device *dev, unsigned int off) -{ - struct i2c_client *i2c = to_i2c_client(dev); - struct cy8c95x0_pinctrl *chip = i2c_get_clientdata(i2c); - u8 port = CY8C95X0_MUX_REGMAP_TO_PORT(off); - u8 reg = CY8C95X0_MUX_REGMAP_TO_REG(off); - - if (port >= chip->nport) - return false; - - return cy8c95x0_muxed_register(reg); -} - -static struct regmap_bus cy8c95x0_regmap_bus = { - .reg_read = cy8c95x0_mux_reg_read, - .reg_write = cy8c95x0_mux_reg_write, -}; - -/* Regmap for muxed registers CY8C95X0_INTMASK - CY8C95X0_DRV_HIZ */ -static const struct regmap_config cy8c95x0_muxed_regmap = { - .name = "muxed", - .reg_bits = 8, - .val_bits = 8, - .cache_type = REGCACHE_FLAT, - .use_single_read = true, - .use_single_write = true, - .max_register = MUXED_STRIDE * BANK_SZ, - .num_reg_defaults_raw = MUXED_STRIDE * BANK_SZ, - .readable_reg = cy8c95x0_mux_accessible_register, - .writeable_reg = cy8c95x0_mux_accessible_register, - .disable_locking = true, +static const struct regmap_range_cfg cy8c95x0_ranges[] = { + { + .range_min = CY8C95X0_VIRTUAL, + .range_max = 0, /* Updated at runtime */ + .selector_reg = CY8C95X0_PORTSEL, + .selector_mask = 0x07, + .selector_shift = 0x0, + .window_start = CY8C95X0_INTMASK, + .window_len = MUXED_STRIDE, + } }; -/* Direct access regmap */ -static const struct regmap_config cy8c95x0_i2c_regmap = { - .name = "direct", +static const struct regmap_config cy8c9520_i2c_regmap = { .reg_bits = 8, .val_bits = 8, - .reg_defaults = cy8c95x0_reg_defaults, - .num_reg_defaults = ARRAY_SIZE(cy8c95x0_reg_defaults), - .readable_reg = cy8c95x0_readable_register, .writeable_reg = cy8c95x0_writeable_register, .volatile_reg = cy8c95x0_volatile_register, .precious_reg = cy8c95x0_precious_register, .cache_type = REGCACHE_FLAT, - .max_register = CY8C95X0_COMMAND, + .ranges = NULL, /* Updated at runtime */ + .num_ranges = 1, + .max_register = 0, /* Updated at runtime */ + .num_reg_defaults_raw = 0, /* Updated at runtime */ + .use_single_read = true, /* Workaround for regcache bug */ .disable_locking = true, }; @@ -544,7 +474,6 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip bool *change, bool async, bool force) { - struct regmap *regmap; int ret, off, i, read_val; /* Caller should never modify PORTSEL directly */ @@ -553,12 +482,10 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip mutex_lock(&chip->i2c_lock); - /* Registers behind the PORTSEL mux have their own regmap */ + /* Registers behind the PORTSEL mux have their own range in regmap */ if (cy8c95x0_muxed_register(reg)) { - regmap = chip->muxed_regmap; off = CY8C95X0_MUX_REGMAP_TO_OFFSET(reg, port); } else { - regmap = chip->regmap; /* Quick path direct access registers honor the port argument */ if (cy8c95x0_quick_path_register(reg)) off = reg + port; @@ -566,7 +493,7 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip off = reg; } - ret = regmap_update_bits_base(regmap, off, mask, val, change, async, force); + ret = regmap_update_bits_base(chip->regmap, off, mask, val, change, async, force); if (ret < 0) goto out; @@ -577,16 +504,16 @@ static inline int cy8c95x0_regmap_update_bits_base(struct cy8c95x0_pinctrl *chip continue; off = CY8C95X0_MUX_REGMAP_TO_OFFSET(i, port); - ret = regmap_read(regmap, off, &read_val); + ret = regmap_read(chip->regmap, off, &read_val); if (ret < 0) continue; if (!(read_val & mask & val)) continue; - regcache_cache_only(regmap, true); - regmap_update_bits(regmap, off, mask & val, 0); - regcache_cache_only(regmap, false); + regcache_cache_only(chip->regmap, true); + regmap_update_bits(chip->regmap, off, mask & val, 0); + regcache_cache_only(chip->regmap, false); } } out: @@ -662,17 +589,14 @@ static int cy8c95x0_regmap_update_bits(struct cy8c95x0_pinctrl *chip, unsigned i static int cy8c95x0_regmap_read(struct cy8c95x0_pinctrl *chip, unsigned int reg, unsigned int port, unsigned int *read_val) { - struct regmap *regmap; int off, ret; mutex_lock(&chip->i2c_lock); - /* Registers behind the PORTSEL mux have their own regmap */ + /* Registers behind the PORTSEL mux have their own range in regmap */ if (cy8c95x0_muxed_register(reg)) { - regmap = chip->muxed_regmap; off = CY8C95X0_MUX_REGMAP_TO_OFFSET(reg, port); } else { - regmap = chip->regmap; /* Quick path direct access registers honor the port argument */ if (cy8c95x0_quick_path_register(reg)) off = reg + port; @@ -680,7 +604,7 @@ static int cy8c95x0_regmap_read(struct cy8c95x0_pinctrl *chip, unsigned int reg, off = reg; } - ret = regmap_read(regmap, off, read_val); + ret = regmap_read(chip->regmap, off, read_val); mutex_unlock(&chip->i2c_lock); @@ -1513,6 +1437,8 @@ static int cy8c95x0_detect(struct i2c_client *client, static int cy8c95x0_probe(struct i2c_client *client) { struct cy8c95x0_pinctrl *chip; + struct regmap_config regmap_conf; + struct regmap_range_cfg regmap_range_conf; struct regulator *reg; int ret; @@ -1532,15 +1458,20 @@ static int cy8c95x0_probe(struct i2c_client *client) chip->tpin = chip->driver_data & CY8C95X0_GPIO_MASK; chip->nport = DIV_ROUND_UP(CY8C95X0_PIN_TO_OFFSET(chip->tpin), BANK_SZ); + memcpy(®map_range_conf, &cy8c95x0_ranges[0], sizeof(regmap_range_conf)); + switch (chip->tpin) { case 20: strscpy(chip->name, cy8c95x0_id[0].name, I2C_NAME_SIZE); + regmap_range_conf.range_max = CY8C95X0_VIRTUAL + 3 * MUXED_STRIDE; break; case 40: strscpy(chip->name, cy8c95x0_id[1].name, I2C_NAME_SIZE); + regmap_range_conf.range_max = CY8C95X0_VIRTUAL + 6 * MUXED_STRIDE; break; case 60: strscpy(chip->name, cy8c95x0_id[2].name, I2C_NAME_SIZE); + regmap_range_conf.range_max = CY8C95X0_VIRTUAL + 8 * MUXED_STRIDE; break; default: return -ENODEV; @@ -1573,22 +1504,18 @@ static int cy8c95x0_probe(struct i2c_client *client) gpiod_set_consumer_name(chip->gpio_reset, "CY8C95X0 RESET"); } - /* Generic regmap for direct access registers */ - chip->regmap = devm_regmap_init_i2c(client, &cy8c95x0_i2c_regmap); + /* Regmap for direct and paged registers */ + memcpy(®map_conf, &cy8c9520_i2c_regmap, sizeof(regmap_conf)); + regmap_conf.ranges = ®map_range_conf; + regmap_conf.max_register = regmap_range_conf.range_max; + regmap_conf.num_reg_defaults_raw = regmap_range_conf.range_max; + + chip->regmap = devm_regmap_init_i2c(client, ®map_conf); if (IS_ERR(chip->regmap)) { ret = PTR_ERR(chip->regmap); goto err_exit; } - /* Port specific regmap behind PORTSEL mux */ - chip->muxed_regmap = devm_regmap_init(&client->dev, &cy8c95x0_regmap_bus, - chip, &cy8c95x0_muxed_regmap); - if (IS_ERR(chip->muxed_regmap)) { - ret = dev_err_probe(&client->dev, PTR_ERR(chip->muxed_regmap), - "Failed to register muxed regmap\n"); - goto err_exit; - } - bitmap_zero(chip->push_pull, MAX_LINE); bitmap_zero(chip->shiftmask, MAX_LINE); bitmap_set(chip->shiftmask, 0, 20); From patchwork Tue May 21 15:25:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Rudolph X-Patchwork-Id: 798255 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 DA5DD1448DC for ; Tue, 21 May 2024 15:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716305205; cv=none; b=cVnzNkI7NVdI/KsAzgYLak7JZlwZTujS4ng/dzKH09gg93a/dUek3M3UMIH/lNhmktGjobyhUcrYrgvl6PsNXR4pj8eRAWnS6ni08y7i1lZBRdm+x4ht+im6mwvmnoIixBr5Cct4oGdLvb0j6vcOkNiojLi5oW9hOi/s6pmJKMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716305205; c=relaxed/simple; bh=aiHtBVIcUBQAnB5Q2EBmNg8ODIWt4KSjAsZp4MaE7bc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RIRCs3uia/gaRyWWwJ5zqPmJ0MvJNf3eJWKJJAe0oZq/eHgIzWbf1Zs9BeOGg3/Ow1puX0675W8bfts2XyEgn+9kcsJ1CL/fPKFAPOjFBMg8gjAmEU5xIN3TW14rjcZFMzGLedM6nvVOAAjUXOypTO/qSuVjxV7z2joSnT7sIjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=9elements.com; spf=pass smtp.mailfrom=9elements.com; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b=Zdbx9h1Y; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=9elements.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=9elements.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=9elements.com header.i=@9elements.com header.b="Zdbx9h1Y" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a59a934ad50so844854266b.1 for ; Tue, 21 May 2024 08:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1716305202; x=1716910002; 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=qjFz7A85flN3TvntQYJ6kQFqr3/C0cpeamTEx2vLXLU=; b=Zdbx9h1Y1VzFBHgpKkn0VUrx0LM9HC/BZnvkVkosPwf07A70+JXWaV9PtzKWGXvBb/ wCUsmOg0bvA9G6ia8l3I3I++UI+TYEK99UVEBAnCD7K012yPC91Ji7FHjXNNaf7Ro4FU At/c2fEf6EEGrrbD6pquSn8OUSSEG2pSGUtXaw6Sefa2AnhyY9u2tL6/tPweLuE7zGML iptl+wIW3HB4pVXb/6vSEPrnc96l7eK2isZHDodpUw+gKdvcDpLqnoxXeY/997x7IxWD 8zorYdOsSDrE1UqX6W0yXpu4Dqz4iM1ixpEYFNsNbY823BcMJ2V4Sycsgjf5qBm6hDa8 JKTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716305202; x=1716910002; 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=qjFz7A85flN3TvntQYJ6kQFqr3/C0cpeamTEx2vLXLU=; b=wF0ln2HDUsW7FQ/4ndDhbkkJ717RZbElC2BHIOsRPnvWFRQhgCh+sAO2JTAcFTCM5h PSUncWJYMetio6LLxgx9nG4qzwiwtdYFje/qwSQV+g92us5SfdwYt5QKITTA9hzVH880 tE3Cq2PByAb9Kh6nTb76GnVnwif8qs3Vrnmpj8RFluxaL9Da7jNGYYTVRitZHkF/hqCQ E3Msau7R4ZUUHV7aZPBAC/wGtGJsVJipXfTUIJ2ZMrntsEGh/NsMQBUiMLdRctYTcyWi 9QoZz/bKm43vu5OZdT3BiAEhyuRkzUav9j3CPbUmUFsjqX8Sg2UZbGHFXH6B+FsVcX22 JyAQ== X-Forwarded-Encrypted: i=1; AJvYcCUdoaJG8Dx7ng3XaLUxOvjGeVBrhg662yPwoGGoojrRzoX+td+gK2Bf5uvNYENa0V92/5RUDiIyhHFIdKubVPL0+5jiOtK+sLt/Zw== X-Gm-Message-State: AOJu0YwQqTtlu0USXG0JVMtUl6+T37lxsoyb1DcNTqhoqbvZVuGQei/7 IrggUBFkIm0doXpIx4m9sRqHdkmvqEomxhPmD2swyq/+a5ODQWnw9QWDB3f+oW0= X-Google-Smtp-Source: AGHT+IH9GEyPJ76wtwNB4/jHWZs7niX/sYQbANa7CsmlIy9vKqofJGQiIZsdI4gRpsE8eF4yskDYXw== X-Received: by 2002:a17:907:845:b0:a59:b376:87b3 with SMTP id a640c23a62f3a-a5a2d6657e1mr2483206366b.62.1716305202032; Tue, 21 May 2024 08:26:42 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b180c7sm1638327666b.221.2024.05.21.08.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 08:26:41 -0700 (PDT) From: Patrick Rudolph To: Patrick Rudolph , Linus Walleij Cc: naresh.solanki@9elements.com, andy.shevchenko@gmail.com, broonie@kernel.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] pinctrl: cy8c95x0: Use REGCACHE_MAPLE Date: Tue, 21 May 2024 17:25:59 +0200 Message-ID: <20240521152602.1097764-3-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240521152602.1097764-1-patrick.rudolph@9elements.com> References: <20240521152602.1097764-1-patrick.rudolph@9elements.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use REGCACHE_MAPLE instead of REGCACHE_FLAT. Signed-off-by: Patrick Rudolph --- drivers/pinctrl/pinctrl-cy8c95x0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c index 9570de598193..4efb8b5cc2d3 100644 --- a/drivers/pinctrl/pinctrl-cy8c95x0.c +++ b/drivers/pinctrl/pinctrl-cy8c95x0.c @@ -457,7 +457,7 @@ static const struct regmap_config cy8c9520_i2c_regmap = { .volatile_reg = cy8c95x0_volatile_register, .precious_reg = cy8c95x0_precious_register, - .cache_type = REGCACHE_FLAT, + .cache_type = REGCACHE_MAPLE, .ranges = NULL, /* Updated at runtime */ .num_ranges = 1, .max_register = 0, /* Updated at runtime */