Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3501195ybl; Sun, 12 Jan 2020 19:54:50 -0800 (PST) X-Google-Smtp-Source: APXvYqyE/Y+YFMQ9fZoghTqwpOqIzvEziemc9D+xF1bSS3y6FsMzVDTFhRhFT48LyqmEGHaA5Bc5 X-Received: by 2002:aca:5e02:: with SMTP id s2mr10958151oib.80.1578887690288; Sun, 12 Jan 2020 19:54:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578887690; cv=none; d=google.com; s=arc-20160816; b=gyh8O3rN7brebopLIBOO4QI66/bNCmTzv/CrhUK1hxB4TpTM/+KgTmZcy53U5YcHgh UYgBKofCMtNQ45lwdM8OQ5J3O7N2IS7py239K64ue/a4V5Mw19rx5jKC+tHwoiIDIbCS VNPcUuXfnkOvCSY2LLnyKMEnkiPU/6ucrYJpZTTsh0T8Gk7GqCDBuJ2reZ6FO/kjR+Jk lSWGgDcwYVAF2pnYrJ9AzK5g/xm6LtW40KiojkdhIo6ODO9YUg8TPVRvqSKUp1WBRZrZ vGyaXwwGVJxsnpl7NwRbeF+DMDpTNvoSz10jWcDatF2KNSgI2VOnIoHuIfGymD55Rh+n Ccfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=tP5rdRHswnvAAe51NTPo8tR712TUgFQuWQxKZmMe5GM=; b=06i1cXokZI7t1gAwYAYKdX/G9QAgZu/Co6A/MysoJ2qdr4jxoXGcQ1QW0gd+ont7Li FyL68JNZny2hmW0EIG+R+kDw/jfk4OZ/QMsjXqSSXMwWVLjhgt4z+yRfRazUhvYFuXux kDQoSOHIvbgWT/wKMuuPeb9scQgNEkdtSEXX69fM2FvHJzrdI30zloDraKIUlCrCyiZG WHI/4ndFR/CPEjMUn7/Qu8GwhYjyze8nptsCL1JrpgjQV3Cnhatd5tf0hdfsKgQkwgbJ VKxI6Po4iszX0PSaSSRBhHYWaDc+ykkZjflfXBfdSez7VudhnHxhyms1TNq65r2xDr+0 utBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm1 header.b=dKF9CSdd; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=KGIeyTaq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y186si5603664oig.241.2020.01.12.19.54.39; Sun, 12 Jan 2020 19:54:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sholland.org header.s=fm1 header.b=dKF9CSdd; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=KGIeyTaq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387635AbgAMDx2 (ORCPT + 99 others); Sun, 12 Jan 2020 22:53:28 -0500 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:53963 "EHLO out2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387554AbgAMDxO (ORCPT ); Sun, 12 Jan 2020 22:53:14 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id CDFFC21E29; Sun, 12 Jan 2020 22:53:13 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Sun, 12 Jan 2020 22:53:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=tP5rdRHswnvAA e51NTPo8tR712TUgFQuWQxKZmMe5GM=; b=dKF9CSddxudc3ArQ7N7yOy3739ZQJ LY54BQL5YP38nE0tk4+NTHjhg2GSgX1rHaYs15n+3WGX6XiSToF55/E6Q3um/Okk 5M4dGCsqUWF0y5MENJkU17+A4DTQT0wbklv5zn4qFvvTcgVdhEnbHkNppQeTjdQk yXfXT5lyRVHJRLBknLe3gZ+upolcCusdF+hXusdDWPIH+s8Vj7Vcre4ZWdvD95c3 eWNZLIpMzKEKkmavz7Npa5cYEMFPYI5t6E8n8aNqRy6TFBkn73cPIjnC6jSgJlq+ lwUpV6hml+uX1krmX+YQ8DQlIDfXvfu480LgmRwSj/FTH1apyBZVUHCgw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=tP5rdRHswnvAAe51NTPo8tR712TUgFQuWQxKZmMe5GM=; b=KGIeyTaq 1pTiu6ChPeR5OMz+DByjMiilJUFMV8eFnBsgwZ8BsniZSA3WIRXhyGM/jATr4qtX oxAHN1GDYNqSOj+wtTzjkz1P/WHDW6JTWxXhgvi/ivOma5NE7whEKQ6EaKKJx88l BPKgd0VYdPjupYK4OFO5vb6v/px2rVYsfh06F0SRrYWAaFPQgWi0UFKLGRUUw/q9 KHCgM4qR/bx4qrfdJL0b2ZvU11uuQrUMZiEEgem0IOXwYFbho79scLdXwXteNeFs qYgwycTnsDSSC+HgVXAwg32E1AKAQQbuSNy6t5yjgnRtUPcIq69xFny/M5iqFIMU m96mW0rlrGNOaQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdeiledgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucfkph epjedtrddufeehrddugeekrdduhedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehsrghm uhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from titanium.stl.sholland.net (70-135-148-151.lightspeed.stlsmo.sbcglobal.net [70.135.148.151]) by mail.messagingengine.com (Postfix) with ESMTPA id 410638005C; Sun, 12 Jan 2020 22:53:13 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Sebastian Reichel , Oskari Lemmela Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Samuel Holland Subject: [PATCH v3 5/8] power: supply: axp20x_usb_power: Use a match structure Date: Sun, 12 Jan 2020 21:53:07 -0600 Message-Id: <20200113035310.18950-6-samuel@sholland.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200113035310.18950-1-samuel@sholland.org> References: <20200113035310.18950-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of ad-hoc variant ID checks throughout the code, let's start moving the variant-specific details to a match structure. This allows for future flexibility, and it better matches the other axp20x power supply drivers. This commit removes most variant checks from axp20x_usb_power_probe(). Other parts of the driver still do ID matching; they are left unchanged for now. Signed-off-by: Samuel Holland --- drivers/power/supply/axp20x_usb_power.c | 86 ++++++++++++++++--------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 2573de2a0adc..cd89ee12dd18 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -403,6 +403,50 @@ static const struct power_supply_desc axp22x_usb_power_desc = { .set_property = axp20x_usb_power_set_property, }; +static const char * const axp20x_irq_names[] = { + "VBUS_PLUGIN", + "VBUS_REMOVAL", + "VBUS_VALID", + "VBUS_NOT_VALID", + NULL +}; + +static const char * const axp22x_irq_names[] = { + "VBUS_PLUGIN", + "VBUS_REMOVAL", + NULL +}; + +struct axp_data { + const struct power_supply_desc *power_desc; + const char * const *irq_names; + enum axp20x_variants axp20x_id; +}; + +static const struct axp_data axp202_data = { + .power_desc = &axp20x_usb_power_desc, + .irq_names = axp20x_irq_names, + .axp20x_id = AXP202_ID, +}; + +static const struct axp_data axp221_data = { + .power_desc = &axp22x_usb_power_desc, + .irq_names = axp22x_irq_names, + .axp20x_id = AXP221_ID, +}; + +static const struct axp_data axp223_data = { + .power_desc = &axp22x_usb_power_desc, + .irq_names = axp22x_irq_names, + .axp20x_id = AXP223_ID, +}; + +static const struct axp_data axp813_data = { + .power_desc = &axp22x_usb_power_desc, + .irq_names = axp22x_irq_names, + .axp20x_id = AXP813_ID, +}; + static int configure_iio_channels(struct platform_device *pdev, struct axp20x_usb_power *power) { @@ -438,12 +482,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); struct power_supply_config psy_cfg = {}; struct axp20x_usb_power *power; - static const char * const axp20x_irq_names[] = { "VBUS_PLUGIN", - "VBUS_REMOVAL", "VBUS_VALID", "VBUS_NOT_VALID", NULL }; - static const char * const axp22x_irq_names[] = { - "VBUS_PLUGIN", "VBUS_REMOVAL", NULL }; - const char * const *irq_names; - const struct power_supply_desc *usb_power_desc; + const struct axp_data *axp_data; int i, irq, ret; if (!of_device_is_available(pdev->dev.of_node)) @@ -459,9 +498,9 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return -ENOMEM; platform_set_drvdata(pdev, power); - power->axp20x_id = (enum axp20x_variants)of_device_get_match_data( - &pdev->dev); + axp_data = of_device_get_match_data(&pdev->dev); + power->axp20x_id = axp_data->axp20x_id; power->regmap = axp20x->regmap; if (power->axp20x_id == AXP202_ID) { @@ -479,34 +518,23 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (ret) return ret; - - usb_power_desc = &axp20x_usb_power_desc; - irq_names = axp20x_irq_names; - } else if (power->axp20x_id == AXP221_ID || - power->axp20x_id == AXP223_ID || - power->axp20x_id == AXP813_ID) { - usb_power_desc = &axp22x_usb_power_desc; - irq_names = axp22x_irq_names; - } else { - dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n", - axp20x->variant); - return -EINVAL; } psy_cfg.of_node = pdev->dev.of_node; psy_cfg.drv_data = power; - power->supply = devm_power_supply_register(&pdev->dev, usb_power_desc, + power->supply = devm_power_supply_register(&pdev->dev, + axp_data->power_desc, &psy_cfg); if (IS_ERR(power->supply)) return PTR_ERR(power->supply); /* Request irqs after registering, as irqs may trigger immediately */ - for (i = 0; irq_names[i]; i++) { - irq = platform_get_irq_byname(pdev, irq_names[i]); + for (i = 0; axp_data->irq_names[i]; i++) { + irq = platform_get_irq_byname(pdev, axp_data->irq_names[i]); if (irq < 0) { dev_warn(&pdev->dev, "No IRQ for %s: %d\n", - irq_names[i], irq); + axp_data->irq_names[i], irq); continue; } irq = regmap_irq_get_virq(axp20x->regmap_irqc, irq); @@ -514,7 +542,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) axp20x_usb_power_irq, 0, DRVNAME, power); if (ret < 0) dev_warn(&pdev->dev, "Error requesting %s IRQ: %d\n", - irq_names[i], ret); + axp_data->irq_names[i], ret); } INIT_DELAYED_WORK(&power->vbus_detect, axp20x_usb_power_poll_vbus); @@ -536,16 +564,16 @@ static int axp20x_usb_power_remove(struct platform_device *pdev) static const struct of_device_id axp20x_usb_power_match[] = { { .compatible = "x-powers,axp202-usb-power-supply", - .data = (void *)AXP202_ID, + .data = &axp202_data, }, { .compatible = "x-powers,axp221-usb-power-supply", - .data = (void *)AXP221_ID, + .data = &axp221_data, }, { .compatible = "x-powers,axp223-usb-power-supply", - .data = (void *)AXP223_ID, + .data = &axp223_data, }, { .compatible = "x-powers,axp813-usb-power-supply", - .data = (void *)AXP813_ID, + .data = &axp813_data, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, axp20x_usb_power_match); -- 2.23.0