Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2338680rdb; Wed, 21 Feb 2024 04:53:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVe5zR5ypx6X7Bo4OOIQc9VkLXKBhGJXEsrRWRKNgTVU/gEYsesJ54rDX66vba6FHiiBjOKJXaFGywgQ5sNjYRsgA9ZXFoNaTvcirHHeQ== X-Google-Smtp-Source: AGHT+IGCE1EnhHrcccxXyMhK7cqxxXznFh5GESrxJ/maGSwQ3+9O8oBSmo2MQJdwXeMeHzxnZJfX X-Received: by 2002:a05:620a:568e:b0:785:d857:2190 with SMTP id wg14-20020a05620a568e00b00785d8572190mr20482990qkn.64.1708520012438; Wed, 21 Feb 2024 04:53:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708520012; cv=pass; d=google.com; s=arc-20160816; b=VAcUN/AYGQ2tyWaSnojrVfkiRXjZVWAmIZXBoZaHJiW+HcB22apLoDykCd6Qk58Jfk C4c/EBtffYVniVDJPgNYFuX8ZKXZ2LA/Zz7I24/FLkjrIcW8YTn8CDzGN7avirFQDX4W HiFEM7+eFNUhFpk7ovZPvzcGwZLCeSWNANYPi1ELTXhOCnzf7qdb269KT0xyccAOHUCj zOlNdbfQYkDCEnvkWgTnFDk9Nv90M97k3FSkwNJbWIYu8qFIEKYToBmfxJZcWKWyh54C 4ivQYLursO2PJ0MELwH/yzS2+KwyFm9yZhyNzhP8gqqM7EGkcg1kHdMH7TW9o1LTNz/g y+3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=7oA0fmKcMGpa77tBwzlw1ahRCKvmpIwJPYwf28NyUZ4=; fh=QSjCVSz05M8UG3VtGm4jgAUVl+NBGhzIqTcObXtI5A4=; b=Uiacz+G9uVwvWIG4O7VQdeSSK/1vFQW5LlUVwdjU65uIPEjyd9CEvyrSZwTEHfN+z8 wZi6bMMW6p1pce6HblYzRHc8jIJuFBRvZbsyMXIRLzxRIKQIkx3HXO+r7XiOI4WVmjqM xFq8DAydJL/16pH1QvJn/9DK7094sB3jVBUwX89BKikEpJLrZYF6jNx5XViIJDe49lYR +usElKFQH3KrP//zOGeGtR2dTS9fLQKFVf52sBDTgRJd7sjOOc+Ei5VjYvgTZoWya1t6 oSAj8NWb4TzeZNDLZHI74ENzE1YX9qBPYzRZJ0/CBWvgNjrAfSLRSEP0Q38hExI77aO8 gIBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ucT/n+aO"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-74731-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74731-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z28-20020a05620a08dc00b0078780c9f119si2266255qkz.739.2024.02.21.04.53.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 04:53:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74731-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=@linaro.org header.s=google header.b="ucT/n+aO"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-74731-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74731-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 2202F1C2289B for ; Wed, 21 Feb 2024 12:53:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B21886A8C6; Wed, 21 Feb 2024 12:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ucT/n+aO" 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 DAB406995B for ; Wed, 21 Feb 2024 12:52:53 +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=1708519976; cv=none; b=o0FX3w4OHqwG+jg3Z9wOSWieikOhEWzUGszZ26qAUqmsYIdUbdg+H5mTrzkLkEbyECimOXOwQ8i74BhyiDhxd6bQQImDyCvyE0DDrzAS7anVpY5QU2FUKtyRjdpoO0/R73JABcyWK3dX64CL1MfreTAE0gN36eUOEo0cYY3N4QM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708519976; c=relaxed/simple; bh=xUhXxEB1TSjaY+70YZslQBzXRf4SXFhFlW0PDrTOM4E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qi/DL3Hsmbw8CcRXHvAJbs2KY11B7NpPHpoSooLpXMRv8IT5fMROH0txhKxbQYJDxUdJdvvO+RqqPdC8taBtDjU04RdO8Ie8PubVgCYpx3v4Etj4sffKdSY0BXqUJKWO2sQzeBx6O0J/VFEPTEi6CnF2/AuO7ixZ8ij7eEqfNJY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ucT/n+aO; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a3e5d82ad86so476414566b.2 for ; Wed, 21 Feb 2024 04:52:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708519972; x=1709124772; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7oA0fmKcMGpa77tBwzlw1ahRCKvmpIwJPYwf28NyUZ4=; b=ucT/n+aOXKNM3fXM3Wkf2EQXadte+t+437I+myl4ecZwoHbZkX5cdDT6/s7jdzZFkr 0BjhT1i6rhv/y5lvyaB0dzQTzF0+leZQu5Vqdbrsb/qxnMQ0K/N9A6Bw3JQ1B0ye/SVg YjJO7mixPu8KY9X/LxaHw8UIblntXdMDZVmzyIVZIvhQ3vLeZUgNVQFBNSsk8AqEE2bK CTTKf1erDqDjuE5tKmCzxcflDeoX7b7Uk4smtRMbhFF/Aao97sh4GLrwMc7ryfo9bJf0 8nbZcpZOX/wUbIXmNqwd/aYl0lILIdP5rRlJ+N1mc4N6RN10NCHSjAlC1GECe0md+nJV CDmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708519972; x=1709124772; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7oA0fmKcMGpa77tBwzlw1ahRCKvmpIwJPYwf28NyUZ4=; b=mK5XRh+1IisV7XFg+9evhS4GFxAVrMzdmhu2u7y0A1p+ZtiU+ffkU3JXuSgKbGojDR EQFCKbfHF1kDPmZXcR6bkoqH+jJaQBGcvD9dEHY3/u55S7RKKK1bPBA9uyy0mb76v7C/ uMQzAg/0JEBf6vh+vYhDonbqYIdv8sw9UooSd/VAxRbmPcWRs1uuf32xCkdCbIQesTqO OCtlYmbjzy+OYHYCBu13Yd4MVo8861g9v/1ocsZRJjYdSAB212Tr4Fd/xCdny7nd3g/q aSQCwijwlAHVIjCJCKGs4nn8xogkosDo0D8V+vaQoKTiX90xRCELGpYf7Zip929oAeZX AWKg== X-Forwarded-Encrypted: i=1; AJvYcCWvwWKqFzehVFONScU9zKqOl4xhsEi5zavzre19ELoih4BjCzqQ1m4umdzKXOP8ZDwZOMCJGVCIVZA2tQ+I40qUqBMOOu+80iSbLn2y X-Gm-Message-State: AOJu0YwAJHwd74FwGNsxI6T2pmfGIvqt+wZGz2QMc6qEooXTa9IzVZED rUXg7B6m9OzQqRVqyz9auHxdEWhIYX8o5zguvIqHZ07mS6+yzpsNxp/e2WY1bHM= X-Received: by 2002:a17:906:e2d0:b0:a3f:f92:ebea with SMTP id gr16-20020a170906e2d000b00a3f0f92ebeamr3876883ejb.5.1708519972322; Wed, 21 Feb 2024 04:52:52 -0800 (PST) Received: from [127.0.1.1] ([188.24.162.93]) by smtp.gmail.com with ESMTPSA id tl23-20020a170907c31700b00a3da5bf34absm4930392ejc.207.2024.02.21.04.52.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 04:52:51 -0800 (PST) From: Abel Vesa Date: Wed, 21 Feb 2024 14:52:38 +0200 Subject: [PATCH v5 2/4] spmi: pmic-arb: Make the APID init a version operation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240221-spmi-multi-master-support-v5-2-3255ca413a0b@linaro.org> References: <20240221-spmi-multi-master-support-v5-0-3255ca413a0b@linaro.org> In-Reply-To: <20240221-spmi-multi-master-support-v5-0-3255ca413a0b@linaro.org> To: Stephen Boyd , Matthias Brugger , Bjorn Andersson , Konrad Dybcio , Dmitry Baryshkov , Neil Armstrong , AngeloGioacchino Del Regno , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Srini Kandagatla , Johan Hovold , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org, Abel Vesa X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=10831; i=abel.vesa@linaro.org; h=from:subject:message-id; bh=xUhXxEB1TSjaY+70YZslQBzXRf4SXFhFlW0PDrTOM4E=; b=owEBbQKS/ZANAwAKARtfRMkAlRVWAcsmYgBl1fIc/LzWkNf2MSvbob5MmWOOzD1tHWKMHm1Rn 4nAP8UdQImJAjMEAAEKAB0WIQRO8+4RTnqPKsqn0bgbX0TJAJUVVgUCZdXyHAAKCRAbX0TJAJUV VtukD/9ZO8SwOLMldVbIUUgf6rJN27VVn/9Z7HqcZLDc8GpELnowT+jl2NvTZKOcdIdLXXWyKdS FmbCUTDyXbivjnHN1L4uLK3j+AyETgD7xkGEMlO6wsmWiN/PqwytOhRQ68UJWkWIoNLx9SqZCTu f+3Y7lHqYX24bZ1eT5NqQsgFJz5i8z+I7L0lFF3PvXswCJhktnMWYTTA2hQSTtLOzu5bKfOpQ8h OEbSVro3oOZmmENUKhuunC6J4wMXG8JQA4VY031Ehf4fUAMSBOPtOLQB2EF14BZcU9+2zpPtQW+ 0VUjogQal8YdO4tC/W3vFmxAihIykE56E6nLcV0L7JMx7xwxcsMPrA1xwaTMH6U8wSLLpkFb3zJ 7DC2YQPMrGpxr4E0wn0gXcGtUKCExU3qZjEYuM9L5lU9OoYSO1LSzwb7H6yQHc3b9A4CsDGLB0C IXpG43flOBMiLfCgwWT9+qVRICXk4pqaai35jyCyO3vJ2EDzhMPWuPooaMz1r3w/SAsCD8OB42E DLuxte0e8ZJz3ER66Jaki4+/0PY+9/rGfBfAxD1PYVMwo577fKP52GdtIe3KBbKwkqO0jAwjDx+ yAz62SNEvqk0r+K/N38Fl1TwOLkmC7Od30tKCtti0Vq07aLjy2tJ5YAjxt80lpSTjzPK/k6axY2 G1SYuhKCrTQZ/jQ== X-Developer-Key: i=abel.vesa@linaro.org; a=openpgp; fpr=6AFF162D57F4223A8770EF5AF7BF214136F41FAE Rather than using conditionals in probe function, add the APID init as a version specific operation. Due to v7, which supports multiple buses, pass on the bus index to be used for sorting out the apid base and count. Signed-off-by: Abel Vesa --- drivers/spmi/spmi-pmic-arb.c | 199 +++++++++++++++++++++++++++---------------- 1 file changed, 124 insertions(+), 75 deletions(-) diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index 9ed1180fe31f..38fed8a585fe 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -183,6 +183,7 @@ struct spmi_pmic_arb { * struct pmic_arb_ver_ops - version dependent functionality. * * @ver_str: version string. + * @init_apid: finds the apid base and count * @ppid_to_apid: finds the apid for a given ppid. * @non_data_cmd: on v1 issues an spmi non-data command. * on v2 no HW support, returns -EOPNOTSUPP. @@ -202,6 +203,7 @@ struct spmi_pmic_arb { */ struct pmic_arb_ver_ops { const char *ver_str; + int (*init_apid)(struct spmi_pmic_arb *pmic_arb, int index); int (*ppid_to_apid)(struct spmi_pmic_arb *pmic_arb, u16 ppid); /* spmi commands (read_cmd, write_cmd, cmd) functionality */ int (*offset)(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, @@ -942,6 +944,38 @@ static int qpnpint_irq_domain_alloc(struct irq_domain *domain, return 0; } +static int pmic_arb_init_apid_min_max(struct spmi_pmic_arb *pmic_arb) +{ + /* + * Initialize max_apid/min_apid to the opposite bounds, during + * the irq domain translation, we are sure to update these + */ + pmic_arb->max_apid = 0; + pmic_arb->min_apid = pmic_arb->max_periphs - 1; + + return 0; +} + +static int pmic_arb_init_apid_v1(struct spmi_pmic_arb *pmic_arb, int index) +{ + u32 *mapping_table; + + if (index) { + dev_err(&pmic_arb->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + + mapping_table = devm_kcalloc(&pmic_arb->spmic->dev, pmic_arb->max_periphs, + sizeof(*mapping_table), GFP_KERNEL); + if (!mapping_table) + return -ENOMEM; + + pmic_arb->mapping_table = mapping_table; + + return pmic_arb_init_apid_min_max(pmic_arb); +} + static int pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pmic_arb, u16 ppid) { u32 *mapping_table = pmic_arb->mapping_table; @@ -1144,6 +1178,40 @@ static int pmic_arb_offset_v2(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, return 0x1000 * pmic_arb->ee + 0x8000 * apid; } +static int pmic_arb_init_apid_v5(struct spmi_pmic_arb *pmic_arb, int index) +{ + int ret; + + if (index) { + dev_err(&pmic_arb->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + + pmic_arb->base_apid = 0; + pmic_arb->apid_count = readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & + PMIC_ARB_FEATURES_PERIPH_MASK; + + if (pmic_arb->base_apid + pmic_arb->apid_count > pmic_arb->max_periphs) { + dev_err(&pmic_arb->spmic->dev, "Unsupported APID count %d detected\n", + pmic_arb->base_apid + pmic_arb->apid_count); + return -EINVAL; + } + + ret = pmic_arb_init_apid_min_max(pmic_arb); + if (ret) + return ret; + + ret = pmic_arb_read_apid_map_v5(pmic_arb); + if (ret) { + dev_err(&pmic_arb->spmic->dev, "could not read APID->PPID mapping table, rc= %d\n", + ret); + return ret; + } + + return 0; +} + /* * v5 offset per ee and per apid for observer channels and per apid for * read/write channels. @@ -1178,6 +1246,49 @@ static int pmic_arb_offset_v5(struct spmi_pmic_arb *pmic_arb, u8 sid, u16 addr, return offset; } +/* + * Only v7 supports 2 buses. Each bus will get a different apid count, read + * from different registers. + */ +static int pmic_arb_init_apid_v7(struct spmi_pmic_arb *pmic_arb, int index) +{ + int ret; + + if (index == 0) { + pmic_arb->base_apid = 0; + pmic_arb->apid_count = readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & + PMIC_ARB_FEATURES_PERIPH_MASK; + } else if (index == 1) { + pmic_arb->base_apid = readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES) & + PMIC_ARB_FEATURES_PERIPH_MASK; + pmic_arb->apid_count = readl_relaxed(pmic_arb->core + PMIC_ARB_FEATURES1) & + PMIC_ARB_FEATURES_PERIPH_MASK; + } else { + dev_err(&pmic_arb->spmic->dev, "Unsupported buses count %d detected\n", + index); + return -EINVAL; + } + + if (pmic_arb->base_apid + pmic_arb->apid_count > pmic_arb->max_periphs) { + dev_err(&pmic_arb->spmic->dev, "Unsupported APID count %d detected\n", + pmic_arb->base_apid + pmic_arb->apid_count); + return -EINVAL; + } + + ret = pmic_arb_init_apid_min_max(pmic_arb); + if (ret) + return ret; + + ret = pmic_arb_read_apid_map_v5(pmic_arb); + if (ret) { + dev_err(&pmic_arb->spmic->dev, "could not read APID->PPID mapping table, rc= %d\n", + ret); + return ret; + } + + return 0; +} + /* * v7 offset per ee and per apid for observer channels and per apid for * read/write channels. @@ -1358,6 +1469,7 @@ pmic_arb_apid_owner_v7(struct spmi_pmic_arb *pmic_arb, u16 n) static const struct pmic_arb_ver_ops pmic_arb_v1 = { .ver_str = "v1", + .init_apid = pmic_arb_init_apid_v1, .ppid_to_apid = pmic_arb_ppid_to_apid_v1, .non_data_cmd = pmic_arb_non_data_cmd_v1, .offset = pmic_arb_offset_v1, @@ -1372,6 +1484,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v1 = { static const struct pmic_arb_ver_ops pmic_arb_v2 = { .ver_str = "v2", + .init_apid = pmic_arb_init_apid_v1, .ppid_to_apid = pmic_arb_ppid_to_apid_v2, .non_data_cmd = pmic_arb_non_data_cmd_v2, .offset = pmic_arb_offset_v2, @@ -1386,6 +1499,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v2 = { static const struct pmic_arb_ver_ops pmic_arb_v3 = { .ver_str = "v3", + .init_apid = pmic_arb_init_apid_v1, .ppid_to_apid = pmic_arb_ppid_to_apid_v2, .non_data_cmd = pmic_arb_non_data_cmd_v2, .offset = pmic_arb_offset_v2, @@ -1400,6 +1514,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v3 = { static const struct pmic_arb_ver_ops pmic_arb_v5 = { .ver_str = "v5", + .init_apid = pmic_arb_init_apid_v5, .ppid_to_apid = pmic_arb_ppid_to_apid_v5, .non_data_cmd = pmic_arb_non_data_cmd_v2, .offset = pmic_arb_offset_v5, @@ -1414,6 +1529,7 @@ static const struct pmic_arb_ver_ops pmic_arb_v5 = { static const struct pmic_arb_ver_ops pmic_arb_v7 = { .ver_str = "v7", + .init_apid = pmic_arb_init_apid_v7, .ppid_to_apid = pmic_arb_ppid_to_apid_v5, .non_data_cmd = pmic_arb_non_data_cmd_v2, .offset = pmic_arb_offset_v7, @@ -1439,7 +1555,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) struct spmi_controller *ctrl; struct resource *res; void __iomem *core; - u32 *mapping_table; u32 channel, ee, hw_ver; int err; @@ -1467,12 +1582,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) pmic_arb->core_size = resource_size(res); - pmic_arb->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID, - sizeof(*pmic_arb->ppid_to_apid), - GFP_KERNEL); - if (!pmic_arb->ppid_to_apid) - return -ENOMEM; - hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); if (hw_ver < PMIC_ARB_VERSION_V2_MIN) { @@ -1506,58 +1615,17 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) return PTR_ERR(pmic_arb->wr_base); } - pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS; + dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n", + pmic_arb->ver_ops->ver_str, hw_ver); - if (hw_ver >= PMIC_ARB_VERSION_V7_MIN) { + if (hw_ver < PMIC_ARB_VERSION_V7_MIN) + pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS; + else pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS_V7; - /* Optional property for v7: */ - of_property_read_u32(pdev->dev.of_node, "qcom,bus-id", - &pmic_arb->bus_instance); - if (pmic_arb->bus_instance > 1) { - dev_err(&pdev->dev, "invalid bus instance (%u) specified\n", - pmic_arb->bus_instance); - return -EINVAL; - } - - if (pmic_arb->bus_instance == 0) { - pmic_arb->base_apid = 0; - pmic_arb->apid_count = - readl_relaxed(core + PMIC_ARB_FEATURES) & - PMIC_ARB_FEATURES_PERIPH_MASK; - } else { - pmic_arb->base_apid = - readl_relaxed(core + PMIC_ARB_FEATURES) & - PMIC_ARB_FEATURES_PERIPH_MASK; - pmic_arb->apid_count = - readl_relaxed(core + PMIC_ARB_FEATURES1) & - PMIC_ARB_FEATURES_PERIPH_MASK; - } - if (pmic_arb->base_apid + pmic_arb->apid_count > pmic_arb->max_periphs) { - dev_err(&pdev->dev, "Unsupported APID count %d detected\n", - pmic_arb->base_apid + pmic_arb->apid_count); - return -EINVAL; - } - } else if (hw_ver >= PMIC_ARB_VERSION_V5_MIN) { - pmic_arb->base_apid = 0; - pmic_arb->apid_count = readl_relaxed(core + PMIC_ARB_FEATURES) & - PMIC_ARB_FEATURES_PERIPH_MASK; - - if (pmic_arb->apid_count > pmic_arb->max_periphs) { - dev_err(&pdev->dev, "Unsupported APID count %d detected\n", - pmic_arb->apid_count); - return -EINVAL; - } - } - - pmic_arb->apid_data = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, - sizeof(*pmic_arb->apid_data), - GFP_KERNEL); - if (!pmic_arb->apid_data) - return -ENOMEM; - - dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n", - pmic_arb->ver_ops->ver_str, hw_ver); + err = pmic_arb->ver_ops->init_apid(pmic_arb, 0); + if (err) + return err; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr"); pmic_arb->intr = devm_ioremap_resource(&ctrl->dev, res); @@ -1599,16 +1667,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) } pmic_arb->ee = ee; - mapping_table = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, - sizeof(*mapping_table), GFP_KERNEL); - if (!mapping_table) - return -ENOMEM; - - pmic_arb->mapping_table = mapping_table; - /* Initialize max_apid/min_apid to the opposite bounds, during - * the irq domain translation, we are sure to update these */ - pmic_arb->max_apid = 0; - pmic_arb->min_apid = pmic_arb->max_periphs - 1; platform_set_drvdata(pdev, ctrl); raw_spin_lock_init(&pmic_arb->lock); @@ -1617,15 +1675,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) ctrl->read_cmd = pmic_arb_read_cmd; ctrl->write_cmd = pmic_arb_write_cmd; - if (hw_ver >= PMIC_ARB_VERSION_V5_MIN) { - err = pmic_arb_read_apid_map_v5(pmic_arb); - if (err) { - dev_err(&pdev->dev, "could not read APID->PPID mapping table, rc= %d\n", - err); - return err; - } - } - dev_dbg(&pdev->dev, "adding irq domain\n"); pmic_arb->domain = irq_domain_add_tree(pdev->dev.of_node, &pmic_arb_irq_domain_ops, pmic_arb); -- 2.34.1