Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-v3.18' of git://git.infradead.org/battery-2.6

Pull power supply and reset updates from Sebastian Reichel:
- Initial support for the following chips
* max77836 (charger)
* max14577 (charger)
* bq27742 (battery gauge)
* ltc2952 (poweroff)
* stih416 (restart)
* syscon-reboot (restart)
* gpio-restart (restart)
- cleanup of power supply core
- misc fixes in power supply and reset drivers

* tag 'for-v3.18' of git://git.infradead.org/battery-2.6: (48 commits)
power: ab8500_fg: Fix build warning
Documentation: charger: max14577: Update the date of introducing ABI
power: reset: corrections for simple syscon reboot driver
Documentation: power: reset: Add documentation for generic SYSCON reboot driver
power: reset: Add generic SYSCON register mapped reset
bq27x00_battery: Fix flag reading for bq27742
power: reset: use restart_notifier mechanism for msm-poweroff
power: Add simple gpio-restart driver
power: reset: st: Provide DT bindings for ST's Power Reset driver
power: reset: Add restart functionality for STiH41x platforms
power: charger-manager: Fix NULL pointer exception with missing cm-fuel-gauge
power: max14577: Fix circular config SYSFS dependency
power: gpio-charger: do not use gpio value directly
power: max8925: Use of_get_child_by_name
power: max8925: Fix NULL ptr dereference on memory allocation failure
bq27x00_battery: Add support to bq27742
Documentation: charger: max14577: Document exported sysfs entry
devicetree: mfd: max14577: Add device tree bindings document
power: max17040: Add ID for MAX77836 Fuel Gauge block
charger: max14577: Configure battery-dependent settings from DTS and sysfs
...

Conflicts:
drivers/power/reset/Kconfig
drivers/power/reset/Makefile

+1920 -250
+14
Documentation/ABI/testing/sysfs-class-power
··· 18 18 This file is writeable and can be used to set the assumed 19 19 battery 'full level'. As batteries age, this value has to be 20 20 amended over time. 21 + 22 + What: /sys/class/power_supply/max14577-charger/device/fast_charge_timer 23 + Date: October 2014 24 + KernelVersion: 3.18.0 25 + Contact: Krzysztof Kozlowski <k.kozlowski@samsung.com> 26 + Description: 27 + This entry shows and sets the maximum time the max14577 28 + charger operates in fast-charge mode. When the timer expires 29 + the device will terminate fast-charge mode (charging current 30 + will drop to 0 A) and will trigger interrupt. 31 + 32 + Valid values: 33 + - 5, 6 or 7 (hours), 34 + - 0: disabled.
+54
Documentation/devicetree/bindings/gpio/gpio-restart.txt
··· 1 + Drive a GPIO line that can be used to restart the system from a restart 2 + handler. 3 + 4 + This binding supports level and edge triggered reset. At driver load 5 + time, the driver will request the given gpio line and install a restart 6 + handler. If the optional properties 'open-source' is not found, the GPIO line 7 + will be driven in the inactive state. Otherwise its not driven until 8 + the restart is initiated. 9 + 10 + When the system is restarted, the restart handler will be invoked in 11 + priority order. The gpio is configured as an output, and driven active, 12 + triggering a level triggered reset condition. This will also cause an 13 + inactive->active edge condition, triggering positive edge triggered 14 + reset. After a delay specified by active-delay, the GPIO is set to 15 + inactive, thus causing an active->inactive edge, triggering negative edge 16 + triggered reset. After a delay specified by inactive-delay, the GPIO 17 + is driven active again. After a delay specified by wait-delay, the 18 + restart handler completes allowing other restart handlers to be attempted. 19 + 20 + Required properties: 21 + - compatible : should be "gpio-restart". 22 + - gpios : The GPIO to set high/low, see "gpios property" in 23 + Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be 24 + low to reset the board set it to "Active Low", otherwise set 25 + gpio to "Active High". 26 + 27 + Optional properties: 28 + - open-source : Treat the GPIO as being open source and defer driving 29 + it to when the restart is initiated. If this optional property is not 30 + specified, the GPIO is initialized as an output in its inactive state. 31 + - priority : A priority ranging from 0 to 255 (default 128) according to 32 + the following guidelines: 33 + 0: Restart handler of last resort, with limited restart 34 + capabilities 35 + 128: Default restart handler; use if no other restart handler is 36 + expected to be available, and/or if restart functionality is 37 + sufficient to restart the entire system 38 + 255: Highest priority restart handler, will preempt all other 39 + restart handlers 40 + - active-delay: Delay (default 100) to wait after driving gpio active [ms] 41 + - inactive-delay: Delay (default 100) to wait after driving gpio inactive [ms] 42 + - wait-delay: Delay (default 3000) to wait after completing restart 43 + sequence [ms] 44 + 45 + Examples: 46 + 47 + gpio-restart { 48 + compatible = "gpio-restart"; 49 + gpios = <&gpio 4 0>; 50 + priority = <128>; 51 + active-delay = <100>; 52 + inactive-delay = <100>; 53 + wait-delay = <3000>; 54 + };
+146
Documentation/devicetree/bindings/mfd/max14577.txt
··· 1 + Maxim MAX14577/77836 Multi-Function Device 2 + 3 + MAX14577 is a Multi-Function Device with Micro-USB Interface Circuit, Li+ 4 + Battery Charger and SFOUT LDO output for powering USB devices. It is 5 + interfaced to host controller using I2C. 6 + 7 + MAX77836 additionally contains PMIC (with two LDO regulators) and Fuel Gauge. 8 + 9 + 10 + Required properties: 11 + - compatible : Must be "maxim,max14577" or "maxim,max77836". 12 + - reg : I2C slave address for the max14577 chip (0x25 for max14577/max77836) 13 + - interrupts : IRQ line for the chip. 14 + - interrupt-parent : The parent interrupt controller. 15 + 16 + 17 + Required nodes: 18 + - charger : 19 + Node for configuring the charger driver. 20 + Required properties: 21 + - compatible : "maxim,max14577-charger" 22 + or "maxim,max77836-charger" 23 + - maxim,fast-charge-uamp : Current in uA for Fast Charge; 24 + Valid values: 25 + - for max14577: 90000 - 950000; 26 + - for max77836: 45000 - 475000; 27 + - maxim,eoc-uamp : Current in uA for End-Of-Charge mode; 28 + Valid values: 29 + - for max14577: 50000 - 200000; 30 + - for max77836: 5000 - 100000; 31 + - maxim,ovp-uvolt : OverVoltage Protection Threshold in uV; 32 + In an overvoltage condition, INT asserts and charging 33 + stops. Valid values: 34 + - 6000000, 6500000, 7000000, 7500000; 35 + - maxim,constant-uvolt : Battery Constant Voltage in uV; 36 + Valid values: 37 + - 4000000 - 4280000 (step by 20000); 38 + - 4350000; 39 + 40 + 41 + Optional nodes: 42 + - max14577-muic/max77836-muic : 43 + Node used only by extcon consumers. 44 + Required properties: 45 + - compatible : "maxim,max14577-muic" or "maxim,max77836-muic" 46 + 47 + - regulators : 48 + Required properties: 49 + - compatible : "maxim,max14577-regulator" 50 + or "maxim,max77836-regulator" 51 + 52 + May contain a sub-node per regulator from the list below. Each 53 + sub-node should contain the constraints and initialization information 54 + for that regulator. See regulator.txt for a description of standard 55 + properties for these sub-nodes. 56 + 57 + List of valid regulator names: 58 + - for max14577: CHARGER, SAFEOUT. 59 + - for max77836: CHARGER, SAFEOUT, LDO1, LDO2. 60 + 61 + The SAFEOUT is a fixed voltage regulator so there is no need to specify 62 + voltages for it. 63 + 64 + 65 + Example: 66 + 67 + #include <dt-bindings/interrupt-controller/irq.h> 68 + 69 + max14577@25 { 70 + compatible = "maxim,max14577"; 71 + reg = <0x25>; 72 + interrupt-parent = <&gpx1>; 73 + interrupts = <5 IRQ_TYPE_NONE>; 74 + 75 + muic: max14577-muic { 76 + compatible = "maxim,max14577-muic"; 77 + }; 78 + 79 + regulators { 80 + compatible = "maxim,max14577-regulator"; 81 + 82 + SAFEOUT { 83 + regulator-name = "SAFEOUT"; 84 + }; 85 + CHARGER { 86 + regulator-name = "CHARGER"; 87 + regulator-min-microamp = <90000>; 88 + regulator-max-microamp = <950000>; 89 + regulator-boot-on; 90 + }; 91 + }; 92 + 93 + charger { 94 + compatible = "maxim,max14577-charger"; 95 + 96 + maxim,constant-uvolt = <4350000>; 97 + maxim,fast-charge-uamp = <450000>; 98 + maxim,eoc-uamp = <50000>; 99 + maxim,ovp-uvolt = <6500000>; 100 + }; 101 + }; 102 + 103 + 104 + max77836@25 { 105 + compatible = "maxim,max77836"; 106 + reg = <0x25>; 107 + interrupt-parent = <&gpx1>; 108 + interrupts = <5 IRQ_TYPE_NONE>; 109 + 110 + muic: max77836-muic { 111 + compatible = "maxim,max77836-muic"; 112 + }; 113 + 114 + regulators { 115 + compatible = "maxim,max77836-regulator"; 116 + 117 + SAFEOUT { 118 + regulator-name = "SAFEOUT"; 119 + }; 120 + CHARGER { 121 + regulator-name = "CHARGER"; 122 + regulator-min-microamp = <90000>; 123 + regulator-max-microamp = <950000>; 124 + regulator-boot-on; 125 + }; 126 + LDO1 { 127 + regulator-name = "LDO1"; 128 + regulator-min-microvolt = <2700000>; 129 + regulator-max-microvolt = <2700000>; 130 + }; 131 + LDO2 { 132 + regulator-name = "LDO2"; 133 + regulator-min-microvolt = <800000>; 134 + regulator-max-microvolt = <3950000>; 135 + }; 136 + }; 137 + 138 + charger { 139 + compatible = "maxim,max77836-charger"; 140 + 141 + maxim,constant-uvolt = <4350000>; 142 + maxim,fast-charge-uamp = <225000>; 143 + maxim,eoc-uamp = <7500>; 144 + maxim,ovp-uvolt = <6500000>; 145 + }; 146 + };
+26
Documentation/devicetree/bindings/power/reset/ltc2952-poweroff.txt
··· 1 + Binding for the LTC2952 PowerPath controller 2 + 3 + This chip is used to externally trigger a system shut down. Once the trigger has 4 + been sent, the chips' watchdog has to be reset to gracefully shut down. 5 + If the Linux systems decides to shut down it powers off the platform via the 6 + kill signal. 7 + 8 + Required properties: 9 + 10 + - compatible: Must contain: "lltc,ltc2952" 11 + - trigger-gpios: phandle + gpio-specifier for the GPIO connected to the 12 + chip's trigger line 13 + - watchdog-gpios: phandle + gpio-specifier for the GPIO connected to the 14 + chip's watchdog line 15 + - kill-gpios: phandle + gpio-specifier for the GPIO connected to the 16 + chip's kill line 17 + 18 + Example: 19 + 20 + ltc2952 { 21 + compatible = "lltc,ltc2952"; 22 + 23 + trigger-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>; 24 + watchdog-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; 25 + kill-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>; 26 + };
+11
Documentation/devicetree/bindings/power/reset/st-reset.txt
··· 1 + *Device-Tree bindings for ST SW reset functionality 2 + 3 + Required properties: 4 + - compatible: should be "st,<chip>-restart". 5 + - st,syscfg: should be a phandle of the syscfg node. 6 + 7 + Example node: 8 + restart { 9 + compatible = "st,stih416-restart"; 10 + st,syscfg = <&syscfg_sbc>; 11 + };
+23
Documentation/devicetree/bindings/power/reset/syscon-reboot.txt
··· 1 + Generic SYSCON mapped register reset driver 2 + 3 + This is a generic reset driver using syscon to map the reset register. 4 + The reset is generally performed with a write to the reset register 5 + defined by the register map pointed by syscon reference plus the offset 6 + with the mask defined in the reboot node. 7 + 8 + Required properties: 9 + - compatible: should contain "syscon-reboot" 10 + - regmap: this is phandle to the register map node 11 + - offset: offset in the register map for the reboot register (in bytes) 12 + - mask: the reset value written to the reboot register (32 bit access) 13 + 14 + Default will be little endian mode, 32 bit access only. 15 + 16 + Examples: 17 + 18 + reboot { 19 + compatible = "syscon-reboot"; 20 + regmap = <&regmapnode>; 21 + offset = <0x0>; 22 + mask = <0x1>; 23 + };
+1 -1
Documentation/power/charger-manager.txt
··· 29 29 While the battery is being charged and the system is in suspend-to-RAM, 30 30 we may need to monitor the battery health by looking at the ambient or 31 31 battery temperature. We can accomplish this by waking up the system 32 - periodically. However, such a method wakes up devices unncessary for 32 + periodically. However, such a method wakes up devices unnecessarily for 33 33 monitoring the battery health and tasks, and user processes that are 34 34 supposed to be kept suspended. That, in turn, incurs unnecessary power 35 35 consumption and slow down charging process. Or even, such peak power
+6
Documentation/power/power_supply_class.txt
··· 101 101 these ones should be used if hardware could only guess (measure and 102 102 retain) the thresholds of a given power supply. 103 103 104 + VOLTAGE_BOOT - Reports the voltage measured during boot 105 + 106 + CURRENT_BOOT - Reports the current measured during boot 107 + 104 108 CHARGE_FULL_DESIGN, CHARGE_EMPTY_DESIGN - design charge values, when 105 109 battery considered full/empty. 106 110 ··· 126 122 the current drawn from a charging source. 127 123 CHARGE_TERM_CURRENT - Charge termination current used to detect the end of charge 128 124 condition. 125 + 126 + CALIBRATE - battery or coulomb counter calibration status 129 127 130 128 CONSTANT_CHARGE_VOLTAGE - constant charge voltage programmed by charger. 131 129 CONSTANT_CHARGE_VOLTAGE_MAX - maximum charge voltage supported by the
+99 -1
drivers/mfd/max14577.c
··· 26 26 #include <linux/mfd/max14577.h> 27 27 #include <linux/mfd/max14577-private.h> 28 28 29 + /* 30 + * Table of valid charger currents for different Maxim chipsets. 31 + * It is placed here because it is used by both charger and regulator driver. 32 + */ 33 + const struct maxim_charger_current maxim_charger_currents[] = { 34 + [MAXIM_DEVICE_TYPE_UNKNOWN] = { 0, 0, 0, 0 }, 35 + [MAXIM_DEVICE_TYPE_MAX14577] = { 36 + .min = MAX14577_CHARGER_CURRENT_LIMIT_MIN, 37 + .high_start = MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START, 38 + .high_step = MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP, 39 + .max = MAX14577_CHARGER_CURRENT_LIMIT_MAX, 40 + }, 41 + [MAXIM_DEVICE_TYPE_MAX77836] = { 42 + .min = MAX77836_CHARGER_CURRENT_LIMIT_MIN, 43 + .high_start = MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START, 44 + .high_step = MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP, 45 + .max = MAX77836_CHARGER_CURRENT_LIMIT_MAX, 46 + }, 47 + }; 48 + EXPORT_SYMBOL_GPL(maxim_charger_currents); 49 + 50 + /* 51 + * maxim_charger_calc_reg_current - Calculate register value for current 52 + * @limits: constraints for charger, matching the MBCICHWRC register 53 + * @min_ua: minimal requested current, micro Amps 54 + * @max_ua: maximum requested current, micro Amps 55 + * @dst: destination to store calculated register value 56 + * 57 + * Calculates the value of MBCICHWRC (Fast Battery Charge Current) register 58 + * for given current and stores it under pointed 'dst'. The stored value 59 + * combines low bit (MBCICHWRCL) and high bits (MBCICHWRCH). It is also 60 + * properly shifted. 61 + * 62 + * The calculated register value matches the current which: 63 + * - is always between <limits.min, limits.max>; 64 + * - is always less or equal to max_ua; 65 + * - is the highest possible value; 66 + * - may be lower than min_ua. 67 + * 68 + * On success returns 0. On error returns -EINVAL (requested min/max current 69 + * is outside of given charger limits) and 'dst' is not set. 70 + */ 71 + int maxim_charger_calc_reg_current(const struct maxim_charger_current *limits, 72 + unsigned int min_ua, unsigned int max_ua, u8 *dst) 73 + { 74 + unsigned int current_bits = 0xf; 75 + 76 + if (min_ua > max_ua) 77 + return -EINVAL; 78 + 79 + if (min_ua > limits->max || max_ua < limits->min) 80 + return -EINVAL; 81 + 82 + if (max_ua < limits->high_start) { 83 + /* 84 + * Less than high_start, so set the minimal current 85 + * (turn Low Bit off, 0 as high bits). 86 + */ 87 + *dst = 0x0; 88 + return 0; 89 + } 90 + 91 + /* max_ua is in range: <high_start, infinite>, cut it to limits.max */ 92 + max_ua = min(limits->max, max_ua); 93 + max_ua -= limits->high_start; 94 + /* 95 + * There is no risk of overflow 'max_ua' here because: 96 + * - max_ua >= limits.high_start 97 + * - BUILD_BUG checks that 'limits' are: max >= high_start + high_step 98 + */ 99 + current_bits = max_ua / limits->high_step; 100 + 101 + /* Turn Low Bit on (use range <limits.high_start, limits.max>) ... */ 102 + *dst = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT; 103 + /* and set proper High Bits */ 104 + *dst |= current_bits << CHGCTRL4_MBCICHWRCH_SHIFT; 105 + 106 + return 0; 107 + } 108 + EXPORT_SYMBOL_GPL(maxim_charger_calc_reg_current); 109 + 29 110 static const struct mfd_cell max14577_devs[] = { 30 111 { 31 112 .name = "max14577-muic", ··· 116 35 .name = "max14577-regulator", 117 36 .of_compatible = "maxim,max14577-regulator", 118 37 }, 119 - { .name = "max14577-charger", }, 38 + { 39 + .name = "max14577-charger", 40 + .of_compatible = "maxim,max14577-charger", 41 + }, 120 42 }; 121 43 122 44 static const struct mfd_cell max77836_devs[] = { ··· 546 462 { 547 463 BUILD_BUG_ON(ARRAY_SIZE(max14577_i2c_id) != MAXIM_DEVICE_TYPE_NUM); 548 464 BUILD_BUG_ON(ARRAY_SIZE(max14577_dt_match) != MAXIM_DEVICE_TYPE_NUM); 465 + 466 + /* Valid charger current values must be provided for each chipset */ 467 + BUILD_BUG_ON(ARRAY_SIZE(maxim_charger_currents) != MAXIM_DEVICE_TYPE_NUM); 468 + 469 + /* Check for valid values for charger */ 470 + BUILD_BUG_ON(MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START + 471 + MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP * 0xf != 472 + MAX14577_CHARGER_CURRENT_LIMIT_MAX); 473 + BUILD_BUG_ON(MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP == 0); 474 + 475 + BUILD_BUG_ON(MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START + 476 + MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP * 0xf != 477 + MAX77836_CHARGER_CURRENT_LIMIT_MAX); 478 + BUILD_BUG_ON(MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP == 0); 549 479 550 480 return i2c_add_driver(&max14577_i2c_driver); 551 481 }
+3 -2
drivers/power/Kconfig
··· 325 325 with help of suspend_again support. 326 326 327 327 config CHARGER_MAX14577 328 - tristate "Maxim MAX14577 MUIC battery charger driver" 328 + tristate "Maxim MAX14577/77836 battery charger driver" 329 329 depends on MFD_MAX14577 330 + depends on SYSFS 330 331 help 331 332 Say Y to enable support for the battery charger control sysfs and 332 - platform data of MAX14577 MUICs. 333 + platform data of MAX14577/77836 MUICs. 333 334 334 335 config CHARGER_MAX8997 335 336 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver"
+5 -4
drivers/power/ab8500_fg.c
··· 2969 2969 2970 2970 static int ab8500_fg_sysfs_psy_create_attrs(struct device *dev) 2971 2971 { 2972 - unsigned int i, j; 2972 + unsigned int i; 2973 2973 struct power_supply *psy = dev_get_drvdata(dev); 2974 2974 struct ab8500_fg *di; 2975 2975 ··· 2978 2978 if (((is_ab8505(di->parent) || is_ab9540(di->parent)) && 2979 2979 abx500_get_chip_id(dev->parent) >= AB8500_CUT2P0) 2980 2980 || is_ab8540(di->parent)) { 2981 - for (j = 0; j < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); j++) 2982 - if (device_create_file(dev, &ab8505_fg_sysfs_psy_attrs[j])) 2981 + for (i = 0; i < ARRAY_SIZE(ab8505_fg_sysfs_psy_attrs); i++) 2982 + if (device_create_file(dev, 2983 + &ab8505_fg_sysfs_psy_attrs[i])) 2983 2984 goto sysfs_psy_create_attrs_failed_ab8505; 2984 2985 } 2985 2986 return 0; 2986 2987 sysfs_psy_create_attrs_failed_ab8505: 2987 2988 dev_err(dev, "Failed creating sysfs psy attrs for ab8505.\n"); 2988 - while (j--) 2989 + while (i--) 2989 2990 device_remove_file(dev, &ab8505_fg_sysfs_psy_attrs[i]); 2990 2991 2991 2992 return -EIO;
+48 -9
drivers/power/bq27x00_battery.c
··· 23 23 * http://focus.ti.com/docs/prod/folders/print/bq27000.html 24 24 * http://focus.ti.com/docs/prod/folders/print/bq27500.html 25 25 * http://www.ti.com/product/bq27425-g1 26 + * http://www.ti.com/product/BQ27742-G1 26 27 */ 27 28 28 29 #include <linux/device.h> ··· 72 71 #define BQ27500_FLAG_FC BIT(9) 73 72 #define BQ27500_FLAG_OTC BIT(15) 74 73 74 + #define BQ27742_POWER_AVG 0x76 75 + 75 76 /* bq27425 register addresses are same as bq27x00 addresses minus 4 */ 76 77 #define BQ27425_REG_OFFSET 0x04 77 78 #define BQ27425_REG_SOC 0x18 /* Register address plus offset */ ··· 86 83 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single); 87 84 }; 88 85 89 - enum bq27x00_chip { BQ27000, BQ27500, BQ27425}; 86 + enum bq27x00_chip { BQ27000, BQ27500, BQ27425, BQ27742}; 90 87 91 88 struct bq27x00_reg_cache { 92 89 int temperature; ··· 155 152 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 156 153 }; 157 154 155 + static enum power_supply_property bq27742_battery_props[] = { 156 + POWER_SUPPLY_PROP_STATUS, 157 + POWER_SUPPLY_PROP_PRESENT, 158 + POWER_SUPPLY_PROP_VOLTAGE_NOW, 159 + POWER_SUPPLY_PROP_CURRENT_NOW, 160 + POWER_SUPPLY_PROP_CAPACITY, 161 + POWER_SUPPLY_PROP_CAPACITY_LEVEL, 162 + POWER_SUPPLY_PROP_TEMP, 163 + POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, 164 + POWER_SUPPLY_PROP_TECHNOLOGY, 165 + POWER_SUPPLY_PROP_CHARGE_FULL, 166 + POWER_SUPPLY_PROP_CHARGE_NOW, 167 + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 168 + POWER_SUPPLY_PROP_CYCLE_COUNT, 169 + POWER_SUPPLY_PROP_POWER_AVG, 170 + POWER_SUPPLY_PROP_HEALTH, 171 + }; 172 + 158 173 static unsigned int poll_interval = 360; 159 174 module_param(poll_interval, uint, 0644); 160 175 MODULE_PARM_DESC(poll_interval, "battery poll interval in seconds - " \ ··· 197 176 */ 198 177 static bool bq27xxx_is_chip_version_higher(struct bq27x00_device_info *di) 199 178 { 200 - if (di->chip == BQ27425 || di->chip == BQ27500) 179 + if (di->chip == BQ27425 || di->chip == BQ27500 || di->chip == BQ27742) 201 180 return true; 202 181 return false; 203 182 } ··· 210 189 { 211 190 int rsoc; 212 191 213 - if (di->chip == BQ27500) 192 + if (di->chip == BQ27500 || di->chip == BQ27742) 214 193 rsoc = bq27x00_read(di, BQ27500_REG_SOC, false); 215 194 else if (di->chip == BQ27425) 216 195 rsoc = bq27x00_read(di, BQ27425_REG_SOC, false); ··· 254 233 { 255 234 int flags; 256 235 bool is_bq27500 = di->chip == BQ27500; 236 + bool is_bq27742 = di->chip == BQ27742; 257 237 bool is_higher = bq27xxx_is_chip_version_higher(di); 238 + bool flags_1b = !(is_bq27500 || is_bq27742); 258 239 259 - flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); 240 + flags = bq27x00_read(di, BQ27x00_REG_FLAGS, flags_1b); 260 241 if (flags >= 0 && !is_higher && (flags & BQ27000_FLAG_CI)) 261 242 return -ENODATA; 262 243 ··· 437 414 struct bq27x00_reg_cache cache = {0, }; 438 415 bool is_bq27500 = di->chip == BQ27500; 439 416 bool is_bq27425 = di->chip == BQ27425; 417 + bool is_bq27742 = di->chip == BQ27742; 418 + bool flags_1b = !(is_bq27500 || is_bq27742); 440 419 441 - cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500); 420 + cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, flags_1b); 442 421 if ((cache.flags & 0xff) == 0xff) 443 422 /* read error */ 444 423 cache.flags = -1; 445 424 if (cache.flags >= 0) { 446 - if (!is_bq27500 && !is_bq27425 425 + if (!is_bq27500 && !is_bq27425 && !is_bq27742 447 426 && (cache.flags & BQ27000_FLAG_CI)) { 448 427 dev_info(di->dev, "battery is not calibrated! ignoring capacity values\n"); 449 428 cache.capacity = -ENODATA; ··· 457 432 cache.health = -ENODATA; 458 433 } else { 459 434 cache.capacity = bq27x00_battery_read_rsoc(di); 460 - if (!is_bq27425) { 435 + if (is_bq27742) 436 + cache.time_to_empty = 437 + bq27x00_battery_read_time(di, 438 + BQ27x00_REG_TTE); 439 + else if (!is_bq27425) { 461 440 cache.energy = bq27x00_battery_read_energy(di); 462 441 cache.time_to_empty = 463 442 bq27x00_battery_read_time(di, ··· 479 450 cache.temperature = bq27x00_battery_read_temperature(di); 480 451 if (!is_bq27425) 481 452 cache.cycle_count = bq27x00_battery_read_cyct(di); 482 - cache.power_avg = 483 - bq27x00_battery_read_pwr_avg(di, BQ27x00_POWER_AVG); 453 + if (is_bq27742) 454 + cache.power_avg = 455 + bq27x00_battery_read_pwr_avg(di, 456 + BQ27742_POWER_AVG); 457 + else 458 + cache.power_avg = 459 + bq27x00_battery_read_pwr_avg(di, 460 + BQ27x00_POWER_AVG); 484 461 485 462 /* We only have to read charge design full once */ 486 463 if (di->charge_design_full <= 0) ··· 737 702 if (di->chip == BQ27425) { 738 703 di->bat.properties = bq27425_battery_props; 739 704 di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props); 705 + } else if (di->chip == BQ27742) { 706 + di->bat.properties = bq27742_battery_props; 707 + di->bat.num_properties = ARRAY_SIZE(bq27742_battery_props); 740 708 } else { 741 709 di->bat.properties = bq27x00_battery_props; 742 710 di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props); ··· 896 858 { "bq27200", BQ27000 }, /* bq27200 is same as bq27000, but with i2c */ 897 859 { "bq27500", BQ27500 }, 898 860 { "bq27425", BQ27425 }, 861 + { "bq27742", BQ27742 }, 899 862 {}, 900 863 }; 901 864 MODULE_DEVICE_TABLE(i2c, bq27x00_id);
+14 -2
drivers/power/charger-manager.c
··· 1656 1656 { 1657 1657 if (pdev->dev.of_node) 1658 1658 return of_cm_parse_desc(&pdev->dev); 1659 - return (struct charger_desc *)dev_get_platdata(&pdev->dev); 1659 + return dev_get_platdata(&pdev->dev); 1660 1660 } 1661 1661 1662 1662 static int charger_manager_probe(struct platform_device *pdev) ··· 1677 1677 } 1678 1678 } 1679 1679 1680 - if (!desc) { 1680 + if (IS_ERR(desc)) { 1681 1681 dev_err(&pdev->dev, "No platform data (desc) found\n"); 1682 1682 return -ENODEV; 1683 1683 } ··· 1717 1717 1718 1718 if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) { 1719 1719 dev_err(&pdev->dev, "No power supply defined\n"); 1720 + return -EINVAL; 1721 + } 1722 + 1723 + if (!desc->psy_fuel_gauge) { 1724 + dev_err(&pdev->dev, "No fuel gauge power supply defined\n"); 1720 1725 return -EINVAL; 1721 1726 } 1722 1727 ··· 1843 1838 */ 1844 1839 device_init_wakeup(&pdev->dev, true); 1845 1840 device_set_wakeup_capable(&pdev->dev, false); 1841 + 1842 + /* 1843 + * Charger-manager have to check the charging state right after 1844 + * tialization of charger-manager and then update current charging 1845 + * state. 1846 + */ 1847 + cm_monitor(); 1846 1848 1847 1849 schedule_work(&setup_polling); 1848 1850
+1 -1
drivers/power/gpio-charger.c
··· 55 55 56 56 switch (psp) { 57 57 case POWER_SUPPLY_PROP_ONLINE: 58 - val->intval = gpio_get_value_cansleep(pdata->gpio); 58 + val->intval = !!gpio_get_value_cansleep(pdata->gpio); 59 59 val->intval ^= pdata->gpio_active_low; 60 60 break; 61 61 default:
+337 -35
drivers/power/max14577_charger.c
··· 1 1 /* 2 - * Battery charger driver for the Maxim 14577 2 + * max14577_charger.c - Battery charger driver for the Maxim 14577/77836 3 3 * 4 - * Copyright (C) 2013 Samsung Electronics 4 + * Copyright (C) 2013,2014 Samsung Electronics 5 5 * Krzysztof Kozlowski <k.kozlowski@samsung.com> 6 6 * 7 7 * This program is free software; you can redistribute it and/or modify ··· 19 19 #include <linux/platform_device.h> 20 20 #include <linux/power_supply.h> 21 21 #include <linux/mfd/max14577-private.h> 22 + #include <linux/mfd/max14577.h> 22 23 23 24 struct max14577_charger { 24 25 struct device *dev; 25 26 struct max14577 *max14577; 26 27 struct power_supply charger; 27 28 28 - unsigned int charging_state; 29 - unsigned int battery_state; 29 + unsigned int charging_state; 30 + unsigned int battery_state; 31 + 32 + struct max14577_charger_platform_data *pdata; 30 33 }; 34 + 35 + /* 36 + * Helper function for mapping values of STATUS2/CHGTYP register on max14577 37 + * and max77836 chipsets to enum maxim_muic_charger_type. 38 + */ 39 + static enum max14577_muic_charger_type maxim_get_charger_type( 40 + enum maxim_device_type dev_type, u8 val) { 41 + switch (val) { 42 + case MAX14577_CHARGER_TYPE_NONE: 43 + case MAX14577_CHARGER_TYPE_USB: 44 + case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: 45 + case MAX14577_CHARGER_TYPE_DEDICATED_CHG: 46 + case MAX14577_CHARGER_TYPE_SPECIAL_500MA: 47 + case MAX14577_CHARGER_TYPE_SPECIAL_1A: 48 + return val; 49 + case MAX14577_CHARGER_TYPE_DEAD_BATTERY: 50 + case MAX14577_CHARGER_TYPE_RESERVED: 51 + if (dev_type == MAXIM_DEVICE_TYPE_MAX77836) 52 + val |= 0x8; 53 + return val; 54 + default: 55 + WARN_ONCE(1, "max14577: Unsupported chgtyp register value 0x%02x", val); 56 + return val; 57 + } 58 + } 31 59 32 60 static int max14577_get_charger_state(struct max14577_charger *chg) 33 61 { ··· 117 89 { 118 90 struct regmap *rmap = chg->max14577->regmap; 119 91 u8 reg_data; 92 + enum max14577_muic_charger_type chg_type; 120 93 121 94 max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, &reg_data); 122 95 reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT); 123 - switch (reg_data) { 96 + chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data); 97 + switch (chg_type) { 124 98 case MAX14577_CHARGER_TYPE_USB: 125 99 case MAX14577_CHARGER_TYPE_DEDICATED_CHG: 126 100 case MAX14577_CHARGER_TYPE_SPECIAL_500MA: 127 101 case MAX14577_CHARGER_TYPE_SPECIAL_1A: 128 102 case MAX14577_CHARGER_TYPE_DEAD_BATTERY: 103 + case MAX77836_CHARGER_TYPE_SPECIAL_BIAS: 129 104 return 1; 130 105 case MAX14577_CHARGER_TYPE_NONE: 131 106 case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: 132 107 case MAX14577_CHARGER_TYPE_RESERVED: 108 + case MAX77836_CHARGER_TYPE_RESERVED: 133 109 default: 134 110 return 0; 135 111 } ··· 150 118 struct regmap *rmap = chg->max14577->regmap; 151 119 int state = POWER_SUPPLY_HEALTH_GOOD; 152 120 u8 reg_data; 121 + enum max14577_muic_charger_type chg_type; 153 122 154 123 max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, &reg_data); 155 124 reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT); 156 - if (reg_data == MAX14577_CHARGER_TYPE_DEAD_BATTERY) { 125 + chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data); 126 + if (chg_type == MAX14577_CHARGER_TYPE_DEAD_BATTERY) { 157 127 state = POWER_SUPPLY_HEALTH_DEAD; 158 128 goto state_set; 159 129 } ··· 181 147 return 1; 182 148 } 183 149 150 + static int max14577_set_fast_charge_timer(struct max14577_charger *chg, 151 + unsigned long hours) 152 + { 153 + u8 reg_data; 154 + 155 + switch (hours) { 156 + case 5 ... 7: 157 + reg_data = hours - 3; 158 + break; 159 + case 0: 160 + /* Disable */ 161 + reg_data = 0x7; 162 + break; 163 + default: 164 + dev_err(chg->dev, "Wrong value for Fast-Charge Timer: %lu\n", 165 + hours); 166 + return -EINVAL; 167 + } 168 + reg_data <<= CHGCTRL1_TCHW_SHIFT; 169 + 170 + return max14577_update_reg(chg->max14577->regmap, 171 + MAX14577_REG_CHGCTRL1, CHGCTRL1_TCHW_MASK, reg_data); 172 + } 173 + 174 + static int max14577_init_constant_voltage(struct max14577_charger *chg, 175 + unsigned int uvolt) 176 + { 177 + u8 reg_data; 178 + 179 + if (uvolt < MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN || 180 + uvolt > MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX) 181 + return -EINVAL; 182 + 183 + if (uvolt == 4200000) 184 + reg_data = 0x0; 185 + else if (uvolt == MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX) 186 + reg_data = 0x1f; 187 + else if (uvolt <= 4280000) { 188 + unsigned int val = uvolt; 189 + 190 + val -= MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN; 191 + val /= MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP; 192 + if (uvolt <= 4180000) 193 + reg_data = 0x1 + val; 194 + else 195 + reg_data = val; /* Fix for gap between 4.18V and 4.22V */ 196 + } else 197 + return -EINVAL; 198 + 199 + reg_data <<= CHGCTRL3_MBCCVWRC_SHIFT; 200 + 201 + return max14577_write_reg(chg->max14577->regmap, 202 + MAX14577_CHG_REG_CHG_CTRL3, reg_data); 203 + } 204 + 205 + static int max14577_init_eoc(struct max14577_charger *chg, 206 + unsigned int uamp) 207 + { 208 + unsigned int current_bits = 0xf; 209 + u8 reg_data; 210 + 211 + switch (chg->max14577->dev_type) { 212 + case MAXIM_DEVICE_TYPE_MAX77836: 213 + if (uamp < 5000) 214 + return -EINVAL; /* Requested current is too low */ 215 + 216 + if (uamp >= 7500 && uamp < 10000) 217 + current_bits = 0x0; 218 + else if (uamp <= 50000) { 219 + /* <5000, 7499> and <10000, 50000> */ 220 + current_bits = uamp / 5000; 221 + } else { 222 + uamp = min(uamp, 100000U) - 50000U; 223 + current_bits = 0xa + uamp / 10000; 224 + } 225 + break; 226 + 227 + case MAXIM_DEVICE_TYPE_MAX14577: 228 + default: 229 + if (uamp < MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN) 230 + return -EINVAL; /* Requested current is too low */ 231 + 232 + uamp = min(uamp, MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX); 233 + uamp -= MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN; 234 + current_bits = uamp / MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP; 235 + break; 236 + } 237 + 238 + reg_data = current_bits << CHGCTRL5_EOCS_SHIFT; 239 + 240 + return max14577_update_reg(chg->max14577->regmap, 241 + MAX14577_CHG_REG_CHG_CTRL5, CHGCTRL5_EOCS_MASK, 242 + reg_data); 243 + } 244 + 245 + static int max14577_init_fast_charge(struct max14577_charger *chg, 246 + unsigned int uamp) 247 + { 248 + u8 reg_data; 249 + int ret; 250 + const struct maxim_charger_current *limits = 251 + &maxim_charger_currents[chg->max14577->dev_type]; 252 + 253 + ret = maxim_charger_calc_reg_current(limits, uamp, uamp, &reg_data); 254 + if (ret) { 255 + dev_err(chg->dev, "Wrong value for fast charge: %u\n", uamp); 256 + return ret; 257 + } 258 + 259 + return max14577_update_reg(chg->max14577->regmap, 260 + MAX14577_CHG_REG_CHG_CTRL4, 261 + CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK, 262 + reg_data); 263 + } 264 + 184 265 /* 185 266 * Sets charger registers to proper and safe default values. 186 267 * Some of these values are equal to defaults in MAX14577E 187 268 * data sheet but there are minor differences. 188 269 */ 189 - static void max14577_charger_reg_init(struct max14577_charger *chg) 270 + static int max14577_charger_reg_init(struct max14577_charger *chg) 190 271 { 191 272 struct regmap *rmap = chg->max14577->regmap; 192 273 u8 reg_data; 274 + int ret; 193 275 194 276 /* 195 277 * Charger-Type Manual Detection, default off (set CHGTYPMAN to 0) ··· 317 167 CDETCTRL1_CHGDETEN_MASK | CDETCTRL1_CHGTYPMAN_MASK, 318 168 reg_data); 319 169 320 - /* Battery Fast-Charge Timer, from SM-V700: 6hrs */ 321 - reg_data = 0x3 << CHGCTRL1_TCHW_SHIFT; 322 - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL1, reg_data); 323 - 324 170 /* 325 171 * Wall-Adapter Rapid Charge, default on 326 172 * Battery-Charger, default on ··· 325 179 reg_data |= 0x1 << CHGCTRL2_MBCHOSTEN_SHIFT; 326 180 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL2, reg_data); 327 181 328 - /* Battery-Charger Constant Voltage (CV) Mode, from SM-V700: 4.35V */ 329 - reg_data = 0xf << CHGCTRL3_MBCCVWRC_SHIFT; 330 - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL3, reg_data); 331 - 332 - /* 333 - * Fast Battery-Charge Current Low, default 200-950mA 334 - * Fast Battery-Charge Current High, from SM-V700: 450mA 335 - */ 336 - reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT; 337 - reg_data |= 0x5 << CHGCTRL4_MBCICHWRCH_SHIFT; 338 - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL4, reg_data); 339 - 340 - /* End-of-Charge Current, from SM-V700: 50mA */ 341 - reg_data = 0x0 << CHGCTRL5_EOCS_SHIFT; 342 - max14577_write_reg(rmap, MAX14577_REG_CHGCTRL5, reg_data); 343 - 344 182 /* Auto Charging Stop, default off */ 345 183 reg_data = 0x0 << CHGCTRL6_AUTOSTOP_SHIFT; 346 184 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL6, reg_data); 347 185 348 - /* Overvoltage-Protection Threshold, from SM-V700: 6.5V */ 349 - reg_data = 0x2 << CHGCTRL7_OTPCGHCVS_SHIFT; 186 + ret = max14577_init_constant_voltage(chg, chg->pdata->constant_uvolt); 187 + if (ret) 188 + return ret; 189 + 190 + ret = max14577_init_eoc(chg, chg->pdata->eoc_uamp); 191 + if (ret) 192 + return ret; 193 + 194 + ret = max14577_init_fast_charge(chg, chg->pdata->fast_charge_uamp); 195 + if (ret) 196 + return ret; 197 + 198 + ret = max14577_set_fast_charge_timer(chg, 199 + MAXIM_CHARGER_FAST_CHARGE_TIMER_DEFAULT); 200 + if (ret) 201 + return ret; 202 + 203 + /* Initialize Overvoltage-Protection Threshold */ 204 + switch (chg->pdata->ovp_uvolt) { 205 + case 7500000: 206 + reg_data = 0x0; 207 + break; 208 + case 6000000: 209 + case 6500000: 210 + case 7000000: 211 + reg_data = 0x1 + (chg->pdata->ovp_uvolt - 6000000) / 500000; 212 + break; 213 + default: 214 + dev_err(chg->dev, "Wrong value for OVP: %u\n", 215 + chg->pdata->ovp_uvolt); 216 + return -EINVAL; 217 + } 218 + reg_data <<= CHGCTRL7_OTPCGHCVS_SHIFT; 350 219 max14577_write_reg(rmap, MAX14577_REG_CHGCTRL7, reg_data); 220 + 221 + return 0; 351 222 } 352 223 353 224 /* Support property from charger */ ··· 378 215 POWER_SUPPLY_PROP_MANUFACTURER, 379 216 }; 380 217 381 - static const char *model_name = "MAX14577"; 218 + static const char * const model_names[] = { 219 + [MAXIM_DEVICE_TYPE_UNKNOWN] = "MAX14577-like", 220 + [MAXIM_DEVICE_TYPE_MAX14577] = "MAX14577", 221 + [MAXIM_DEVICE_TYPE_MAX77836] = "MAX77836", 222 + }; 382 223 static const char *manufacturer = "Maxim Integrated"; 383 224 384 225 static int max14577_charger_get_property(struct power_supply *psy, ··· 411 244 val->intval = max14577_get_online(chg); 412 245 break; 413 246 case POWER_SUPPLY_PROP_MODEL_NAME: 414 - val->strval = model_name; 247 + BUILD_BUG_ON(ARRAY_SIZE(model_names) != MAXIM_DEVICE_TYPE_NUM); 248 + val->strval = model_names[chg->max14577->dev_type]; 415 249 break; 416 250 case POWER_SUPPLY_PROP_MANUFACTURER: 417 251 val->strval = manufacturer; ··· 423 255 424 256 return ret; 425 257 } 258 + 259 + #ifdef CONFIG_OF 260 + static struct max14577_charger_platform_data *max14577_charger_dt_init( 261 + struct platform_device *pdev) 262 + { 263 + struct max14577_charger_platform_data *pdata; 264 + struct device_node *np = pdev->dev.of_node; 265 + int ret; 266 + 267 + if (!np) { 268 + dev_err(&pdev->dev, "No charger OF node\n"); 269 + return ERR_PTR(-EINVAL); 270 + } 271 + 272 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 273 + if (!pdata) 274 + return ERR_PTR(-ENOMEM); 275 + 276 + ret = of_property_read_u32(np, "maxim,constant-uvolt", 277 + &pdata->constant_uvolt); 278 + if (ret) { 279 + dev_err(&pdev->dev, "Cannot parse maxim,constant-uvolt field from DT\n"); 280 + return ERR_PTR(ret); 281 + } 282 + 283 + ret = of_property_read_u32(np, "maxim,fast-charge-uamp", 284 + &pdata->fast_charge_uamp); 285 + if (ret) { 286 + dev_err(&pdev->dev, "Cannot parse maxim,fast-charge-uamp field from DT\n"); 287 + return ERR_PTR(ret); 288 + } 289 + 290 + ret = of_property_read_u32(np, "maxim,eoc-uamp", &pdata->eoc_uamp); 291 + if (ret) { 292 + dev_err(&pdev->dev, "Cannot parse maxim,eoc-uamp field from DT\n"); 293 + return ERR_PTR(ret); 294 + } 295 + 296 + ret = of_property_read_u32(np, "maxim,ovp-uvolt", &pdata->ovp_uvolt); 297 + if (ret) { 298 + dev_err(&pdev->dev, "Cannot parse maxim,ovp-uvolt field from DT\n"); 299 + return ERR_PTR(ret); 300 + } 301 + 302 + return pdata; 303 + } 304 + #else /* CONFIG_OF */ 305 + static struct max14577_charger_platform_data *max14577_charger_dt_init( 306 + struct platform_device *pdev) 307 + { 308 + return NULL; 309 + } 310 + #endif /* CONFIG_OF */ 311 + 312 + static ssize_t show_fast_charge_timer(struct device *dev, 313 + struct device_attribute *attr, char *buf) 314 + { 315 + struct max14577_charger *chg = dev_get_drvdata(dev); 316 + u8 reg_data; 317 + int ret; 318 + unsigned int val; 319 + 320 + ret = max14577_read_reg(chg->max14577->regmap, MAX14577_REG_CHGCTRL1, 321 + &reg_data); 322 + if (ret) 323 + return ret; 324 + 325 + reg_data &= CHGCTRL1_TCHW_MASK; 326 + reg_data >>= CHGCTRL1_TCHW_SHIFT; 327 + switch (reg_data) { 328 + case 0x2 ... 0x4: 329 + val = reg_data + 3; 330 + break; 331 + case 0x7: 332 + val = 0; 333 + break; 334 + default: 335 + val = 5; 336 + break; 337 + } 338 + 339 + return scnprintf(buf, PAGE_SIZE, "%u\n", val); 340 + } 341 + 342 + static ssize_t store_fast_charge_timer(struct device *dev, 343 + struct device_attribute *attr, const char *buf, size_t count) 344 + { 345 + struct max14577_charger *chg = dev_get_drvdata(dev); 346 + unsigned long val; 347 + int ret; 348 + 349 + ret = kstrtoul(buf, 10, &val); 350 + if (ret) 351 + return ret; 352 + 353 + ret = max14577_set_fast_charge_timer(chg, val); 354 + if (ret) 355 + return ret; 356 + 357 + return count; 358 + } 359 + 360 + static DEVICE_ATTR(fast_charge_timer, S_IRUGO | S_IWUSR, 361 + show_fast_charge_timer, store_fast_charge_timer); 426 362 427 363 static int max14577_charger_probe(struct platform_device *pdev) 428 364 { ··· 542 270 chg->dev = &pdev->dev; 543 271 chg->max14577 = max14577; 544 272 545 - max14577_charger_reg_init(chg); 273 + chg->pdata = max14577_charger_dt_init(pdev); 274 + if (IS_ERR_OR_NULL(chg->pdata)) 275 + return PTR_ERR(chg->pdata); 276 + 277 + ret = max14577_charger_reg_init(chg); 278 + if (ret) 279 + return ret; 546 280 547 281 chg->charger.name = "max14577-charger", 548 282 chg->charger.type = POWER_SUPPLY_TYPE_BATTERY, ··· 556 278 chg->charger.num_properties = ARRAY_SIZE(max14577_charger_props), 557 279 chg->charger.get_property = max14577_charger_get_property, 558 280 559 - ret = power_supply_register(&pdev->dev, &chg->charger); 281 + ret = device_create_file(&pdev->dev, &dev_attr_fast_charge_timer); 560 282 if (ret) { 561 - dev_err(&pdev->dev, "failed: power supply register\n"); 283 + dev_err(&pdev->dev, "failed: create sysfs entry\n"); 562 284 return ret; 563 285 } 564 286 287 + ret = power_supply_register(&pdev->dev, &chg->charger); 288 + if (ret) { 289 + dev_err(&pdev->dev, "failed: power supply register\n"); 290 + goto err; 291 + } 292 + 293 + /* Check for valid values for charger */ 294 + BUILD_BUG_ON(MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN + 295 + MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP * 0xf != 296 + MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX); 565 297 return 0; 298 + 299 + err: 300 + device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); 301 + 302 + return ret; 566 303 } 567 304 568 305 static int max14577_charger_remove(struct platform_device *pdev) 569 306 { 570 307 struct max14577_charger *chg = platform_get_drvdata(pdev); 571 308 309 + device_remove_file(&pdev->dev, &dev_attr_fast_charge_timer); 572 310 power_supply_unregister(&chg->charger); 573 311 574 312 return 0; 575 313 } 314 + 315 + static const struct platform_device_id max14577_charger_id[] = { 316 + { "max14577-charger", MAXIM_DEVICE_TYPE_MAX14577, }, 317 + { "max77836-charger", MAXIM_DEVICE_TYPE_MAX77836, }, 318 + { } 319 + }; 320 + MODULE_DEVICE_TABLE(platform, max14577_charger_id); 576 321 577 322 static struct platform_driver max14577_charger_driver = { 578 323 .driver = { ··· 604 303 }, 605 304 .probe = max14577_charger_probe, 606 305 .remove = max14577_charger_remove, 306 + .id_table = max14577_charger_id, 607 307 }; 608 308 module_platform_driver(max14577_charger_driver); 609 309 610 310 MODULE_AUTHOR("Krzysztof Kozlowski <k.kozlowski@samsung.com>"); 611 - MODULE_DESCRIPTION("MAXIM 14577 charger driver"); 311 + MODULE_DESCRIPTION("Maxim 14577/77836 charger driver"); 612 312 MODULE_LICENSE("GPL");
+2 -1
drivers/power/max17040_battery.c
··· 277 277 #endif /* CONFIG_PM_SLEEP */ 278 278 279 279 static const struct i2c_device_id max17040_id[] = { 280 - { "max17040", 0 }, 280 + { "max17040" }, 281 + { "max77836-battery" }, 281 282 { } 282 283 }; 283 284 MODULE_DEVICE_TABLE(i2c, max17040_id);
+5 -2
drivers/power/max8925_power.c
··· 443 443 if (!nproot) 444 444 return pdev->dev.platform_data; 445 445 446 - np = of_find_node_by_name(nproot, "charger"); 446 + np = of_get_child_by_name(nproot, "charger"); 447 447 if (!np) { 448 448 dev_err(&pdev->dev, "failed to find charger node\n"); 449 449 return NULL; ··· 452 452 pdata = devm_kzalloc(&pdev->dev, 453 453 sizeof(struct max8925_power_pdata), 454 454 GFP_KERNEL); 455 + if (!pdata) 456 + goto ret; 455 457 456 458 of_property_read_u32(np, "topoff-threshold", &topoff_threshold); 457 459 of_property_read_u32(np, "batt-detect", &batt_detect); 458 460 of_property_read_u32(np, "fast-charge", &fast_charge); 459 461 of_property_read_u32(np, "no-insert-detect", &no_insert_detect); 460 462 of_property_read_u32(np, "no-temp-support", &no_temp_support); 461 - of_node_put(np); 462 463 463 464 pdata->batt_detect = batt_detect; 464 465 pdata->fast_charge = fast_charge; ··· 467 466 pdata->no_insert_detect = no_insert_detect; 468 467 pdata->no_temp_support = no_temp_support; 469 468 469 + ret: 470 + of_node_put(np); 470 471 return pdata; 471 472 } 472 473 #else
+48 -54
drivers/power/power_supply_core.c
··· 58 58 59 59 static int __power_supply_changed_work(struct device *dev, void *data) 60 60 { 61 - struct power_supply *psy = (struct power_supply *)data; 61 + struct power_supply *psy = data; 62 62 struct power_supply *pst = dev_get_drvdata(dev); 63 63 64 64 if (__power_supply_is_supplied_by(psy, pst)) { ··· 78 78 dev_dbg(psy->dev, "%s\n", __func__); 79 79 80 80 spin_lock_irqsave(&psy->changed_lock, flags); 81 - if (psy->changed) { 81 + /* 82 + * Check 'changed' here to avoid issues due to race between 83 + * power_supply_changed() and this routine. In worst case 84 + * power_supply_changed() can be called again just before we take above 85 + * lock. During the first call of this routine we will mark 'changed' as 86 + * false and it will stay false for the next call as well. 87 + */ 88 + if (likely(psy->changed)) { 82 89 psy->changed = false; 83 90 spin_unlock_irqrestore(&psy->changed_lock, flags); 84 91 class_for_each_device(power_supply_class, NULL, psy, ··· 96 89 kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); 97 90 spin_lock_irqsave(&psy->changed_lock, flags); 98 91 } 92 + 99 93 /* 100 - * Dependent power supplies (e.g. battery) may have changed state 101 - * as a result of this event, so poll again and hold the 102 - * wakeup_source until all events are processed. 94 + * Hold the wakeup_source until all events are processed. 95 + * power_supply_changed() might have called again and have set 'changed' 96 + * to true. 103 97 */ 104 - if (!psy->changed) 98 + if (likely(!psy->changed)) 105 99 pm_relax(psy->dev); 106 100 spin_unlock_irqrestore(&psy->changed_lock, flags); 107 101 } ··· 127 119 static int __power_supply_populate_supplied_from(struct device *dev, 128 120 void *data) 129 121 { 130 - struct power_supply *psy = (struct power_supply *)data; 122 + struct power_supply *psy = data; 131 123 struct power_supply *epsy = dev_get_drvdata(dev); 132 124 struct device_node *np; 133 125 int i = 0; ··· 135 127 do { 136 128 np = of_parse_phandle(psy->of_node, "power-supplies", i++); 137 129 if (!np) 138 - continue; 130 + break; 139 131 140 132 if (np == epsy->of_node) { 141 133 dev_info(psy->dev, "%s: Found supply : %s\n", ··· 166 158 static int __power_supply_find_supply_from_node(struct device *dev, 167 159 void *data) 168 160 { 169 - struct device_node *np = (struct device_node *)data; 161 + struct device_node *np = data; 170 162 struct power_supply *epsy = dev_get_drvdata(dev); 171 163 172 - /* return error breaks out of class_for_each_device loop */ 164 + /* returning non-zero breaks out of class_for_each_device loop */ 173 165 if (epsy->of_node == np) 174 - return -EINVAL; 166 + return 1; 175 167 176 168 return 0; 177 169 } ··· 179 171 static int power_supply_find_supply_from_node(struct device_node *supply_node) 180 172 { 181 173 int error; 182 - struct device *dev; 183 - struct class_dev_iter iter; 184 174 185 175 /* 186 - * Use iterator to see if any other device is registered. 187 - * This is required since class_for_each_device returns 0 188 - * if there are no devices registered. 189 - */ 190 - class_dev_iter_init(&iter, power_supply_class, NULL, NULL); 191 - dev = class_dev_iter_next(&iter); 192 - 193 - if (!dev) 194 - return -EPROBE_DEFER; 195 - 196 - /* 197 - * We have to treat the return value as inverted, because if 198 - * we return error on not found, then it won't continue looking. 199 - * So we trick it by returning error on success to stop looking 200 - * once the matching device is found. 176 + * class_for_each_device() either returns its own errors or values 177 + * returned by __power_supply_find_supply_from_node(). 178 + * 179 + * __power_supply_find_supply_from_node() will return 0 (no match) 180 + * or 1 (match). 181 + * 182 + * We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if 183 + * it returned 0, or error as returned by it. 201 184 */ 202 185 error = class_for_each_device(power_supply_class, NULL, supply_node, 203 186 __power_supply_find_supply_from_node); 204 187 205 - return error ? 0 : -EPROBE_DEFER; 188 + return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER; 206 189 } 207 190 208 191 static int power_supply_check_supplies(struct power_supply *psy) ··· 214 215 215 216 np = of_parse_phandle(psy->of_node, "power-supplies", cnt++); 216 217 if (!np) 217 - continue; 218 + break; 218 219 219 220 ret = power_supply_find_supply_from_node(np); 220 - if (ret) { 221 - dev_dbg(psy->dev, "Failed to find supply, defer!\n"); 222 - of_node_put(np); 223 - return -EPROBE_DEFER; 224 - } 225 221 of_node_put(np); 222 + 223 + if (ret) { 224 + dev_dbg(psy->dev, "Failed to find supply!\n"); 225 + return ret; 226 + } 226 227 } while (np); 228 + 229 + /* Missing valid "power-supplies" entries */ 230 + if (cnt == 1) 231 + return 0; 227 232 228 233 /* All supplies found, allocate char ** array for filling */ 229 234 psy->supplied_from = devm_kzalloc(psy->dev, sizeof(psy->supplied_from), ··· 237 234 return -ENOMEM; 238 235 } 239 236 240 - *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * cnt, 237 + *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * (cnt - 1), 241 238 GFP_KERNEL); 242 239 if (!*psy->supplied_from) { 243 240 dev_err(psy->dev, "Couldn't allocate memory for supply list\n"); ··· 256 253 static int __power_supply_am_i_supplied(struct device *dev, void *data) 257 254 { 258 255 union power_supply_propval ret = {0,}; 259 - struct power_supply *psy = (struct power_supply *)data; 256 + struct power_supply *psy = data; 260 257 struct power_supply *epsy = dev_get_drvdata(dev); 261 258 262 259 if (__power_supply_is_supplied_by(epsy, psy)) 263 - if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) { 264 - if (ret.intval) 265 - return ret.intval; 266 - } 260 + if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) 261 + return ret.intval; 267 262 268 263 return 0; 269 264 } ··· 286 285 unsigned int *count = data; 287 286 288 287 (*count)++; 289 - if (psy->type != POWER_SUPPLY_TYPE_BATTERY) { 290 - if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret)) 291 - return 0; 292 - if (ret.intval) 288 + if (psy->type != POWER_SUPPLY_TYPE_BATTERY) 289 + if (!psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret)) 293 290 return ret.intval; 294 - } 291 + 295 292 return 0; 296 293 } 297 294 ··· 422 423 if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) { 423 424 psy->tzd = thermal_zone_device_register(psy->name, 0, 0, 424 425 psy, &psy_tzd_ops, NULL, 0, 0); 425 - if (IS_ERR(psy->tzd)) 426 - return PTR_ERR(psy->tzd); 427 - break; 426 + return PTR_ERR_OR_ZERO(psy->tzd); 428 427 } 429 428 } 430 429 return 0; ··· 500 503 psy->tcd = thermal_cooling_device_register( 501 504 (char *)psy->name, 502 505 psy, &psy_tcd_ops); 503 - if (IS_ERR(psy->tcd)) 504 - return PTR_ERR(psy->tcd); 505 - break; 506 + return PTR_ERR_OR_ZERO(psy->tcd); 506 507 } 507 508 } 508 509 return 0; ··· 586 591 587 592 power_supply_changed(psy); 588 593 589 - goto success; 594 + return 0; 590 595 591 596 create_triggers_failed: 592 597 psy_unregister_cooler(psy); ··· 599 604 check_supplies_failed: 600 605 dev_set_name_failed: 601 606 put_device(dev); 602 - success: 603 607 return rc; 604 608 } 605 609
+4 -15
drivers/power/power_supply_leds.c
··· 57 57 58 58 static int power_supply_create_bat_triggers(struct power_supply *psy) 59 59 { 60 - int rc = 0; 61 - 62 60 psy->charging_full_trig_name = kasprintf(GFP_KERNEL, 63 61 "%s-charging-or-full", psy->name); 64 62 if (!psy->charging_full_trig_name) ··· 85 87 led_trigger_register_simple(psy->charging_blink_full_solid_trig_name, 86 88 &psy->charging_blink_full_solid_trig); 87 89 88 - goto success; 90 + return 0; 89 91 90 92 charging_blink_full_solid_failed: 91 93 kfree(psy->full_trig_name); ··· 94 96 charging_failed: 95 97 kfree(psy->charging_full_trig_name); 96 98 charging_full_failed: 97 - rc = -ENOMEM; 98 - success: 99 - return rc; 99 + return -ENOMEM; 100 100 } 101 101 102 102 static void power_supply_remove_bat_triggers(struct power_supply *psy) ··· 128 132 129 133 static int power_supply_create_gen_triggers(struct power_supply *psy) 130 134 { 131 - int rc = 0; 132 - 133 135 psy->online_trig_name = kasprintf(GFP_KERNEL, "%s-online", psy->name); 134 136 if (!psy->online_trig_name) 135 - goto online_failed; 137 + return -ENOMEM; 136 138 137 139 led_trigger_register_simple(psy->online_trig_name, &psy->online_trig); 138 140 139 - goto success; 140 - 141 - online_failed: 142 - rc = -ENOMEM; 143 - success: 144 - return rc; 141 + return 0; 145 142 } 146 143 147 144 static void power_supply_remove_gen_triggers(struct power_supply *psy)
+14 -10
drivers/power/power_supply_sysfs.c
··· 73 73 const ptrdiff_t off = attr - power_supply_attrs; 74 74 union power_supply_propval value; 75 75 76 - if (off == POWER_SUPPLY_PROP_TYPE) 76 + if (off == POWER_SUPPLY_PROP_TYPE) { 77 77 value.intval = psy->type; 78 - else 78 + } else { 79 79 ret = psy->get_property(psy, off, &value); 80 80 81 - if (ret < 0) { 82 - if (ret == -ENODATA) 83 - dev_dbg(dev, "driver has no data for `%s' property\n", 84 - attr->attr.name); 85 - else if (ret != -ENODEV) 86 - dev_err(dev, "driver failed to report `%s' property: %zd\n", 87 - attr->attr.name, ret); 88 - return ret; 81 + if (ret < 0) { 82 + if (ret == -ENODATA) 83 + dev_dbg(dev, "driver has no data for `%s' property\n", 84 + attr->attr.name); 85 + else if (ret != -ENODEV) 86 + dev_err(dev, "driver failed to report `%s' property: %zd\n", 87 + attr->attr.name, ret); 88 + return ret; 89 + } 89 90 } 90 91 91 92 if (off == POWER_SUPPLY_PROP_STATUS) ··· 150 149 POWER_SUPPLY_ATTR(voltage_now), 151 150 POWER_SUPPLY_ATTR(voltage_avg), 152 151 POWER_SUPPLY_ATTR(voltage_ocv), 152 + POWER_SUPPLY_ATTR(voltage_boot), 153 153 POWER_SUPPLY_ATTR(current_max), 154 154 POWER_SUPPLY_ATTR(current_now), 155 155 POWER_SUPPLY_ATTR(current_avg), 156 + POWER_SUPPLY_ATTR(current_boot), 156 157 POWER_SUPPLY_ATTR(power_now), 157 158 POWER_SUPPLY_ATTR(power_avg), 158 159 POWER_SUPPLY_ATTR(charge_full_design), ··· 196 193 POWER_SUPPLY_ATTR(type), 197 194 POWER_SUPPLY_ATTR(scope), 198 195 POWER_SUPPLY_ATTR(charge_term_current), 196 + POWER_SUPPLY_ATTR(calibrate), 199 197 /* Properties of type `const char *' */ 200 198 POWER_SUPPLY_ATTR(model_name), 201 199 POWER_SUPPLY_ATTR(manufacturer),
+31 -2
drivers/power/reset/Kconfig
··· 40 40 41 41 config POWER_RESET_BRCMSTB 42 42 bool "Broadcom STB reset driver" if COMPILE_TEST 43 - depends on POWER_RESET && ARM 43 + depends on ARM 44 44 default ARCH_BRCMSTB 45 45 help 46 46 This driver provides restart support for ARM-based Broadcom STB ··· 57 57 If your board needs a GPIO high/low to power down, say Y and 58 58 create a binding in your devicetree. 59 59 60 + config POWER_RESET_GPIO_RESTART 61 + bool "GPIO restart driver" 62 + depends on OF_GPIO 63 + help 64 + This driver supports restarting your board via a GPIO line. 65 + If your board needs a GPIO high/low to restart, say Y and 66 + create a binding in your devicetree. 67 + 60 68 config POWER_RESET_HISI 61 69 bool "Hisilicon power-off driver" 62 - depends on POWER_RESET && ARCH_HISI 70 + depends on ARCH_HISI 63 71 help 64 72 Reboot support for Hisilicon boards. 65 73 ··· 76 68 depends on ARCH_QCOM 77 69 help 78 70 Power off and restart support for Qualcomm boards. 71 + 72 + config POWER_RESET_LTC2952 73 + bool "LTC2952 PowerPath power-off driver" 74 + depends on OF_GPIO 75 + help 76 + This driver supports an external powerdown trigger and board power 77 + down via the LTC2952. Bindings are made in the device tree. 79 78 80 79 config POWER_RESET_QNAP 81 80 bool "QNAP power-off driver" ··· 106 91 depends on ARCH_SUNXI 107 92 help 108 93 Reboot support for the Allwinner A31 SoCs. 94 + 95 + config POWER_RESET_ST 96 + bool "ST restart power-off driver" 97 + depends on ARCH_STI 98 + help 99 + Power off and reset support for STMicroelectronics boards. 109 100 110 101 config POWER_RESET_VERSATILE 111 102 bool "ARM Versatile family reboot driver" ··· 143 122 help 144 123 Reboot support for the KEYSTONE SoCs. 145 124 125 + config POWER_RESET_SYSCON 126 + bool "Generic SYSCON regmap reset driver" 127 + depends on OF 128 + select MFD_SYSCON 129 + help 130 + Reboot support for generic SYSCON mapped register reset. 131 + 146 132 endif 133 +
+4
drivers/power/reset/Makefile
··· 4 4 obj-$(CONFIG_POWER_RESET_AXXIA) += axxia-reset.o 5 5 obj-$(CONFIG_POWER_RESET_BRCMSTB) += brcmstb-reboot.o 6 6 obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o 7 + obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o 7 8 obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o 8 9 obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o 10 + obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o 9 11 obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o 10 12 obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o 11 13 obj-$(CONFIG_POWER_RESET_SUN6I) += sun6i-reboot.o 14 + obj-$(CONFIG_POWER_RESET_ST) += st-poweroff.o 12 15 obj-$(CONFIG_POWER_RESET_VERSATILE) += arm-versatile-reboot.o 13 16 obj-$(CONFIG_POWER_RESET_VEXPRESS) += vexpress-poweroff.o 14 17 obj-$(CONFIG_POWER_RESET_XGENE) += xgene-reboot.o 15 18 obj-$(CONFIG_POWER_RESET_KEYSTONE) += keystone-reset.o 19 + obj-$(CONFIG_POWER_RESET_SYSCON) += syscon-reboot.o
+149
drivers/power/reset/gpio-restart.c
··· 1 + /* 2 + * Toggles a GPIO pin to restart a device 3 + * 4 + * Copyright (C) 2014 Google, Inc. 5 + * 6 + * This software is licensed under the terms of the GNU General Public 7 + * License version 2, as published by the Free Software Foundation, and 8 + * may be copied, distributed, and modified under those terms. 9 + * 10 + * This program is distributed in the hope that it will be useful, 11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 + * GNU General Public License for more details. 14 + * 15 + * Based on the gpio-poweroff driver. 16 + */ 17 + #include <linux/reboot.h> 18 + #include <linux/kernel.h> 19 + #include <linux/init.h> 20 + #include <linux/delay.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/gpio/consumer.h> 23 + #include <linux/of_platform.h> 24 + #include <linux/module.h> 25 + 26 + struct gpio_restart { 27 + struct gpio_desc *reset_gpio; 28 + struct notifier_block restart_handler; 29 + u32 active_delay_ms; 30 + u32 inactive_delay_ms; 31 + u32 wait_delay_ms; 32 + }; 33 + 34 + static int gpio_restart_notify(struct notifier_block *this, 35 + unsigned long mode, void *cmd) 36 + { 37 + struct gpio_restart *gpio_restart = 38 + container_of(this, struct gpio_restart, restart_handler); 39 + 40 + /* drive it active, also inactive->active edge */ 41 + gpiod_direction_output(gpio_restart->reset_gpio, 1); 42 + mdelay(gpio_restart->active_delay_ms); 43 + 44 + /* drive inactive, also active->inactive edge */ 45 + gpiod_set_value(gpio_restart->reset_gpio, 0); 46 + mdelay(gpio_restart->inactive_delay_ms); 47 + 48 + /* drive it active, also inactive->active edge */ 49 + gpiod_set_value(gpio_restart->reset_gpio, 1); 50 + 51 + /* give it some time */ 52 + mdelay(gpio_restart->wait_delay_ms); 53 + 54 + WARN_ON(1); 55 + 56 + return NOTIFY_DONE; 57 + } 58 + 59 + static int gpio_restart_probe(struct platform_device *pdev) 60 + { 61 + struct gpio_restart *gpio_restart; 62 + bool open_source = false; 63 + u32 property; 64 + int ret; 65 + 66 + gpio_restart = devm_kzalloc(&pdev->dev, sizeof(*gpio_restart), 67 + GFP_KERNEL); 68 + if (!gpio_restart) 69 + return -ENOMEM; 70 + 71 + open_source = of_property_read_bool(pdev->dev.of_node, "open-source"); 72 + 73 + gpio_restart->reset_gpio = devm_gpiod_get(&pdev->dev, NULL, 74 + open_source ? GPIOD_IN : GPIOD_OUT_LOW); 75 + if (IS_ERR(gpio_restart->reset_gpio)) { 76 + dev_err(&pdev->dev, "Could net get reset GPIO\n"); 77 + return PTR_ERR(gpio_restart->reset_gpio); 78 + } 79 + 80 + gpio_restart->restart_handler.notifier_call = gpio_restart_notify; 81 + gpio_restart->restart_handler.priority = 128; 82 + gpio_restart->active_delay_ms = 100; 83 + gpio_restart->inactive_delay_ms = 100; 84 + gpio_restart->wait_delay_ms = 3000; 85 + 86 + ret = of_property_read_u32(pdev->dev.of_node, "priority", &property); 87 + if (!ret) { 88 + if (property > 255) 89 + dev_err(&pdev->dev, "Invalid priority property: %u\n", 90 + property); 91 + else 92 + gpio_restart->restart_handler.priority = property; 93 + } 94 + 95 + of_property_read_u32(pdev->dev.of_node, "active-delay", 96 + &gpio_restart->active_delay_ms); 97 + of_property_read_u32(pdev->dev.of_node, "inactive-delay", 98 + &gpio_restart->inactive_delay_ms); 99 + of_property_read_u32(pdev->dev.of_node, "wait-delay", 100 + &gpio_restart->wait_delay_ms); 101 + 102 + platform_set_drvdata(pdev, gpio_restart); 103 + 104 + ret = register_restart_handler(&gpio_restart->restart_handler); 105 + if (ret) { 106 + dev_err(&pdev->dev, "%s: cannot register restart handler, %d\n", 107 + __func__, ret); 108 + return -ENODEV; 109 + } 110 + 111 + return 0; 112 + } 113 + 114 + static int gpio_restart_remove(struct platform_device *pdev) 115 + { 116 + struct gpio_restart *gpio_restart = platform_get_drvdata(pdev); 117 + int ret; 118 + 119 + ret = unregister_restart_handler(&gpio_restart->restart_handler); 120 + if (ret) { 121 + dev_err(&pdev->dev, 122 + "%s: cannot unregister restart handler, %d\n", 123 + __func__, ret); 124 + return -ENODEV; 125 + } 126 + 127 + return 0; 128 + } 129 + 130 + static const struct of_device_id of_gpio_restart_match[] = { 131 + { .compatible = "gpio-restart", }, 132 + {}, 133 + }; 134 + 135 + static struct platform_driver gpio_restart_driver = { 136 + .probe = gpio_restart_probe, 137 + .remove = gpio_restart_remove, 138 + .driver = { 139 + .name = "restart-gpio", 140 + .owner = THIS_MODULE, 141 + .of_match_table = of_gpio_restart_match, 142 + }, 143 + }; 144 + 145 + module_platform_driver(gpio_restart_driver); 146 + 147 + MODULE_AUTHOR("David Riley <davidriley@chromium.org>"); 148 + MODULE_DESCRIPTION("GPIO restart driver"); 149 + MODULE_LICENSE("GPL");
+386
drivers/power/reset/ltc2952-poweroff.c
··· 1 + /* 2 + * LTC2952 (PowerPath) driver 3 + * 4 + * Copyright (C) 2014, Xsens Technologies BV <info@xsens.com> 5 + * Maintainer: Ren� Moll <linux@r-moll.nl> 6 + * 7 + * This program is free software; you can redistribute it and/or 8 + * modify it under the terms of the GNU General Public License 9 + * as published by the Free Software Foundation; either version 2 10 + * of the License, or (at your option) any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + * ---------------------------------------- 18 + * - Description 19 + * ---------------------------------------- 20 + * 21 + * This driver is to be used with an external PowerPath Controller (LTC2952). 22 + * Its function is to determine when a external shut down is triggered 23 + * and react by properly shutting down the system. 24 + * 25 + * This driver expects a device tree with a ltc2952 entry for pin mapping. 26 + * 27 + * ---------------------------------------- 28 + * - GPIO 29 + * ---------------------------------------- 30 + * 31 + * The following GPIOs are used: 32 + * - trigger (input) 33 + * A level change indicates the shut-down trigger. If it's state reverts 34 + * within the time-out defined by trigger_delay, the shut down is not 35 + * executed. 36 + * 37 + * - watchdog (output) 38 + * Once a shut down is triggered, the driver will toggle this signal, 39 + * with an internal (wde_interval) to stall the hardware shut down. 40 + * 41 + * - kill (output) 42 + * The last action during shut down is triggering this signalling, such 43 + * that the PowerPath Control will power down the hardware. 44 + * 45 + * ---------------------------------------- 46 + * - Interrupts 47 + * ---------------------------------------- 48 + * 49 + * The driver requires a non-shared, edge-triggered interrupt on the trigger 50 + * GPIO. 51 + * 52 + */ 53 + 54 + #include <linux/kernel.h> 55 + #include <linux/init.h> 56 + #include <linux/interrupt.h> 57 + #include <linux/device.h> 58 + #include <linux/platform_device.h> 59 + #include <linux/ktime.h> 60 + #include <linux/slab.h> 61 + #include <linux/kmod.h> 62 + #include <linux/module.h> 63 + #include <linux/gpio/consumer.h> 64 + #include <linux/reboot.h> 65 + 66 + struct ltc2952_poweroff_data { 67 + struct hrtimer timer_trigger; 68 + struct hrtimer timer_wde; 69 + 70 + ktime_t trigger_delay; 71 + ktime_t wde_interval; 72 + 73 + struct device *dev; 74 + 75 + unsigned int virq; 76 + 77 + /** 78 + * 0: trigger 79 + * 1: watchdog 80 + * 2: kill 81 + */ 82 + struct gpio_desc *gpio[3]; 83 + }; 84 + 85 + static int ltc2952_poweroff_panic; 86 + static struct ltc2952_poweroff_data *ltc2952_data; 87 + 88 + #define POWERPATH_IO_TRIGGER 0 89 + #define POWERPATH_IO_WATCHDOG 1 90 + #define POWERPATH_IO_KILL 2 91 + 92 + /** 93 + * ltc2952_poweroff_timer_wde - Timer callback 94 + * Toggles the watchdog reset signal each wde_interval 95 + * 96 + * @timer: corresponding timer 97 + * 98 + * Returns HRTIMER_RESTART for an infinite loop which will only stop when the 99 + * machine actually shuts down 100 + */ 101 + static enum hrtimer_restart ltc2952_poweroff_timer_wde(struct hrtimer *timer) 102 + { 103 + ktime_t now; 104 + int state; 105 + unsigned long overruns; 106 + 107 + if (ltc2952_poweroff_panic) 108 + return HRTIMER_NORESTART; 109 + 110 + state = gpiod_get_value(ltc2952_data->gpio[POWERPATH_IO_WATCHDOG]); 111 + gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_WATCHDOG], !state); 112 + 113 + now = hrtimer_cb_get_time(timer); 114 + overruns = hrtimer_forward(timer, now, ltc2952_data->wde_interval); 115 + 116 + return HRTIMER_RESTART; 117 + } 118 + 119 + static enum hrtimer_restart ltc2952_poweroff_timer_trigger( 120 + struct hrtimer *timer) 121 + { 122 + int ret; 123 + 124 + ret = hrtimer_start(&ltc2952_data->timer_wde, 125 + ltc2952_data->wde_interval, HRTIMER_MODE_REL); 126 + 127 + if (ret) { 128 + dev_err(ltc2952_data->dev, "unable to start the timer\n"); 129 + /* 130 + * The device will not toggle the watchdog reset, 131 + * thus shut down is only safe if the PowerPath controller 132 + * has a long enough time-off before triggering a hardware 133 + * power-off. 134 + * 135 + * Only sending a warning as the system will power-off anyway 136 + */ 137 + } 138 + 139 + dev_info(ltc2952_data->dev, "executing shutdown\n"); 140 + 141 + orderly_poweroff(true); 142 + 143 + return HRTIMER_NORESTART; 144 + } 145 + 146 + /** 147 + * ltc2952_poweroff_handler - Interrupt handler 148 + * Triggered each time the trigger signal changes state and (de)activates a 149 + * time-out (timer_trigger). Once the time-out is actually reached the shut 150 + * down is executed. 151 + * 152 + * @irq: IRQ number 153 + * @dev_id: pointer to the main data structure 154 + */ 155 + static irqreturn_t ltc2952_poweroff_handler(int irq, void *dev_id) 156 + { 157 + int ret; 158 + struct ltc2952_poweroff_data *data = dev_id; 159 + 160 + if (ltc2952_poweroff_panic) 161 + goto irq_ok; 162 + 163 + if (hrtimer_active(&data->timer_wde)) { 164 + /* shutdown is already triggered, nothing to do any more */ 165 + goto irq_ok; 166 + } 167 + 168 + if (!hrtimer_active(&data->timer_trigger)) { 169 + ret = hrtimer_start(&data->timer_trigger, data->trigger_delay, 170 + HRTIMER_MODE_REL); 171 + 172 + if (ret) 173 + dev_err(data->dev, "unable to start the wait timer\n"); 174 + } else { 175 + ret = hrtimer_cancel(&data->timer_trigger); 176 + /* omitting return value check, timer should have been valid */ 177 + } 178 + 179 + irq_ok: 180 + return IRQ_HANDLED; 181 + } 182 + 183 + static void ltc2952_poweroff_kill(void) 184 + { 185 + gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_KILL], 1); 186 + } 187 + 188 + static int ltc2952_poweroff_suspend(struct platform_device *pdev, 189 + pm_message_t state) 190 + { 191 + return -ENOSYS; 192 + } 193 + 194 + static int ltc2952_poweroff_resume(struct platform_device *pdev) 195 + { 196 + return -ENOSYS; 197 + } 198 + 199 + static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data) 200 + { 201 + unsigned int i; 202 + 203 + for (i = 0; i < ARRAY_SIZE(data->gpio); i++) 204 + data->gpio[i] = NULL; 205 + 206 + data->wde_interval = ktime_set(0, 300L*1E6L); 207 + data->trigger_delay = ktime_set(2, 500L*1E6L); 208 + 209 + hrtimer_init(&data->timer_trigger, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 210 + data->timer_trigger.function = &ltc2952_poweroff_timer_trigger; 211 + 212 + hrtimer_init(&data->timer_wde, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 213 + data->timer_wde.function = &ltc2952_poweroff_timer_wde; 214 + } 215 + 216 + static int ltc2952_poweroff_init(struct platform_device *pdev) 217 + { 218 + int ret, virq; 219 + unsigned int i; 220 + struct ltc2952_poweroff_data *data; 221 + 222 + static char *name[] = { 223 + "trigger", 224 + "watchdog", 225 + "kill", 226 + NULL 227 + }; 228 + 229 + data = ltc2952_data; 230 + ltc2952_poweroff_default(ltc2952_data); 231 + 232 + for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) { 233 + ltc2952_data->gpio[i] = gpiod_get(&pdev->dev, name[i]); 234 + 235 + if (IS_ERR(ltc2952_data->gpio[i])) { 236 + ret = PTR_ERR(ltc2952_data->gpio[i]); 237 + dev_err(&pdev->dev, 238 + "unable to claim the following gpio: %s\n", 239 + name[i]); 240 + goto err_io; 241 + } 242 + } 243 + 244 + ret = gpiod_direction_output( 245 + ltc2952_data->gpio[POWERPATH_IO_WATCHDOG], 0); 246 + if (ret) { 247 + dev_err(&pdev->dev, "unable to use watchdog-gpio as output\n"); 248 + goto err_io; 249 + } 250 + 251 + ret = gpiod_direction_output(ltc2952_data->gpio[POWERPATH_IO_KILL], 0); 252 + if (ret) { 253 + dev_err(&pdev->dev, "unable to use kill-gpio as output\n"); 254 + goto err_io; 255 + } 256 + 257 + virq = gpiod_to_irq(ltc2952_data->gpio[POWERPATH_IO_TRIGGER]); 258 + if (virq < 0) { 259 + dev_err(&pdev->dev, "cannot map GPIO as interrupt"); 260 + goto err_io; 261 + } 262 + 263 + ltc2952_data->virq = virq; 264 + ret = request_irq(virq, 265 + ltc2952_poweroff_handler, 266 + (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING), 267 + "ltc2952-poweroff", 268 + ltc2952_data 269 + ); 270 + 271 + if (ret) { 272 + dev_err(&pdev->dev, "cannot configure an interrupt handler\n"); 273 + goto err_io; 274 + } 275 + 276 + return 0; 277 + 278 + err_io: 279 + for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) 280 + if (ltc2952_data->gpio[i]) 281 + gpiod_put(ltc2952_data->gpio[i]); 282 + 283 + return ret; 284 + } 285 + 286 + static int ltc2952_poweroff_probe(struct platform_device *pdev) 287 + { 288 + int ret; 289 + 290 + if (pm_power_off) { 291 + dev_err(&pdev->dev, "pm_power_off already registered"); 292 + return -EBUSY; 293 + } 294 + 295 + ltc2952_data = kzalloc(sizeof(*ltc2952_data), GFP_KERNEL); 296 + if (!ltc2952_data) 297 + return -ENOMEM; 298 + 299 + ltc2952_data->dev = &pdev->dev; 300 + 301 + ret = ltc2952_poweroff_init(pdev); 302 + if (ret) 303 + goto err; 304 + 305 + pm_power_off = &ltc2952_poweroff_kill; 306 + 307 + dev_info(&pdev->dev, "probe successful\n"); 308 + 309 + return 0; 310 + 311 + err: 312 + kfree(ltc2952_data); 313 + return ret; 314 + } 315 + 316 + static int ltc2952_poweroff_remove(struct platform_device *pdev) 317 + { 318 + unsigned int i; 319 + 320 + pm_power_off = NULL; 321 + 322 + if (ltc2952_data) { 323 + free_irq(ltc2952_data->virq, ltc2952_data); 324 + 325 + for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) 326 + gpiod_put(ltc2952_data->gpio[i]); 327 + 328 + kfree(ltc2952_data); 329 + } 330 + 331 + return 0; 332 + } 333 + 334 + static const struct of_device_id of_ltc2952_poweroff_match[] = { 335 + { .compatible = "lltc,ltc2952"}, 336 + {}, 337 + }; 338 + MODULE_DEVICE_TABLE(of, of_ltc2952_poweroff_match); 339 + 340 + static struct platform_driver ltc2952_poweroff_driver = { 341 + .probe = ltc2952_poweroff_probe, 342 + .remove = ltc2952_poweroff_remove, 343 + .driver = { 344 + .name = "ltc2952-poweroff", 345 + .owner = THIS_MODULE, 346 + .of_match_table = of_ltc2952_poweroff_match, 347 + }, 348 + .suspend = ltc2952_poweroff_suspend, 349 + .resume = ltc2952_poweroff_resume, 350 + }; 351 + 352 + static int ltc2952_poweroff_notify_panic(struct notifier_block *nb, 353 + unsigned long code, void *unused) 354 + { 355 + ltc2952_poweroff_panic = 1; 356 + return NOTIFY_DONE; 357 + } 358 + 359 + static struct notifier_block ltc2952_poweroff_panic_nb = { 360 + .notifier_call = ltc2952_poweroff_notify_panic, 361 + }; 362 + 363 + static int __init ltc2952_poweroff_platform_init(void) 364 + { 365 + ltc2952_poweroff_panic = 0; 366 + 367 + atomic_notifier_chain_register(&panic_notifier_list, 368 + &ltc2952_poweroff_panic_nb); 369 + 370 + return platform_driver_register(&ltc2952_poweroff_driver); 371 + } 372 + 373 + static void __exit ltc2952_poweroff_platform_exit(void) 374 + { 375 + atomic_notifier_chain_unregister(&panic_notifier_list, 376 + &ltc2952_poweroff_panic_nb); 377 + 378 + platform_driver_unregister(&ltc2952_poweroff_driver); 379 + } 380 + 381 + module_init(ltc2952_poweroff_platform_init); 382 + module_exit(ltc2952_poweroff_platform_exit); 383 + 384 + MODULE_AUTHOR("Ren� Moll <rene.moll@xsens.com>"); 385 + MODULE_DESCRIPTION("LTC PowerPath power-off driver"); 386 + MODULE_LICENSE("GPL v2");
+14 -6
drivers/power/reset/msm-poweroff.c
··· 20 20 #include <linux/platform_device.h> 21 21 #include <linux/module.h> 22 22 #include <linux/reboot.h> 23 - 24 - #include <asm/system_misc.h> 23 + #include <linux/pm.h> 25 24 26 25 static void __iomem *msm_ps_hold; 27 - 28 - static void do_msm_restart(enum reboot_mode reboot_mode, const char *cmd) 26 + static int do_msm_restart(struct notifier_block *nb, unsigned long action, 27 + void *data) 29 28 { 30 29 writel(0, msm_ps_hold); 31 30 mdelay(10000); 31 + 32 + return NOTIFY_DONE; 32 33 } 34 + 35 + static struct notifier_block restart_nb = { 36 + .notifier_call = do_msm_restart, 37 + .priority = 128, 38 + }; 33 39 34 40 static void do_msm_poweroff(void) 35 41 { 36 42 /* TODO: Add poweroff capability */ 37 - do_msm_restart(REBOOT_HARD, NULL); 43 + do_msm_restart(&restart_nb, 0, NULL); 38 44 } 39 45 40 46 static int msm_restart_probe(struct platform_device *pdev) ··· 53 47 if (IS_ERR(msm_ps_hold)) 54 48 return PTR_ERR(msm_ps_hold); 55 49 50 + register_restart_handler(&restart_nb); 51 + 56 52 pm_power_off = do_msm_poweroff; 57 - arm_pm_restart = do_msm_restart; 53 + 58 54 return 0; 59 55 } 60 56
+151
drivers/power/reset/st-poweroff.c
··· 1 + /* 2 + * Copyright (C) 2014 STMicroelectronics 3 + * 4 + * Power off Restart driver, used in STMicroelectronics devices. 5 + * 6 + * Author: Christophe Kerello <christophe.kerello@st.com> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2, as 10 + * published by the Free Software Foundation. 11 + */ 12 + 13 + #include <linux/module.h> 14 + #include <linux/of.h> 15 + #include <linux/of_platform.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/mfd/syscon.h> 18 + #include <linux/regmap.h> 19 + 20 + #include <asm/system_misc.h> 21 + 22 + struct reset_syscfg { 23 + struct regmap *regmap; 24 + /* syscfg used for reset */ 25 + unsigned int offset_rst; 26 + unsigned int mask_rst; 27 + /* syscfg used for unmask the reset */ 28 + unsigned int offset_rst_msk; 29 + unsigned int mask_rst_msk; 30 + }; 31 + 32 + /* STiH415 */ 33 + #define STIH415_SYSCFG_11 0x2c 34 + #define STIH415_SYSCFG_15 0x3c 35 + 36 + static struct reset_syscfg stih415_reset = { 37 + .offset_rst = STIH415_SYSCFG_11, 38 + .mask_rst = BIT(0), 39 + .offset_rst_msk = STIH415_SYSCFG_15, 40 + .mask_rst_msk = BIT(0) 41 + }; 42 + 43 + /* STiH416 */ 44 + #define STIH416_SYSCFG_500 0x7d0 45 + #define STIH416_SYSCFG_504 0x7e0 46 + 47 + static struct reset_syscfg stih416_reset = { 48 + .offset_rst = STIH416_SYSCFG_500, 49 + .mask_rst = BIT(0), 50 + .offset_rst_msk = STIH416_SYSCFG_504, 51 + .mask_rst_msk = BIT(0) 52 + }; 53 + 54 + /* STiH407 */ 55 + #define STIH407_SYSCFG_4000 0x0 56 + #define STIH407_SYSCFG_4008 0x20 57 + 58 + static struct reset_syscfg stih407_reset = { 59 + .offset_rst = STIH407_SYSCFG_4000, 60 + .mask_rst = BIT(0), 61 + .offset_rst_msk = STIH407_SYSCFG_4008, 62 + .mask_rst_msk = BIT(0) 63 + }; 64 + 65 + /* STiD127 */ 66 + #define STID127_SYSCFG_700 0x0 67 + #define STID127_SYSCFG_773 0x124 68 + 69 + static struct reset_syscfg stid127_reset = { 70 + .offset_rst = STID127_SYSCFG_773, 71 + .mask_rst = BIT(0), 72 + .offset_rst_msk = STID127_SYSCFG_700, 73 + .mask_rst_msk = BIT(8) 74 + }; 75 + 76 + static struct reset_syscfg *st_restart_syscfg; 77 + 78 + static void st_restart(enum reboot_mode reboot_mode, const char *cmd) 79 + { 80 + /* reset syscfg updated */ 81 + regmap_update_bits(st_restart_syscfg->regmap, 82 + st_restart_syscfg->offset_rst, 83 + st_restart_syscfg->mask_rst, 84 + 0); 85 + 86 + /* unmask the reset */ 87 + regmap_update_bits(st_restart_syscfg->regmap, 88 + st_restart_syscfg->offset_rst_msk, 89 + st_restart_syscfg->mask_rst_msk, 90 + 0); 91 + } 92 + 93 + static struct of_device_id st_reset_of_match[] = { 94 + { 95 + .compatible = "st,stih415-restart", 96 + .data = (void *)&stih415_reset, 97 + }, { 98 + .compatible = "st,stih416-restart", 99 + .data = (void *)&stih416_reset, 100 + }, { 101 + .compatible = "st,stih407-restart", 102 + .data = (void *)&stih407_reset, 103 + }, { 104 + .compatible = "st,stid127-restart", 105 + .data = (void *)&stid127_reset, 106 + }, 107 + {} 108 + }; 109 + 110 + static int st_reset_probe(struct platform_device *pdev) 111 + { 112 + struct device_node *np = pdev->dev.of_node; 113 + const struct of_device_id *match; 114 + struct device *dev = &pdev->dev; 115 + 116 + match = of_match_device(st_reset_of_match, dev); 117 + if (!match) 118 + return -ENODEV; 119 + 120 + st_restart_syscfg = (struct reset_syscfg *)match->data; 121 + 122 + st_restart_syscfg->regmap = 123 + syscon_regmap_lookup_by_phandle(np, "st,syscfg"); 124 + if (IS_ERR(st_restart_syscfg->regmap)) { 125 + dev_err(dev, "No syscfg phandle specified\n"); 126 + return PTR_ERR(st_restart_syscfg->regmap); 127 + } 128 + 129 + arm_pm_restart = st_restart; 130 + 131 + return 0; 132 + } 133 + 134 + static struct platform_driver st_reset_driver = { 135 + .probe = st_reset_probe, 136 + .driver = { 137 + .name = "st_reset", 138 + .of_match_table = st_reset_of_match, 139 + }, 140 + }; 141 + 142 + static int __init st_reset_init(void) 143 + { 144 + return platform_driver_register(&st_reset_driver); 145 + } 146 + 147 + device_initcall(st_reset_init); 148 + 149 + MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>"); 150 + MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver"); 151 + MODULE_LICENSE("GPL v2");
+91
drivers/power/reset/syscon-reboot.c
··· 1 + /* 2 + * Generic Syscon Reboot Driver 3 + * 4 + * Copyright (c) 2013, Applied Micro Circuits Corporation 5 + * Author: Feng Kan <fkan@apm.com> 6 + * 7 + * This program is free software; you can redistribute it and/or 8 + * modify it under the terms of the GNU General Public License as 9 + * published by the Free Software Foundation; either version 2 of 10 + * the License, or (at your option) any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + */ 17 + #include <linux/delay.h> 18 + #include <linux/io.h> 19 + #include <linux/notifier.h> 20 + #include <linux/mfd/syscon.h> 21 + #include <linux/of_address.h> 22 + #include <linux/of_device.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/reboot.h> 25 + #include <linux/regmap.h> 26 + 27 + struct syscon_reboot_context { 28 + struct regmap *map; 29 + u32 offset; 30 + u32 mask; 31 + struct notifier_block restart_handler; 32 + }; 33 + 34 + static int syscon_restart_handle(struct notifier_block *this, 35 + unsigned long mode, void *cmd) 36 + { 37 + struct syscon_reboot_context *ctx = 38 + container_of(this, struct syscon_reboot_context, 39 + restart_handler); 40 + 41 + /* Issue the reboot */ 42 + regmap_write(ctx->map, ctx->offset, ctx->mask); 43 + 44 + mdelay(1000); 45 + 46 + pr_emerg("Unable to restart system\n"); 47 + return NOTIFY_DONE; 48 + } 49 + 50 + static int syscon_reboot_probe(struct platform_device *pdev) 51 + { 52 + struct syscon_reboot_context *ctx; 53 + struct device *dev = &pdev->dev; 54 + int err; 55 + 56 + ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); 57 + if (!ctx) 58 + return -ENOMEM; 59 + 60 + ctx->map = syscon_regmap_lookup_by_phandle(dev->of_node, "regmap"); 61 + if (IS_ERR(ctx->map)) 62 + return PTR_ERR(ctx->map); 63 + 64 + if (of_property_read_u32(pdev->dev.of_node, "offset", &ctx->offset)) 65 + return -EINVAL; 66 + 67 + if (of_property_read_u32(pdev->dev.of_node, "mask", &ctx->mask)) 68 + return -EINVAL; 69 + 70 + ctx->restart_handler.notifier_call = syscon_restart_handle; 71 + ctx->restart_handler.priority = 128; 72 + err = register_restart_handler(&ctx->restart_handler); 73 + if (err) 74 + dev_err(dev, "can't register restart notifier (err=%d)\n", err); 75 + 76 + return err; 77 + } 78 + 79 + static struct of_device_id syscon_reboot_of_match[] = { 80 + { .compatible = "syscon-reboot" }, 81 + {} 82 + }; 83 + 84 + static struct platform_driver syscon_reboot_driver = { 85 + .probe = syscon_reboot_probe, 86 + .driver = { 87 + .name = "syscon-reboot", 88 + .of_match_table = syscon_reboot_of_match, 89 + }, 90 + }; 91 + module_platform_driver(syscon_reboot_driver);
+1 -1
drivers/power/reset/xgene-reboot.c
··· 40 40 41 41 static struct xgene_reboot_context *xgene_restart_ctx; 42 42 43 - static void xgene_restart(char str, const char *cmd) 43 + static void xgene_restart(enum reboot_mode mode, const char *cmd) 44 44 { 45 45 struct xgene_reboot_context *ctx = xgene_restart_ctx; 46 46 unsigned long timeout;
+123 -2
drivers/power/sbs-battery.c
··· 48 48 REG_FULL_CHARGE_CAPACITY_CHARGE, 49 49 REG_DESIGN_CAPACITY, 50 50 REG_DESIGN_CAPACITY_CHARGE, 51 - REG_DESIGN_VOLTAGE, 51 + REG_DESIGN_VOLTAGE_MIN, 52 + REG_DESIGN_VOLTAGE_MAX, 53 + REG_MANUFACTURER, 54 + REG_MODEL_NAME, 52 55 }; 53 56 54 57 /* Battery Mode defines */ ··· 71 68 #define BATTERY_FULL_CHARGED 0x20 72 69 #define BATTERY_FULL_DISCHARGED 0x10 73 70 71 + /* min_value and max_value are only valid for numerical data */ 74 72 #define SBS_DATA(_psp, _addr, _min_value, _max_value) { \ 75 73 .psp = _psp, \ 76 74 .addr = _addr, \ ··· 115 111 SBS_DATA(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 0x18, 0, 65535), 116 112 [REG_DESIGN_CAPACITY_CHARGE] = 117 113 SBS_DATA(POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 0x18, 0, 65535), 118 - [REG_DESIGN_VOLTAGE] = 114 + [REG_DESIGN_VOLTAGE_MIN] = 115 + SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 0x19, 0, 65535), 116 + [REG_DESIGN_VOLTAGE_MAX] = 119 117 SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, 65535), 120 118 [REG_SERIAL_NUMBER] = 121 119 SBS_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535), 120 + /* Properties of type `const char *' */ 121 + [REG_MANUFACTURER] = 122 + SBS_DATA(POWER_SUPPLY_PROP_MANUFACTURER, 0x20, 0, 65535), 123 + [REG_MODEL_NAME] = 124 + SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535) 122 125 }; 123 126 124 127 static enum power_supply_property sbs_properties[] = { ··· 141 130 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, 142 131 POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, 143 132 POWER_SUPPLY_PROP_SERIAL_NUMBER, 133 + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 144 134 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 145 135 POWER_SUPPLY_PROP_ENERGY_NOW, 146 136 POWER_SUPPLY_PROP_ENERGY_FULL, ··· 149 137 POWER_SUPPLY_PROP_CHARGE_NOW, 150 138 POWER_SUPPLY_PROP_CHARGE_FULL, 151 139 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 140 + /* Properties of type `const char *' */ 141 + POWER_SUPPLY_PROP_MANUFACTURER, 142 + POWER_SUPPLY_PROP_MODEL_NAME 152 143 }; 153 144 154 145 struct sbs_info { ··· 167 152 struct delayed_work work; 168 153 int ignore_changes; 169 154 }; 155 + 156 + static char model_name[I2C_SMBUS_BLOCK_MAX + 1]; 157 + static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; 170 158 171 159 static int sbs_read_word_data(struct i2c_client *client, u8 address) 172 160 { ··· 193 175 __func__, address); 194 176 return ret; 195 177 } 178 + 179 + return le16_to_cpu(ret); 180 + } 181 + 182 + static int sbs_read_string_data(struct i2c_client *client, u8 address, 183 + char *values) 184 + { 185 + struct sbs_info *chip = i2c_get_clientdata(client); 186 + s32 ret = 0, block_length = 0; 187 + int retries_length = 1, retries_block = 1; 188 + u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1]; 189 + 190 + if (chip->pdata) { 191 + retries_length = max(chip->pdata->i2c_retry_count + 1, 1); 192 + retries_block = max(chip->pdata->i2c_retry_count + 1, 1); 193 + } 194 + 195 + /* Adapter needs to support these two functions */ 196 + if (!i2c_check_functionality(client->adapter, 197 + I2C_FUNC_SMBUS_BYTE_DATA | 198 + I2C_FUNC_SMBUS_I2C_BLOCK)){ 199 + return -ENODEV; 200 + } 201 + 202 + /* Get the length of block data */ 203 + while (retries_length > 0) { 204 + ret = i2c_smbus_read_byte_data(client, address); 205 + if (ret >= 0) 206 + break; 207 + retries_length--; 208 + } 209 + 210 + if (ret < 0) { 211 + dev_dbg(&client->dev, 212 + "%s: i2c read at address 0x%x failed\n", 213 + __func__, address); 214 + return ret; 215 + } 216 + 217 + /* block_length does not include NULL terminator */ 218 + block_length = ret; 219 + if (block_length > I2C_SMBUS_BLOCK_MAX) { 220 + dev_err(&client->dev, 221 + "%s: Returned block_length is longer than 0x%x\n", 222 + __func__, I2C_SMBUS_BLOCK_MAX); 223 + return -EINVAL; 224 + } 225 + 226 + /* Get the block data */ 227 + while (retries_block > 0) { 228 + ret = i2c_smbus_read_i2c_block_data( 229 + client, address, 230 + block_length + 1, block_buffer); 231 + if (ret >= 0) 232 + break; 233 + retries_block--; 234 + } 235 + 236 + if (ret < 0) { 237 + dev_dbg(&client->dev, 238 + "%s: i2c read at address 0x%x failed\n", 239 + __func__, address); 240 + return ret; 241 + } 242 + 243 + /* block_buffer[0] == block_length */ 244 + memcpy(values, block_buffer + 1, block_length); 245 + values[block_length] = '\0'; 196 246 197 247 return le16_to_cpu(ret); 198 248 } ··· 404 318 return 0; 405 319 } 406 320 321 + static int sbs_get_battery_string_property(struct i2c_client *client, 322 + int reg_offset, enum power_supply_property psp, char *val) 323 + { 324 + s32 ret; 325 + 326 + ret = sbs_read_string_data(client, sbs_data[reg_offset].addr, val); 327 + 328 + if (ret < 0) 329 + return ret; 330 + 331 + return 0; 332 + } 333 + 407 334 static void sbs_unit_adjustment(struct i2c_client *client, 408 335 enum power_supply_property psp, union power_supply_propval *val) 409 336 { ··· 435 336 break; 436 337 437 338 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 339 + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 438 340 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 439 341 case POWER_SUPPLY_PROP_CURRENT_NOW: 440 342 case POWER_SUPPLY_PROP_CHARGE_NOW: ··· 597 497 case POWER_SUPPLY_PROP_TEMP: 598 498 case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: 599 499 case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG: 500 + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: 600 501 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: 601 502 ret = sbs_get_property_index(client, psp); 602 503 if (ret < 0) 603 504 break; 604 505 605 506 ret = sbs_get_battery_property(client, ret, psp, val); 507 + break; 508 + 509 + case POWER_SUPPLY_PROP_MODEL_NAME: 510 + ret = sbs_get_property_index(client, psp); 511 + if (ret < 0) 512 + break; 513 + 514 + ret = sbs_get_battery_string_property(client, ret, psp, 515 + model_name); 516 + val->strval = model_name; 517 + break; 518 + 519 + case POWER_SUPPLY_PROP_MANUFACTURER: 520 + ret = sbs_get_property_index(client, psp); 521 + if (ret < 0) 522 + break; 523 + 524 + ret = sbs_get_battery_string_property(client, ret, psp, 525 + manufacturer); 526 + val->strval = manufacturer; 606 527 break; 607 528 608 529 default:
+4 -76
drivers/regulator/max14577.c
··· 22 22 #include <linux/mfd/max14577-private.h> 23 23 #include <linux/regulator/of_regulator.h> 24 24 25 - /* 26 - * Valid limits of current for max14577 and max77836 chargers. 27 - * They must correspond to MBCICHWRCL and MBCICHWRCH fields in CHGCTRL4 28 - * register for given chipset. 29 - */ 30 - struct maxim_charger_current { 31 - /* Minimal current, set in CHGCTRL4/MBCICHWRCL, uA */ 32 - unsigned int min; 33 - /* 34 - * Minimal current when high setting is active, 35 - * set in CHGCTRL4/MBCICHWRCH, uA 36 - */ 37 - unsigned int high_start; 38 - /* Value of one step in high setting, uA */ 39 - unsigned int high_step; 40 - /* Maximum current of high setting, uA */ 41 - unsigned int max; 42 - }; 43 - 44 - /* Table of valid charger currents for different Maxim chipsets */ 45 - static const struct maxim_charger_current maxim_charger_currents[] = { 46 - [MAXIM_DEVICE_TYPE_UNKNOWN] = { 0, 0, 0, 0 }, 47 - [MAXIM_DEVICE_TYPE_MAX14577] = { 48 - .min = MAX14577_REGULATOR_CURRENT_LIMIT_MIN, 49 - .high_start = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START, 50 - .high_step = MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP, 51 - .max = MAX14577_REGULATOR_CURRENT_LIMIT_MAX, 52 - }, 53 - [MAXIM_DEVICE_TYPE_MAX77836] = { 54 - .min = MAX77836_REGULATOR_CURRENT_LIMIT_MIN, 55 - .high_start = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START, 56 - .high_step = MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP, 57 - .max = MAX77836_REGULATOR_CURRENT_LIMIT_MAX, 58 - }, 59 - }; 60 - 61 25 static int max14577_reg_is_enabled(struct regulator_dev *rdev) 62 26 { 63 27 int rid = rdev_get_id(rdev); ··· 67 103 static int max14577_reg_set_current_limit(struct regulator_dev *rdev, 68 104 int min_uA, int max_uA) 69 105 { 70 - int i, current_bits = 0xf; 71 106 u8 reg_data; 107 + int ret; 72 108 struct max14577 *max14577 = rdev_get_drvdata(rdev); 73 109 const struct maxim_charger_current *limits = 74 110 &maxim_charger_currents[max14577->dev_type]; ··· 76 112 if (rdev_get_id(rdev) != MAX14577_CHARGER) 77 113 return -EINVAL; 78 114 79 - if (min_uA > limits->max || max_uA < limits->min) 80 - return -EINVAL; 81 - 82 - if (max_uA < limits->high_start) { 83 - /* 84 - * Less than high_start, 85 - * so set the minimal current (turn only Low Bit off) 86 - */ 87 - u8 reg_data = 0x0 << CHGCTRL4_MBCICHWRCL_SHIFT; 88 - return max14577_update_reg(rdev->regmap, 89 - MAX14577_CHG_REG_CHG_CTRL4, 90 - CHGCTRL4_MBCICHWRCL_MASK, reg_data); 91 - } 92 - 93 - /* 94 - * max_uA is in range: <high_start, inifinite>, so search for 95 - * valid current starting from maximum current. 96 - */ 97 - for (i = limits->max; i >= limits->high_start; i -= limits->high_step) { 98 - if (i <= max_uA) 99 - break; 100 - current_bits--; 101 - } 102 - BUG_ON(current_bits < 0); /* Cannot happen */ 103 - 104 - /* Turn Low Bit on (use range high_start-max)... */ 105 - reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT; 106 - /* and set proper High Bits */ 107 - reg_data |= current_bits << CHGCTRL4_MBCICHWRCH_SHIFT; 115 + ret = maxim_charger_calc_reg_current(limits, min_uA, max_uA, &reg_data); 116 + if (ret) 117 + return ret; 108 118 109 119 return max14577_update_reg(rdev->regmap, MAX14577_CHG_REG_CHG_CTRL4, 110 120 CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK, ··· 380 442 381 443 static int __init max14577_regulator_init(void) 382 444 { 383 - /* Check for valid values for charger */ 384 - BUILD_BUG_ON(MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START + 385 - MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf != 386 - MAX14577_REGULATOR_CURRENT_LIMIT_MAX); 387 - BUILD_BUG_ON(MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START + 388 - MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf != 389 - MAX77836_REGULATOR_CURRENT_LIMIT_MAX); 390 - /* Valid charger current values must be provided for each chipset */ 391 - BUILD_BUG_ON(ARRAY_SIZE(maxim_charger_currents) != MAXIM_DEVICE_TYPE_NUM); 392 - 393 445 BUILD_BUG_ON(ARRAY_SIZE(max14577_supported_regulators) != MAX14577_REGULATOR_NUM); 394 446 BUILD_BUG_ON(ARRAY_SIZE(max77836_supported_regulators) != MAX77836_REGULATOR_NUM); 395 447
+69 -24
include/linux/mfd/max14577-private.h
··· 72 72 MAX14577_MUIC_REG_END, 73 73 }; 74 74 75 + /* 76 + * Combined charger types for max14577 and max77836. 77 + * 78 + * On max14577 three lower bits map to STATUS2/CHGTYP field. 79 + * However the max77836 has different two last values of STATUS2/CHGTYP. 80 + * To indicate the difference enum has two additional values for max77836. 81 + * These values are just a register value bitwise OR with 0x8. 82 + */ 75 83 enum max14577_muic_charger_type { 76 - MAX14577_CHARGER_TYPE_NONE = 0, 77 - MAX14577_CHARGER_TYPE_USB, 78 - MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT, 79 - MAX14577_CHARGER_TYPE_DEDICATED_CHG, 80 - MAX14577_CHARGER_TYPE_SPECIAL_500MA, 81 - MAX14577_CHARGER_TYPE_SPECIAL_1A, 82 - MAX14577_CHARGER_TYPE_RESERVED, 83 - MAX14577_CHARGER_TYPE_DEAD_BATTERY = 7, 84 + MAX14577_CHARGER_TYPE_NONE = 0x0, 85 + MAX14577_CHARGER_TYPE_USB = 0x1, 86 + MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT = 0x2, 87 + MAX14577_CHARGER_TYPE_DEDICATED_CHG = 0x3, 88 + MAX14577_CHARGER_TYPE_SPECIAL_500MA = 0x4, 89 + /* Special 1A or 2A charger */ 90 + MAX14577_CHARGER_TYPE_SPECIAL_1A = 0x5, 91 + /* max14577: reserved, used on max77836 */ 92 + MAX14577_CHARGER_TYPE_RESERVED = 0x6, 93 + /* max14577: dead-battery charing with maximum current 100mA */ 94 + MAX14577_CHARGER_TYPE_DEAD_BATTERY = 0x7, 95 + /* 96 + * max77836: special charger (bias on D+/D-), 97 + * matches register value of 0x6 98 + */ 99 + MAX77836_CHARGER_TYPE_SPECIAL_BIAS = 0xe, 100 + /* max77836: reserved, register value 0x7 */ 101 + MAX77836_CHARGER_TYPE_RESERVED = 0xf, 84 102 }; 85 103 86 104 /* MAX14577 interrupts */ ··· 139 121 #define STATUS2_CHGTYP_SHIFT 0 140 122 #define STATUS2_CHGDETRUN_SHIFT 3 141 123 #define STATUS2_DCDTMR_SHIFT 4 142 - #define STATUS2_DBCHG_SHIFT 5 124 + #define MAX14577_STATUS2_DBCHG_SHIFT 5 125 + #define MAX77836_STATUS2_DXOVP_SHIFT 5 143 126 #define STATUS2_VBVOLT_SHIFT 6 144 127 #define MAX77836_STATUS2_VIDRM_SHIFT 7 145 128 #define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT) 146 129 #define STATUS2_CHGDETRUN_MASK BIT(STATUS2_CHGDETRUN_SHIFT) 147 130 #define STATUS2_DCDTMR_MASK BIT(STATUS2_DCDTMR_SHIFT) 148 - #define STATUS2_DBCHG_MASK BIT(STATUS2_DBCHG_SHIFT) 131 + #define MAX14577_STATUS2_DBCHG_MASK BIT(MAX14577_STATUS2_DBCHG_SHIFT) 132 + #define MAX77836_STATUS2_DXOVP_MASK BIT(MAX77836_STATUS2_DXOVP_SHIFT) 149 133 #define STATUS2_VBVOLT_MASK BIT(STATUS2_VBVOLT_SHIFT) 150 134 #define MAX77836_STATUS2_VIDRM_MASK BIT(MAX77836_STATUS2_VIDRM_SHIFT) 151 135 ··· 197 177 #define CTRL3_JIGSET_SHIFT 0 198 178 #define CTRL3_BOOTSET_SHIFT 2 199 179 #define CTRL3_ADCDBSET_SHIFT 4 180 + #define CTRL3_WBTH_SHIFT 6 200 181 #define CTRL3_JIGSET_MASK (0x3 << CTRL3_JIGSET_SHIFT) 201 182 #define CTRL3_BOOTSET_MASK (0x3 << CTRL3_BOOTSET_SHIFT) 202 183 #define CTRL3_ADCDBSET_MASK (0x3 << CTRL3_ADCDBSET_SHIFT) 184 + #define CTRL3_WBTH_MASK (0x3 << CTRL3_WBTH_SHIFT) 203 185 204 186 /* Slave addr = 0x4A: Charger */ 205 187 enum max14577_charger_reg { ··· 232 210 #define CDETCTRL1_CHGTYPMAN_SHIFT 1 233 211 #define CDETCTRL1_DCDEN_SHIFT 2 234 212 #define CDETCTRL1_DCD2SCT_SHIFT 3 235 - #define CDETCTRL1_DCHKTM_SHIFT 4 236 - #define CDETCTRL1_DBEXIT_SHIFT 5 213 + #define MAX14577_CDETCTRL1_DCHKTM_SHIFT 4 214 + #define MAX77836_CDETCTRL1_CDLY_SHIFT 4 215 + #define MAX14577_CDETCTRL1_DBEXIT_SHIFT 5 216 + #define MAX77836_CDETCTRL1_DCDCPL_SHIFT 5 237 217 #define CDETCTRL1_DBIDLE_SHIFT 6 238 218 #define CDETCTRL1_CDPDET_SHIFT 7 239 219 #define CDETCTRL1_CHGDETEN_MASK BIT(CDETCTRL1_CHGDETEN_SHIFT) 240 220 #define CDETCTRL1_CHGTYPMAN_MASK BIT(CDETCTRL1_CHGTYPMAN_SHIFT) 241 221 #define CDETCTRL1_DCDEN_MASK BIT(CDETCTRL1_DCDEN_SHIFT) 242 222 #define CDETCTRL1_DCD2SCT_MASK BIT(CDETCTRL1_DCD2SCT_SHIFT) 243 - #define CDETCTRL1_DCHKTM_MASK BIT(CDETCTRL1_DCHKTM_SHIFT) 244 - #define CDETCTRL1_DBEXIT_MASK BIT(CDETCTRL1_DBEXIT_SHIFT) 223 + #define MAX14577_CDETCTRL1_DCHKTM_MASK BIT(MAX14577_CDETCTRL1_DCHKTM_SHIFT) 224 + #define MAX77836_CDETCTRL1_CDDLY_MASK BIT(MAX77836_CDETCTRL1_CDDLY_SHIFT) 225 + #define MAX14577_CDETCTRL1_DBEXIT_MASK BIT(MAX14577_CDETCTRL1_DBEXIT_SHIFT) 226 + #define MAX77836_CDETCTRL1_DCDCPL_MASK BIT(MAX77836_CDETCTRL1_DCDCPL_SHIFT) 245 227 #define CDETCTRL1_DBIDLE_MASK BIT(CDETCTRL1_DBIDLE_SHIFT) 246 228 #define CDETCTRL1_CDPDET_MASK BIT(CDETCTRL1_CDPDET_SHIFT) 247 229 ··· 281 255 #define CHGCTRL7_OTPCGHCVS_SHIFT 0 282 256 #define CHGCTRL7_OTPCGHCVS_MASK (0x3 << CHGCTRL7_OTPCGHCVS_SHIFT) 283 257 284 - /* MAX14577 regulator current limits (as in CHGCTRL4 register), uA */ 285 - #define MAX14577_REGULATOR_CURRENT_LIMIT_MIN 90000 286 - #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START 200000 287 - #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP 50000 288 - #define MAX14577_REGULATOR_CURRENT_LIMIT_MAX 950000 258 + /* MAX14577 charger current limits (as in CHGCTRL4 register), uA */ 259 + #define MAX14577_CHARGER_CURRENT_LIMIT_MIN 90000U 260 + #define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START 200000U 261 + #define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP 50000U 262 + #define MAX14577_CHARGER_CURRENT_LIMIT_MAX 950000U 289 263 290 - /* MAX77836 regulator current limits (as in CHGCTRL4 register), uA */ 291 - #define MAX77836_REGULATOR_CURRENT_LIMIT_MIN 45000 292 - #define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_START 100000 293 - #define MAX77836_REGULATOR_CURRENT_LIMIT_HIGH_STEP 25000 294 - #define MAX77836_REGULATOR_CURRENT_LIMIT_MAX 475000 264 + /* MAX77836 charger current limits (as in CHGCTRL4 register), uA */ 265 + #define MAX77836_CHARGER_CURRENT_LIMIT_MIN 45000U 266 + #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START 100000U 267 + #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP 25000U 268 + #define MAX77836_CHARGER_CURRENT_LIMIT_MAX 475000U 269 + 270 + /* 271 + * MAX14577 charger End-Of-Charge current limits 272 + * (as in CHGCTRL5 register), uA 273 + */ 274 + #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN 50000U 275 + #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP 10000U 276 + #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX 200000U 277 + 278 + /* 279 + * MAX14577/MAX77836 Battery Constant Voltage 280 + * (as in CHGCTRL3 register), uV 281 + */ 282 + #define MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN 4000000U 283 + #define MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP 20000U 284 + #define MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX 4350000U 285 + 286 + /* Default value for fast charge timer, in hours */ 287 + #define MAXIM_CHARGER_FAST_CHARGE_TIMER_DEFAULT 5 295 288 296 289 /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */ 297 290 #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000
+30
include/linux/mfd/max14577.h
··· 54 54 struct device_node *of_node; 55 55 }; 56 56 57 + struct max14577_charger_platform_data { 58 + u32 constant_uvolt; 59 + u32 fast_charge_uamp; 60 + u32 eoc_uamp; 61 + u32 ovp_uvolt; 62 + }; 63 + 57 64 /* 58 65 * MAX14577 MFD platform data 59 66 */ ··· 80 73 81 74 struct max14577_regulator_platform_data *regulators; 82 75 }; 76 + 77 + /* 78 + * Valid limits of current for max14577 and max77836 chargers. 79 + * They must correspond to MBCICHWRCL and MBCICHWRCH fields in CHGCTRL4 80 + * register for given chipset. 81 + */ 82 + struct maxim_charger_current { 83 + /* Minimal current, set in CHGCTRL4/MBCICHWRCL, uA */ 84 + unsigned int min; 85 + /* 86 + * Minimal current when high setting is active, 87 + * set in CHGCTRL4/MBCICHWRCH, uA 88 + */ 89 + unsigned int high_start; 90 + /* Value of one step in high setting, uA */ 91 + unsigned int high_step; 92 + /* Maximum current of high setting, uA */ 93 + unsigned int max; 94 + }; 95 + 96 + extern const struct maxim_charger_current maxim_charger_currents[]; 97 + extern int maxim_charger_calc_reg_current(const struct maxim_charger_current *limits, 98 + unsigned int min_ua, unsigned int max_ua, u8 *dst); 83 99 84 100 #endif /* __MAX14577_H__ */
+6 -2
include/linux/power_supply.h
··· 18 18 #include <linux/spinlock.h> 19 19 #include <linux/notifier.h> 20 20 21 - struct device; 22 - 23 21 /* 24 22 * All voltages, currents, charges, energies, time and temperatures in uV, 25 23 * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise ··· 100 102 POWER_SUPPLY_PROP_VOLTAGE_NOW, 101 103 POWER_SUPPLY_PROP_VOLTAGE_AVG, 102 104 POWER_SUPPLY_PROP_VOLTAGE_OCV, 105 + POWER_SUPPLY_PROP_VOLTAGE_BOOT, 103 106 POWER_SUPPLY_PROP_CURRENT_MAX, 104 107 POWER_SUPPLY_PROP_CURRENT_NOW, 105 108 POWER_SUPPLY_PROP_CURRENT_AVG, 109 + POWER_SUPPLY_PROP_CURRENT_BOOT, 106 110 POWER_SUPPLY_PROP_POWER_NOW, 107 111 POWER_SUPPLY_PROP_POWER_AVG, 108 112 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, ··· 146 146 POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ 147 147 POWER_SUPPLY_PROP_SCOPE, 148 148 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, 149 + POWER_SUPPLY_PROP_CALIBRATE, 149 150 /* Properties of type `const char *' */ 150 151 POWER_SUPPLY_PROP_MODEL_NAME, 151 152 POWER_SUPPLY_PROP_MANUFACTURER, ··· 173 172 const char *strval; 174 173 }; 175 174 175 + struct device; 176 176 struct device_node; 177 177 178 178 struct power_supply { ··· 293 291 case POWER_SUPPLY_PROP_CURRENT_MAX: 294 292 case POWER_SUPPLY_PROP_CURRENT_NOW: 295 293 case POWER_SUPPLY_PROP_CURRENT_AVG: 294 + case POWER_SUPPLY_PROP_CURRENT_BOOT: 296 295 return 1; 297 296 default: 298 297 break; ··· 318 315 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 319 316 case POWER_SUPPLY_PROP_VOLTAGE_AVG: 320 317 case POWER_SUPPLY_PROP_VOLTAGE_OCV: 318 + case POWER_SUPPLY_PROP_VOLTAGE_BOOT: 321 319 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: 322 320 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: 323 321 case POWER_SUPPLY_PROP_POWER_NOW: