The power supply interface changes in Linux 4.1, which requires to
changes to all drivers which make use of it. The upstream commit which
did this (297d716) was not on Jiri's branch, which is why we didn't
notice it until just now. In addition to the changes made by that patch,
Linus had to resolve several merge issues (8de29a3) caused by changes to
our driver's use of the power supply.

This patch rolls up both sets of changes into one and adds the necessary
preprocessor guards to keep things working with earlier kernels.

Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
---
 3.17/wacom.h     | 17 +++++++++++++
 3.17/wacom_sys.c | 77 ++++++++++++++++++++++++++++++++++++++++----------------
 3.17/wacom_wac.c |  8 +++---
 3 files changed, 76 insertions(+), 26 deletions(-)

diff --git a/3.17/wacom.h b/3.17/wacom.h
index 9e34d5d..4eb26c3 100644
--- a/3.17/wacom.h
+++ b/3.17/wacom.h
@@ -106,6 +106,16 @@
 #define USB_VENDOR_ID_WACOM    0x056a
 #define USB_VENDOR_ID_LENOVO   0x17ef
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+#define WACOM_POWERSUPPLY_DEVICE(ps) (ps)
+#define WACOM_POWERSUPPLY_REF(ps) (ps)
+#define WACOM_POWERSUPPLY_DESC(ps) (ps##_desc)
+#else
+#define WACOM_POWERSUPPLY_DEVICE(ps) ((ps).dev)
+#define WACOM_POWERSUPPLY_REF(ps) (&(ps))
+#define WACOM_POWERSUPPLY_DESC(ps) (ps)
+#endif
+
 struct wacom {
        struct usb_device *usbdev;
        struct usb_interface *intf;
@@ -120,8 +130,15 @@ struct wacom {
                u8 img_lum;   /* OLED matrix display brightness */
        } led;
        bool led_initialized;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+       struct power_supply *battery;
+       struct power_supply *ac;
+       struct power_supply_desc battery_desc;
+       struct power_supply_desc ac_desc;
+#else
        struct power_supply battery;
        struct power_supply ac;
+#endif
 };
 
 static inline void wacom_schedule_work(struct wacom_wac *wacom_wac)
diff --git a/3.17/wacom_sys.c b/3.17/wacom_sys.c
index 2fb6fa9..4189c46 100644
--- a/3.17/wacom_sys.c
+++ b/3.17/wacom_sys.c
@@ -961,7 +961,11 @@ static int wacom_battery_get_property(struct power_supply 
*psy,
                                      enum power_supply_property psp,
                                      union power_supply_propval *val)
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+       struct wacom *wacom = power_supply_get_drvdata(psy);
+#else
        struct wacom *wacom = container_of(psy, struct wacom, battery);
+#endif
        int ret = 0;
 
        switch (psp) {
@@ -998,7 +1002,11 @@ static int wacom_ac_get_property(struct power_supply *psy,
                                enum power_supply_property psp,
                                union power_supply_propval *val)
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+       struct wacom *wacom = power_supply_get_drvdata(psy);
+#else
        struct wacom *wacom = container_of(psy, struct wacom, ac);
+#endif
        int ret = 0;
 
        switch (psp) {
@@ -1021,41 +1029,66 @@ static int wacom_initialize_battery(struct wacom *wacom)
 {
        static atomic_t battery_no = ATOMIC_INIT(0);
        int error;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+       struct power_supply_config psy_cfg = { .drv_data = wacom, };
+#endif
        unsigned long n;
 
        if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
                n = atomic_inc_return(&battery_no) - 1;
 
-               wacom->battery.properties = wacom_battery_props;
-               wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
-               wacom->battery.get_property = wacom_battery_get_property;
+               WACOM_POWERSUPPLY_DESC(wacom->battery).properties = 
wacom_battery_props;
+               WACOM_POWERSUPPLY_DESC(wacom->battery).num_properties = 
ARRAY_SIZE(wacom_battery_props);
+               WACOM_POWERSUPPLY_DESC(wacom->battery).get_property = 
wacom_battery_get_property;
                sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
-               wacom->battery.name = wacom->wacom_wac.bat_name;
-               wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
-               wacom->battery.use_for_apm = 0;
+               WACOM_POWERSUPPLY_DESC(wacom->battery).name = 
wacom->wacom_wac.bat_name;
+               WACOM_POWERSUPPLY_DESC(wacom->battery).type = 
POWER_SUPPLY_TYPE_BATTERY;
+               WACOM_POWERSUPPLY_DESC(wacom->battery).use_for_apm = 0;
 
-               wacom->ac.properties = wacom_ac_props;
-               wacom->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
-               wacom->ac.get_property = wacom_ac_get_property;
+               WACOM_POWERSUPPLY_DESC(wacom->ac).properties = wacom_ac_props;
+               WACOM_POWERSUPPLY_DESC(wacom->ac).num_properties = 
ARRAY_SIZE(wacom_ac_props);
+               WACOM_POWERSUPPLY_DESC(wacom->ac).get_property = 
wacom_ac_get_property;
                sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
-               wacom->ac.name = wacom->wacom_wac.ac_name;
-               wacom->ac.type = POWER_SUPPLY_TYPE_MAINS;
-               wacom->ac.use_for_apm = 0;
-
+               WACOM_POWERSUPPLY_DESC(wacom->ac).name = 
wacom->wacom_wac.ac_name;
+               WACOM_POWERSUPPLY_DESC(wacom->battery).type = 
POWER_SUPPLY_TYPE_MAINS;
+               WACOM_POWERSUPPLY_DESC(wacom->battery).use_for_apm = 0;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+               wacom->battery = power_supply_register(&wacom->hdev->dev,
+                                                      
&WACOM_POWERSUPPLY_DESC(wacom->battery),
+                                                      &psy_cfg);
+               if (IS_ERR(wacom->battery))
+                       return PTR_ERR(wacom->battery);
+#else
                error = power_supply_register(&wacom->hdev->dev,
                                              &wacom->battery);
+
                if (error)
                        return error;
+#endif
 
-               power_supply_powers(&wacom->battery, &wacom->hdev->dev);
+               power_supply_powers(WACOM_POWERSUPPLY_REF(wacom->battery), 
&wacom->hdev->dev);
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,1,0)
+               wacom->ac = power_supply_register(&wacom->hdev->dev,
+                                                 
&WACOM_POWERSUPPLY_DESC(wacom->ac),
+                                                 &psy_cfg
+                       );
+
+               if (IS_ERR(wacom->ac)) {
+                       power_supply_unregister(wacom->battery);
+                       return PTR_ERR(wacom->ac);
+               }
+#else
                error = power_supply_register(&wacom->hdev->dev, &wacom->ac);
+
                if (error) {
                        power_supply_unregister(&wacom->battery);
                        return error;
                }
+#endif
 
-               power_supply_powers(&wacom->ac, &wacom->hdev->dev);
+               power_supply_powers(WACOM_POWERSUPPLY_REF(wacom->ac), 
&wacom->hdev->dev);
        }
 
        return 0;
@@ -1063,11 +1096,11 @@ static int wacom_initialize_battery(struct wacom *wacom)
 
 static void wacom_destroy_battery(struct wacom *wacom)
 {
-       if (wacom->battery.dev) {
-               power_supply_unregister(&wacom->battery);
-               wacom->battery.dev = NULL;
-               power_supply_unregister(&wacom->ac);
-               wacom->ac.dev = NULL;
+       if (WACOM_POWERSUPPLY_DEVICE(wacom->battery)) {
+               power_supply_unregister(WACOM_POWERSUPPLY_REF(wacom->battery));
+               WACOM_POWERSUPPLY_DEVICE(wacom->battery) = NULL;
+               power_supply_unregister(WACOM_POWERSUPPLY_REF(wacom->ac));
+               WACOM_POWERSUPPLY_DEVICE(wacom->ac) = NULL;
        }
 }
 
@@ -1339,11 +1372,11 @@ void wacom_battery_work(struct work_struct *work)
        struct wacom *wacom = container_of(work, struct wacom, work);
 
        if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
-            !wacom->battery.dev) {
+            !WACOM_POWERSUPPLY_DEVICE(wacom->battery)) {
                wacom_initialize_battery(wacom);
        }
        else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
-                wacom->battery.dev) {
+                WACOM_POWERSUPPLY_DEVICE(wacom->battery)) {
                wacom_destroy_battery(wacom);
        }
 }
diff --git a/3.17/wacom_wac.c b/3.17/wacom_wac.c
index 5b8e718..f4a8215 100644
--- a/3.17/wacom_wac.c
+++ b/3.17/wacom_wac.c
@@ -65,8 +65,8 @@ static void wacom_notify_battery(struct wacom_wac *wacom_wac,
                wacom_wac->bat_connected = bat_connected;
                wacom_wac->ps_connected = ps_connected;
 
-               if (wacom->battery.dev)
-                       power_supply_changed(&wacom->battery);
+               if (WACOM_POWERSUPPLY_DEVICE(wacom->battery))
+                       
power_supply_changed(WACOM_POWERSUPPLY_REF(wacom->battery));
        }
 }
 
@@ -1995,7 +1995,7 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, 
size_t len)
                wacom_notify_battery(wacom_wac, battery, charging,
                                     battery || charging, 1);
 
-               if (!wacom->battery.dev &&
+               if (!WACOM_POWERSUPPLY_DEVICE(wacom->battery) &&
                    !(features->quirks & WACOM_QUIRK_BATTERY)) {
                        features->quirks |= WACOM_QUIRK_BATTERY;
                        INIT_WORK(&wacom->work, wacom_battery_work);
@@ -2003,7 +2003,7 @@ static int wacom_status_irq(struct wacom_wac *wacom_wac, 
size_t len)
                }
        }
        else if ((features->quirks & WACOM_QUIRK_BATTERY) &&
-                wacom->battery.dev) {
+                WACOM_POWERSUPPLY_DEVICE(wacom->battery)) {
                features->quirks &= ~WACOM_QUIRK_BATTERY;
                INIT_WORK(&wacom->work, wacom_battery_work);
                wacom_schedule_work(wacom_wac);
-- 
2.4.0


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to