1. 29 8月, 2017 1 次提交
    • H
      power: supply: Add power_supply_set_input_current_limit_from_supplier helper · c3142dd8
      Hans de Goede 提交于
      On some devices the USB Type-C port power (USB PD 2.0) negotiation is
      done by a separate port-controller IC, while the current limit is
      controlled through another (charger) IC.
      
      It has been decided to model this by modelling the external Type-C
      power brick (adapter/charger) as a power-supply class device which
      supplies the charger-IC, with its voltage-now and current-max representing
      the negotiated voltage and max current draw.
      
      This commit adds a power_supply_set_input_current_limit_from_supplier
      helper function which charger power-supply drivers can call to get
      the max-current from their supplier and have this applied
      through their set_property call-back to their input-current-limit.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NSebastian Reichel <sebastian.reichel@collabora.co.uk>
      c3142dd8
  2. 08 6月, 2017 3 次提交
  3. 02 7月, 2016 1 次提交
    • R
      power_supply: fix return value of get_property · e3805385
      Rhyland Klein 提交于
      power_supply_get_property() should ideally return -EAGAIN if it is
      called while the power_supply is being registered. There was no way
      previously to determine if use_cnt == 0 meant that the power_supply
      wasn't fully registered yet, or if it had already been unregistered.
      
      Add a new boolean to the power_supply struct to simply show if
      registration is completed. Lastly, modify the check in
      power_supply_show_property() to also ignore -EAGAIN when so it
      doesn't complain about not returning the property.
      Signed-off-by: NRhyland Klein <rklein@nvidia.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      e3805385
  4. 15 2月, 2016 1 次提交
  5. 10 6月, 2015 2 次提交
    • H
      power: Add devm_power_supply_get_by_phandle() helper function · fe27e1df
      Hans de Goede 提交于
      This commit adds a resource-managed version of the
      power_supply_get_by_phandle() function.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      fe27e1df
    • K
      power_supply: sysfs: Bring back write to writeable properties · 5c6e3a97
      Krzysztof Kozlowski 提交于
      The fix for NULL pointer exception related to calling uevent for not
      finished probe caused to set all writeable properties as non-writeable.
      This was caused by checking if property is writeable before the initial
      increase of power supply usage counter and in the same time using
      wrapper over property_is_writeable(). The wrapper returns ENODEV if the
      usage counter is still 0.
      
      The call trace looked like:
        device probe:
          power_supply_register()
            use_cnt = 0;
            device_add()
              create sysfs entries
                power_supply_attr_is_visible()
                  power_supply_property_is_writeable()
                    if (use_cnt == 0) return -ENODEV;
            use_cnt++;
      
      Replace the usage of wrapper with direct call to property_is_writeable()
      from driver. This should be safe call during device probe because
      implementations of this callback just return 0/1 for different
      properties and they do not access any of the driver's internal data.
      
      Fixes: 8e59c7f2 ("power_supply: Fix NULL pointer dereference during bq27x00_battery probe")
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      5c6e3a97
  6. 21 5月, 2015 1 次提交
    • K
      power_supply: Fix possible NULL pointer dereference on early uevent · 7f1a57fd
      Krzysztof Kozlowski 提交于
      Don't call the power_supply_changed() from power_supply_register() when
      parent is still probing because it may lead to accessing parent too
      early.
      
      In bq27x00_battery this caused NULL pointer exception because uevent of
      power_supply_changed called back the the get_property() method provided
      by the driver. The get_property() method accessed pointer which should
      be returned by power_supply_register().
      
      Starting from bq27x00_battery_probe():
        di->bat = power_supply_register()
          power_supply_changed()
            kobject_uevent()
              power_supply_uevent()
                power_supply_show_property()
                  power_supply_get_property()
                    bq27x00_battery_get_property()
                      dereference of di->bat which is NULL here
      
      The dereference of di->bat (value returned by power_supply_register())
      is the currently visible problem. However calling back the methods
      provided by driver before ending the probe may lead to accessing other
      driver-related data which is not yet initialized.
      
      The call to power_supply_changed() is postponed till probing ends -
      mutex of parent device is released.
      Reported-by: NH. Nikolaus Schaller <hns@goldelico.com>
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Fixes: 297d716f ("power_supply: Change ownership from driver to core")
      Tested-By: NDr. H. Nikolaus Schaller <hns@goldelico.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      7f1a57fd
  7. 14 3月, 2015 5 次提交
    • K
      power_supply: Add power_supply_put for decrementing device reference counter · 1a352462
      Krzysztof Kozlowski 提交于
      The power_supply_get_by_phandle() and power_supply_get_by_name() use
      function class_find_device() for obtaining the reference to power
      supply. Each use of class_find_device() increases the power supply's
      device reference counter.
      
      However the reference counter was not decreased by users of this API.
      Thus final device_unregister() call from power_supply_unregister() could
      not release the device and clean up its resources. This lead to memory
      leak if at least once power_supply_get_by_*() was called between
      registering and unregistering the power supply.
      
      Add and document new API power_supply_put() for decrementing the
      reference counter.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Reviewed-by: NSebastian Reichel <sre@kernel.org>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      1a352462
    • K
      power_supply: Change ownership from driver to core · 297d716f
      Krzysztof Kozlowski 提交于
      Change the ownership of power_supply structure from each driver
      implementing the class to the power supply core.
      
      The patch changes power_supply_register() function thus all drivers
      implementing power supply class are adjusted.
      
      Each driver provides the implementation of power supply. However it
      should not be the owner of power supply class instance because it is
      exposed by core to other subsystems with power_supply_get_by_name().
      These other subsystems have no knowledge when the driver will unregister
      the power supply. This leads to several issues when driver is unbound -
      mostly because user of power supply accesses freed memory.
      
      Instead let the core own the instance of struct 'power_supply'.  Other
      users of this power supply will still access valid memory because it
      will be freed when device reference count reaches 0. Currently this
      means "it will leak" but power_supply_put() call in next patches will
      solve it.
      
      This solves invalid memory references in following race condition
      scenario:
      
      Thread 1: charger manager
      Thread 2: power supply driver, used by charger manager
      
      THREAD 1 (charger manager)         THREAD 2 (power supply driver)
      ==========================         ==============================
      psy = power_supply_get_by_name()
                                         Driver unbind, .remove
                                           power_supply_unregister()
                                           Device fully removed
      psy->get_property()
      
      The 'get_property' call is executed in invalid context because the driver was
      unbound and struct 'power_supply' memory was freed.
      
      This could be observed easily with charger manager driver (here compiled
      with max17040 fuel gauge):
      
      $ cat /sys/devices/virtual/power_supply/cm-battery/capacity &
      $ echo "1-0036" > /sys/bus/i2c/drivers/max17040/unbind
      [   55.725123] Unable to handle kernel NULL pointer dereference at virtual address 00000000
      [   55.732584] pgd = d98d4000
      [   55.734060] [00000000] *pgd=5afa2831, *pte=00000000, *ppte=00000000
      [   55.740318] Internal error: Oops: 80000007 [#1] PREEMPT SMP ARM
      [   55.746210] Modules linked in:
      [   55.749259] CPU: 1 PID: 2936 Comm: cat Tainted: G        W       3.19.0-rc1-next-20141226-00048-gf79f475f3c44-dirty #1496
      [   55.760190] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
      [   55.766270] task: d9b76f00 ti: daf54000 task.ti: daf54000
      [   55.771647] PC is at 0x0
      [   55.774182] LR is at charger_get_property+0x2f4/0x36c
      [   55.779201] pc : [<00000000>]    lr : [<c034b0b4>]    psr: 60000013
      [   55.779201] sp : daf55e90  ip : 00000003  fp : 00000000
      [   55.790657] r10: 00000000  r9 : c06e2878  r8 : d9b26c68
      [   55.795865] r7 : dad81610  r6 : daec7410  r5 : daf55ebc  r4 : 00000000
      [   55.802367] r3 : 00000000  r2 : daf55ebc  r1 : 0000002a  r0 : d9b26c68
      [   55.808879] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
      [   55.815994] Control: 10c5387d  Table: 598d406a  DAC: 00000015
      [   55.821723] Process cat (pid: 2936, stack limit = 0xdaf54210)
      [   55.827451] Stack: (0xdaf55e90 to 0xdaf56000)
      [   55.831795] 5e80:                                     60000013 c01459c4 0000002a c06f8ef8
      [   55.839956] 5ea0: db651000 c06f8ef8 daebac00 c04cb668 daebac08 c0346864 00000000 c01459c4
      [   55.848115] 5ec0: d99eaa80 c06f8ef8 00000fff 00001000 db651000 c027f25c c027f240 d99eaa80
      [   55.856274] 5ee0: d9a06c00 c0146218 daf55f18 00001000 d99eaa80 db4c18c0 00000001 00000001
      [   55.864468] 5f00: daf55f80 c0144c78 c0144c54 c0107f90 00015000 d99eaab0 00000000 00000000
      [   55.872603] 5f20: 000051c7 00000000 db4c18c0 c04a9370 00015000 00001000 daf55f80 00001000
      [   55.880763] 5f40: daf54000 00015000 00000000 c00e53dc db4c18c0 c00e548c 0000000d 00008124
      [   55.888937] 5f60: 00000001 00000000 00000000 db4c18c0 db4c18c0 00001000 00015000 c00e5550
      [   55.897099] 5f80: 00000000 00000000 00001000 00001000 00015000 00000003 00000003 c000f364
      [   55.905239] 5fa0: 00000000 c000f1a0 00001000 00015000 00000003 00015000 00001000 0001333c
      [   55.913399] 5fc0: 00001000 00015000 00000003 00000003 00000002 00000000 00000000 00000000
      [   55.921560] 5fe0: 7fffe000 be999850 0000a225 b6f3c19c 60000010 00000003 00000000 00000000
      [   55.929744] [<c034b0b4>] (charger_get_property) from [<c0346864>] (power_supply_show_property+0x48/0x20c)
      [   55.939286] [<c0346864>] (power_supply_show_property) from [<c027f25c>] (dev_attr_show+0x1c/0x48)
      [   55.948130] [<c027f25c>] (dev_attr_show) from [<c0146218>] (sysfs_kf_seq_show+0x84/0x104)
      [   55.956298] [<c0146218>] (sysfs_kf_seq_show) from [<c0144c78>] (kernfs_seq_show+0x24/0x28)
      [   55.964536] [<c0144c78>] (kernfs_seq_show) from [<c0107f90>] (seq_read+0x1b0/0x484)
      [   55.972172] [<c0107f90>] (seq_read) from [<c00e53dc>] (__vfs_read+0x18/0x4c)
      [   55.979188] [<c00e53dc>] (__vfs_read) from [<c00e548c>] (vfs_read+0x7c/0x100)
      [   55.986304] [<c00e548c>] (vfs_read) from [<c00e5550>] (SyS_read+0x40/0x8c)
      [   55.993164] [<c00e5550>] (SyS_read) from [<c000f1a0>] (ret_fast_syscall+0x0/0x48)
      [   56.000626] Code: bad PC value
      [   56.011652] ---[ end trace 7b64343fbdae8ef1 ]---
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      
      [for the nvec part]
      Reviewed-by: NMarc Dietrich <marvin24@gmx.de>
      
      [for compal-laptop.c]
      Acked-by: NDarren Hart <dvhart@linux.intel.com>
      
      [for the mfd part]
      Acked-by: NLee Jones <lee.jones@linaro.org>
      
      [for the hid part]
      Acked-by: NJiri Kosina <jkosina@suse.cz>
      
      [for the acpi part]
      Acked-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      297d716f
    • K
      power_supply: Add API for safe access of power supply function attrs · bc154056
      Krzysztof Kozlowski 提交于
      Add simple wrappers for accessing power supply's function attributes:
       - get_property -> power_supply_get_property
       - set_property -> power_supply_set_property
       - property_is_writeable -> power_supply_property_is_writeable
       - external_power_changed -> power_supply_external_power_changed
      
      This API along with atomic usage counter adds a safe way of accessing a
      power supply from another driver. If power supply is unregistered after
      obtaining reference to it by some driver, then the API wrappers won't be
      executed in invalid (freed) context.
      
      Next patch changing the ownership of power supply class is still needed
      to fully fix race conditions in accessing freed power supply.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Reviewed-by: NSebastian Reichel <sre@kernel.org>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      bc154056
    • K
      power_supply: Move run-time configuration to separate structure · 2dc9215d
      Krzysztof Kozlowski 提交于
      Add new structure 'power_supply_config' for holding run-time
      initialization data like of_node, supplies and private driver data.
      
      The power_supply_register() function is changed so all power supply
      drivers need updating.
      
      When registering the power supply this new 'power_supply_config' should be
      used instead of directly initializing 'struct power_supply'. This allows
      changing the ownership of power_supply structure from driver to the
      power supply core in next patches.
      
      When a driver does not use of_node or supplies then it should use NULL
      as config. If driver uses of_node or supplies then it should allocate
      config on stack and initialize it with proper values.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      
      [for the nvec part]
      Reviewed-by: NMarc Dietrich <marvin24@gmx.de>
      
      [for drivers/platform/x86/compal-laptop.c]
      Reviewed-by: NDarren Hart <dvhart@linux.intel.com>
      
      [for drivers/hid/*]
      Reviewed-by: NJiri Kosina <jkosina@suse.cz>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      2dc9215d
    • K
      power_supply: Add driver private data · e44ea364
      Krzysztof Kozlowski 提交于
      Allow drivers to store private data inside power_supply structure for
      later usage in power supply operations.
      
      Usage of driver private data is necessary to access driver's state
      container object from power supply calls (like get_property()) if struct
      'power_supply' is a stored there as a pointer, for example:
      
      struct some_driver_info {
      	struct i2c_client       *client;
      	struct power_supply     *power_supply;
      	...
      }
      
      In such case one cannot use container_of() and must store pointer to
      state container as private data.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Reviewed-by: NBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
      Reviewed-by: NSebastian Reichel <sre@kernel.org>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      e44ea364
  8. 26 2月, 2015 1 次提交
  9. 28 10月, 2014 1 次提交
    • K
      power_supply: Add no_thermal property to prevent recursive get_temp calls · a69d82b9
      Krzysztof Kozlowski 提交于
      Add a 'no_thermal' property to the power supply class. If true then
      thermal zone won't be created for this power supply in
      power_supply_register().
      
      Power supply drivers may want to set it if they support
      POWER_SUPPLY_PROP_TEMP and they are forwarding this get property call to
      other thermal zone.
      
      If they won't set it lockdep may report false positive deadlock for
      thermal zone's mutex because of nested calls to thermal_zone_get_temp().
      First is the call to thermal_zone_get_temp() of the driver's thermal
      zone. Thermal core gets POWER_SUPPLY_PROP_TEMP property from this
      driver. The driver then calls other thermal zone thermal_zone_get_temp()
      and returns result.
      
      Example of such driver is charger manager.
      Signed-off-by: NKrzysztof Kozlowski <k.kozlowski@samsung.com>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      a69d82b9
  10. 16 9月, 2014 1 次提交
  11. 07 9月, 2014 1 次提交
  12. 19 7月, 2014 1 次提交
    • J
      power_supply: Add inlmt,iterm, min/max temp props · 6bb1d272
      Jenny TC 提交于
      Add new power supply properties for input current, charge termination
      current, min and max temperature
      
      POWER_SUPPLY_PROP_TEMP_MIN - minimum operatable temperature
      POWER_SUPPLY_PROP_TEMP_MAX - maximum operatable temperature
      
      POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT - input current limit programmed
      by charger. Indicates the input current for a charging source.
      
      POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT - Charge termination current used
      to detect the end of charge condition
      Signed-off-by: NJenny TC <jenny.tc@intel.com>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Signed-off-by: NSebastian Reichel <sre@kernel.org>
      6bb1d272
  13. 30 5月, 2014 1 次提交
  14. 24 12月, 2013 1 次提交
  15. 02 12月, 2013 1 次提交
    • P
      power_supply: Add power_supply notifier · d36240d2
      Pali Rohár 提交于
      This patch adds a notifier chain to the power_supply, this helps drivers
      in other subsystem to listen to changes in power supply subsystem.
      
      This would help to take some actions in those drivers on changing the
      power supply properties. One such scenario is to increase/decrease system
      performance based on the battery capacity/voltage. Another scenario is to
      adjust the h/w peak current detection voltage/current thresholds based on
      battery voltage/capacity. The notifier helps drivers to listen to changes
      in power_suppy susbystem without polling the power_supply properties
      Signed-off-by: NJenny TC <jenny.tc@intel.com>
      Signed-off-by: NPali Rohár <pali.rohar@gmail.com>
      Acked-by: NJenny TC <jenny.tc@intel.com>
      Signed-off-by: NAnton Vorontsov <anton@enomsg.org>
      d36240d2
  16. 28 8月, 2013 1 次提交
  17. 29 6月, 2013 1 次提交
  18. 17 4月, 2013 2 次提交
  19. 07 2月, 2013 1 次提交
  20. 06 1月, 2013 1 次提交
  21. 18 11月, 2012 2 次提交
  22. 23 8月, 2012 2 次提交
  23. 14 7月, 2012 1 次提交
  24. 20 6月, 2012 1 次提交
  25. 18 6月, 2012 1 次提交
  26. 05 5月, 2012 2 次提交
    • A
      power_supply: Make the core a boolean instead of a tristate · 0d4ed4e2
      Anton Vorontsov 提交于
      On Mon, Apr 02, 2012 at 01:53:23PM +1000, Benjamin Herrenschmidt wrote:
      > > drivers/built-in.o: In function `.nouveau_pm_trigger':
      > > (.text+0xa56e8): undefined reference to `.power_supply_is_system_supplied'
      > >
      > > nouveau probably needs to depends on CONFIG_POWER_SUPPLY to force a module
      > > build with the latter is =m
      >
      > Ok, not that trivial...
      >
      > The problem is more like POWER_SUPPLY should be a bool, not a tristate.
      >
      > If you think about it: you don't want things like nouveau to depend on a
      > random subsystem like that, people will never get it. In fact,
      > POWER_SUPPLY provides empty inline stubs when not enabled, so that's
      > really designed to not have depends...
      >
      > However that -cannot- work if POWER_SUPPLY is modular and the drivers
      > who use it are not.
      >
      > The only fixes here that make sense I can think of
      > that don't also involve Kconfig horrors are:
      >
      >  - Ugly: in power_supply.h, use the extern variant if
      >
      >       defined(CONFIG_POWER_SUPPLY) ||
      >        (defined(CONFIG_POWER_SUPPLY_MODULE) && defined(MODULE))
      >
      > IE. use the stub if power supply is a module and what is being built is
      > built-in. Of course that's not only ugly, it somewhat sucks from a user
      > perspective as the subsystem now exists but can't be used by some
      > drivers...
      >
      >  - Better: Just make the bloody thing a bool :-) The power supply
      > framework itself is small enough, just make it a boolean option and
      > avoid the problem entirely. The actual power supply sub drivers can
      > remain modular of course.
      Suggested-by: NBenjamin Herrenschmidt <benh@kernel.crashing.org>
      Signed-off-by: NAnton Vorontsov <cbouatmailru@gmail.com>
      0d4ed4e2
    • R
      power_supply: Add voltage_ocv property and use it for max17042 driver · a2ebfe2f
      Ramakrishna Pallala 提交于
      This adds a new sysfs file called 'voltage_ocv' which gives the
      Open Circuit Voltage of the battery.
      
      This property can be used for platform shutdown policies and
      can be useful for initial capacity estimations.
      
      Note: This patch is generated against linux-next branch.
      Signed-off-by: NRamakrishna Pallala <ramakrishna.pallala@intel.com>
      Signed-off-by: NAnton Vorontsov <anton.vorontsov@linaro.org>
      a2ebfe2f
  27. 16 3月, 2012 1 次提交
    • P
      device.h: audit and cleanup users in main include dir · 313162d0
      Paul Gortmaker 提交于
      The <linux/device.h> header includes a lot of stuff, and
      it in turn gets a lot of use just for the basic "struct device"
      which appears so often.
      
      Clean up the users as follows:
      
      1) For those headers only needing "struct device" as a pointer
      in fcn args, replace the include with exactly that.
      
      2) For headers not really using anything from device.h, simply
      delete the include altogether.
      
      3) For headers relying on getting device.h implicitly before
      being included themselves, now explicitly include device.h
      
      4) For files in which doing #1 or #2 uncovers an implicit
      dependency on some other header, fix by explicitly adding
      the required header(s).
      
      Any C files that were implicitly relying on device.h to be
      present have already been dealt with in advance.
      
      Total removals from #1 and #2: 51.  Total additions coming
      from #3: 9.  Total other implicit dependencies from #4: 7.
      
      As of 3.3-rc1, there were 110, so a net removal of 42 gives
      about a 38% reduction in device.h presence in include/*
      Signed-off-by: NPaul Gortmaker <paul.gortmaker@windriver.com>
      313162d0
  28. 04 1月, 2012 1 次提交
  29. 10 12月, 2011 1 次提交