diff options
author | Hans de Goede <hdegoede@redhat.com> | 2018-01-22 12:42:18 -0500 |
---|---|---|
committer | Sebastian Reichel <sebastian.reichel@collabora.co.uk> | 2018-01-23 10:51:22 -0500 |
commit | 2d7e6a8376c0eaf260f54b265acadd2e185d7b82 (patch) | |
tree | b5cee38764ae38d82672d47d77d0e05494b7088e | |
parent | 6e5ab19d54e8cd7bdc779db0b807403558dbea62 (diff) |
power: supply: max17042_battery: Always fall back to default platform-data
It is possible to have CONFIG_OF enabled on x86 builds, where we have no
firmware provided max17042_platform_data. The CONFIG_OF implementation of
max17042_get_pdata would return NULL in this case, causing the probe to
fail.
Instead always fallback to the default platform-data, as used on x86 sofar,
when there is no firmware provided pdata, independent of CONFIG_OF.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
-rw-r--r-- | drivers/power/supply/max17042_battery.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 102b3f71e9a4..35dde81b1c9b 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c | |||
@@ -886,16 +886,13 @@ static void max17042_init_worker(struct work_struct *work) | |||
886 | 886 | ||
887 | #ifdef CONFIG_OF | 887 | #ifdef CONFIG_OF |
888 | static struct max17042_platform_data * | 888 | static struct max17042_platform_data * |
889 | max17042_get_pdata(struct max17042_chip *chip) | 889 | max17042_get_of_pdata(struct max17042_chip *chip) |
890 | { | 890 | { |
891 | struct device *dev = &chip->client->dev; | 891 | struct device *dev = &chip->client->dev; |
892 | struct device_node *np = dev->of_node; | 892 | struct device_node *np = dev->of_node; |
893 | u32 prop; | 893 | u32 prop; |
894 | struct max17042_platform_data *pdata; | 894 | struct max17042_platform_data *pdata; |
895 | 895 | ||
896 | if (!np) | ||
897 | return dev->platform_data; | ||
898 | |||
899 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | 896 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
900 | if (!pdata) | 897 | if (!pdata) |
901 | return NULL; | 898 | return NULL; |
@@ -920,7 +917,8 @@ max17042_get_pdata(struct max17042_chip *chip) | |||
920 | 917 | ||
921 | return pdata; | 918 | return pdata; |
922 | } | 919 | } |
923 | #else | 920 | #endif |
921 | |||
924 | static struct max17042_reg_data max17047_default_pdata_init_regs[] = { | 922 | static struct max17042_reg_data max17047_default_pdata_init_regs[] = { |
925 | /* | 923 | /* |
926 | * Some firmwares do not set FullSOCThr, Enable End-of-Charge Detection | 924 | * Some firmwares do not set FullSOCThr, Enable End-of-Charge Detection |
@@ -930,15 +928,12 @@ static struct max17042_reg_data max17047_default_pdata_init_regs[] = { | |||
930 | }; | 928 | }; |
931 | 929 | ||
932 | static struct max17042_platform_data * | 930 | static struct max17042_platform_data * |
933 | max17042_get_pdata(struct max17042_chip *chip) | 931 | max17042_get_default_pdata(struct max17042_chip *chip) |
934 | { | 932 | { |
935 | struct device *dev = &chip->client->dev; | 933 | struct device *dev = &chip->client->dev; |
936 | struct max17042_platform_data *pdata; | 934 | struct max17042_platform_data *pdata; |
937 | int ret, misc_cfg; | 935 | int ret, misc_cfg; |
938 | 936 | ||
939 | if (dev->platform_data) | ||
940 | return dev->platform_data; | ||
941 | |||
942 | /* | 937 | /* |
943 | * The MAX17047 gets used on x86 where we might not have pdata, assume | 938 | * The MAX17047 gets used on x86 where we might not have pdata, assume |
944 | * the firmware will already have initialized the fuel-gauge and provide | 939 | * the firmware will already have initialized the fuel-gauge and provide |
@@ -971,7 +966,21 @@ max17042_get_pdata(struct max17042_chip *chip) | |||
971 | 966 | ||
972 | return pdata; | 967 | return pdata; |
973 | } | 968 | } |
969 | |||
970 | static struct max17042_platform_data * | ||
971 | max17042_get_pdata(struct max17042_chip *chip) | ||
972 | { | ||
973 | struct device *dev = &chip->client->dev; | ||
974 | |||
975 | #ifdef CONFIG_OF | ||
976 | if (dev->of_node) | ||
977 | return max17042_get_of_pdata(chip); | ||
974 | #endif | 978 | #endif |
979 | if (dev->platform_data) | ||
980 | return dev->platform_data; | ||
981 | |||
982 | return max17042_get_default_pdata(chip); | ||
983 | } | ||
975 | 984 | ||
976 | static const struct regmap_config max17042_regmap_config = { | 985 | static const struct regmap_config max17042_regmap_config = { |
977 | .reg_bits = 8, | 986 | .reg_bits = 8, |