Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp414494imc; Sun, 10 Mar 2019 09:26:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwicBDxPqwXMFD+N4sotrtPixEaKvlKN5MP3LzSz4/Ff0ur/rbu7vueQfs+f9OdoDswQ+P6 X-Received: by 2002:a65:4348:: with SMTP id k8mr26336650pgq.289.1552235168518; Sun, 10 Mar 2019 09:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552235168; cv=none; d=google.com; s=arc-20160816; b=CVY2FKS2zkTlFZ+2u9a9wtfeeNqM2h+TyWnqCk/dXmGmrS0aYZqyqAOJpZKAAGLYCC mXbVR7/jlgDWQsG1Koc6OU1K3F8C7g4PQ29jHUj2TCKG7Id4043hVTFUmdBrVEIierG8 VFYwuHXOauHGKj0Rr9B1tbCawM1n19ncHq3mA5y1ucCoM8yOshWjgdDOBTFL0vk4znja vFCdmJociST2IJikR28SDZiBLc0TkJCXFE/Y3aIBHu5IxhaYsI9xDxJGPO4b5TaACOL9 +iukpcXEkshMEpJD5xdHx44GVSr/IZwScuo9QdUnp2EOrJosyxUFSGvTqkAlq5FMPRwt BR/g== 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; bh=qjkqpN3RPJL4EmjQby66coAJxJ5NlwESOUu3RRC54mY=; b=Hh+2HoeIZXYXS5u9VK6j7yFEAF5OWd697CXZBSoxi6vxvmzu2ZVPe4V93aaGqESf/Y k/liG7EQ8iCpdl5tt32lLKM1q0LVzp6PRqHeMdnur1s8VeFSFWxUHRhz9cvirbvFly+c y/30fI/0qMqwB6FTosA+L9JVF+ZSDEh7LOGXKP9u9LcQWsMObH4QXgUTf+LVIEXLluhW NbNfGFK6zRBEypLALS6O4UghdLpGT1LVJTfJlUOo2Xw/lCzSpqvvlGcW1y0cZR0erHS8 PbwWy8d9x7kkD3gl02bScGh7nuNR4+6dONZUrVDSybdtpwufLCM/upWdLk9KSOCNRL23 sUFw== ARC-Authentication-Results: i=1; mx.google.com; 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 n7si3080355pgp.400.2019.03.10.09.25.52; Sun, 10 Mar 2019 09:26:08 -0700 (PDT) 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; 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 S1726782AbfCJQZN (ORCPT + 99 others); Sun, 10 Mar 2019 12:25:13 -0400 Received: from shell.v3.sk ([90.176.6.54]:45147 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726703AbfCJQY6 (ORCPT ); Sun, 10 Mar 2019 12:24:58 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 501F9102C8A; Sun, 10 Mar 2019 17:24:54 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id JrSw2Q8yLBll; Sun, 10 Mar 2019 17:24:41 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 206C4102CB3; Sun, 10 Mar 2019 17:24:34 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tgeSt8vosZOo; Sun, 10 Mar 2019 17:24:31 +0100 (CET) Received: from nedofet.lan (ip-89-102-31-34.net.upcbroadband.cz [89.102.31.34]) by zimbra.v3.sk (Postfix) with ESMTPSA id 513F9102CA4; Sun, 10 Mar 2019 17:24:30 +0100 (CET) From: Lubomir Rintel To: Sebastian Reichel Cc: Darren Hart , Rob Herring , Mark Rutland , x86@kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Lubomir Rintel , Andy Shevchenko Subject: [PATCH 06/10] power: supply: olpc_battery: Move priv data to a struct Date: Sun, 10 Mar 2019 17:24:15 +0100 Message-Id: <20190310162419.11861-7-lkundrak@v3.sk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190310162419.11861-1-lkundrak@v3.sk> References: <20190310162419.11861-1-lkundrak@v3.sk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The global variables for private data are not too nice. I'd like some more, and that would clutter the global name space even further. Signed-off-by: Lubomir Rintel Reviewed-by: Andy Shevchenko --- Changes since v4: - Bring some more code that was misplaced here. Changes since v2: - Bring the allocaton of the priv data structure here Changes since v1: - Split out the move to devm_* into a separate patch drivers/power/supply/olpc_battery.c | 78 ++++++++++++++++++----------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/drivers/power/supply/olpc_battery.c b/drivers/power/supply/o= lpc_battery.c index 3dcf5e19f329..f7bb9bedd893 100644 --- a/drivers/power/supply/olpc_battery.c +++ b/drivers/power/supply/olpc_battery.c @@ -53,6 +53,12 @@ =20 #define BAT_ADDR_MFR_TYPE 0x5F =20 +struct olpc_battery_data { + struct power_supply *olpc_ac; + struct power_supply *olpc_bat; + char bat_serial[17]; +}; + /********************************************************************* * Power *********************************************************************/ @@ -91,11 +97,8 @@ static const struct power_supply_desc olpc_ac_desc =3D= { .get_property =3D olpc_ac_get_prop, }; =20 -static struct power_supply *olpc_ac; - -static char bat_serial[17]; /* Ick */ - -static int olpc_bat_get_status(union power_supply_propval *val, uint8_t = ec_byte) +static int olpc_bat_get_status(struct olpc_battery_data *data, + union power_supply_propval *val, uint8_t ec_byte) { if (olpc_platform_info.ecver > 0x44) { if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE)) @@ -326,6 +329,7 @@ static int olpc_bat_get_property(struct power_supply = *psy, enum power_supply_property psp, union power_supply_propval *val) { + struct olpc_battery_data *data =3D power_supply_get_drvdata(psy); int ret =3D 0; __be16 ec_word; uint8_t ec_byte; @@ -347,7 +351,7 @@ static int olpc_bat_get_property(struct power_supply = *psy, =20 switch (psp) { case POWER_SUPPLY_PROP_STATUS: - ret =3D olpc_bat_get_status(val, ec_byte); + ret =3D olpc_bat_get_status(data, val, ec_byte); if (ret) return ret; break; @@ -450,8 +454,8 @@ static int olpc_bat_get_property(struct power_supply = *psy, if (ret) return ret; =20 - sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf)); - val->strval =3D bat_serial; + sprintf(data->bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf)); + val->strval =3D data->bat_serial; break; case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: ret =3D olpc_bat_get_voltage_max_design(val); @@ -579,17 +583,17 @@ static struct power_supply_desc olpc_bat_desc =3D { .use_for_apm =3D 1, }; =20 -static struct power_supply *olpc_bat; - static int olpc_battery_suspend(struct platform_device *pdev, pm_message_t state) { - if (device_may_wakeup(&olpc_ac->dev)) + struct olpc_battery_data *data =3D platform_get_drvdata(pdev); + + if (device_may_wakeup(&data->olpc_ac->dev)) olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR); else olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR); =20 - if (device_may_wakeup(&olpc_bat->dev)) + if (device_may_wakeup(&data->olpc_bat->dev)) olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC | EC_SCI_SRC_BATERR); else @@ -601,8 +605,15 @@ static int olpc_battery_suspend(struct platform_devi= ce *pdev, =20 static int olpc_battery_probe(struct platform_device *pdev) { - int ret; + struct power_supply_config psy_cfg =3D {}; + struct olpc_battery_data *data; uint8_t status; + int ret; + + data =3D devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + platform_set_drvdata(pdev, data); =20 /* * We've seen a number of EC protocol changes; this driver requires @@ -620,9 +631,13 @@ static int olpc_battery_probe(struct platform_device= *pdev) =20 /* Ignore the status. It doesn't actually matter */ =20 - olpc_ac =3D power_supply_register(&pdev->dev, &olpc_ac_desc, NULL); - if (IS_ERR(olpc_ac)) - return PTR_ERR(olpc_ac); + psy_cfg.of_node =3D pdev->dev.of_node; + psy_cfg.drv_data =3D data; + + data->olpc_ac =3D power_supply_register(&pdev->dev, &olpc_ac_desc, &psy= _cfg); + if (IS_ERR(data->olpc_ac)) + return PTR_ERR(data->olpc_ac); + if (of_device_is_compatible(pdev->dev.of_node, "olpc,xo1.5-battery")) { /* XO-1.5 */ olpc_bat_desc.properties =3D olpc_xo15_bat_props; @@ -633,42 +648,45 @@ static int olpc_battery_probe(struct platform_devic= e *pdev) olpc_bat_desc.num_properties =3D ARRAY_SIZE(olpc_xo1_bat_props); } =20 - olpc_bat =3D power_supply_register(&pdev->dev, &olpc_bat_desc, NULL); - if (IS_ERR(olpc_bat)) { - ret =3D PTR_ERR(olpc_bat); + data->olpc_bat =3D power_supply_register(&pdev->dev, &olpc_bat_desc, &p= sy_cfg); + if (IS_ERR(data->olpc_bat)) { + ret =3D PTR_ERR(data->olpc_bat); goto battery_failed; } =20 - ret =3D device_create_bin_file(&olpc_bat->dev, &olpc_bat_eeprom); + ret =3D device_create_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom); if (ret) goto eeprom_failed; =20 - ret =3D device_create_file(&olpc_bat->dev, &olpc_bat_error); + ret =3D device_create_file(&data->olpc_bat->dev, &olpc_bat_error); if (ret) goto error_failed; =20 if (olpc_ec_wakeup_available()) { - device_set_wakeup_capable(&olpc_ac->dev, true); - device_set_wakeup_capable(&olpc_bat->dev, true); + device_set_wakeup_capable(&data->olpc_ac->dev, true); + device_set_wakeup_capable(&data->olpc_bat->dev, true); } =20 return 0; =20 error_failed: - device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom); + device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom); eeprom_failed: - power_supply_unregister(olpc_bat); + power_supply_unregister(data->olpc_bat); battery_failed: - power_supply_unregister(olpc_ac); + power_supply_unregister(data->olpc_ac); return ret; } =20 static int olpc_battery_remove(struct platform_device *pdev) { - device_remove_file(&olpc_bat->dev, &olpc_bat_error); - device_remove_bin_file(&olpc_bat->dev, &olpc_bat_eeprom); - power_supply_unregister(olpc_bat); - power_supply_unregister(olpc_ac); + struct olpc_battery_data *data =3D platform_get_drvdata(pdev); + + device_remove_file(&data->olpc_bat->dev, &olpc_bat_error); + device_remove_bin_file(&data->olpc_bat->dev, &olpc_bat_eeprom); + power_supply_unregister(data->olpc_bat); + power_supply_unregister(data->olpc_ac); + return 0; } =20 --=20 2.20.1