Chanwoo writes: Update extcon next for v5.19 Detailed description for this pull request: 1. update extcon core driver - extcon_get_extcon_dev() has been almost used to get the extcon device on booting time. If extcon provider driver is probed at late time, the extcon consumer driver get the -EPROBE_DEFER return value. It requires the inefficient handling code of -EPROBE_DEFER. Instead, extcon_get_extcon_dev() will return -EPROBE_DEFER if the required extcon device is none. It makes the extcon consumer driver to be simplified when getting extcon device. - Register device after dev_set_drvdata because of accessing the sysfs attributes at timing of between drv_set_data and device_register. - Fix some kernel-doc comments of extcon functions. 2. update extcon provider driver - Update extcon-intel-int3496.c : Add support for controlling vbus power via regulator and support to the extcon-intel-int3496.c driver to bind to devices without an ACPi companion. And fix the minor clean-up. - Use struct_size() helper on extcon-usbc-cros-ec.c - Remove the disable irq operation in system sleep for using vbus/id gpio as the wakeup source on extcon-usb-gpio.c - Add support of SM5703 device by using existing extcon-sm5502.c and rename i2c_devic_id from sm5703 to sm5703-muic to reduce confusion between SM5703 MFD device and extcon device. - Add usb role class support and add queue work sync before driver release on extcon-ptn5150.c * tag 'extcon-next-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon: extcon: Modify extcon device to be created after driver data is set extcon: sm5502: Clarify SM5703's i2c device ID extcon: ptn5150: Add usb role class support extcon: ptn5150: Add queue work sync before driver release extcon: sm5502: Add support for SM5703 dt-bindings: extcon: bindings for SM5703 extcon: usb-gpio: Remove disable irq operation in system sleep extcon: Fix some kernel-doc comments extcon: usbc-cros-ec: Use struct_size() helper in kzalloc() extcon: int3496: Add support for controlling Vbus through a regulator extcon: int3496: Add support for binding to plain platform devices extcon: int3496: Request non-exclusive access to the ID GPIO extcon: int3496: Make the driver a bit less verbose extcon: Fix extcon_get_extcon_dev() error handling
Unified · Split
| @@ -20,11 +20,12 @@ properties: · 19 unmodified lines | ||
| 20 | 20 | enum: |
| 21 | 21 | - siliconmitus,sm5502-muic |
| 22 | 22 | - siliconmitus,sm5504-muic |
| 23 | + - siliconmitus,sm5703-muic | |
| 23 | 24 | |
| 24 | 25 | reg: |
| 25 | 26 | maxItems: 1 |
| 26 | − description: I2C slave address of the device. Usually 0x25 for SM5502, | |
| 27 | − 0x14 for SM5504. | |
| 27 | + description: I2C slave address of the device. Usually 0x25 for SM5502 | |
| 28 | + and SM5703, 0x14 for SM5504. | |
| 28 | 29 | |
| 29 | 30 | interrupts: |
| 30 | 31 | maxItems: 1 |
| @@ -131,6 +131,7 @@ config EXTCON_PALMAS · 130 unmodified lines | ||
| 131 | 131 | config EXTCON_PTN5150 |
| 132 | 132 | tristate "NXP PTN5150 CC LOGIC USB EXTCON support" |
| 133 | 133 | depends on I2C && (GPIOLIB || COMPILE_TEST) |
| 134 | + depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH | |
| 134 | 135 | select REGMAP_I2C |
| 135 | 136 | help |
| 136 | 137 | Say Y here to enable support for USB peripheral and USB host |
| @@ -156,7 +157,7 @@ config EXTCON_RT8973A · 19 unmodified lines | ||
| 156 | 157 | from abnormal high input voltage (up to 28V). |
| 157 | 158 | |
| 158 | 159 | config EXTCON_SM5502 |
| 159 | − tristate "Silicon Mitus SM5502/SM5504 EXTCON support" | |
| 160 | + tristate "Silicon Mitus SM5502/SM5504/SM5703 EXTCON support" | |
| 160 | 161 | depends on I2C |
| 161 | 162 | select IRQ_DOMAIN |
| 162 | 163 | select REGMAP_I2C |
| @@ -394,8 +394,8 @@ static int axp288_extcon_probe(struct platform_device *pdev) · 393 unmodified lines | ||
| 394 | 394 | if (adev) { |
| 395 | 395 | info->id_extcon = extcon_get_extcon_dev(acpi_dev_name(adev)); |
| 396 | 396 | put_device(&adev->dev); |
| 397 | − if (!info->id_extcon) | |
| 398 | − return -EPROBE_DEFER; | |
| 397 | + if (IS_ERR(info->id_extcon)) | |
| 398 | + return PTR_ERR(info->id_extcon); | |
| 399 | 399 | |
| 400 | 400 | dev_info(dev, "controlling USB role\n"); |
| 401 | 401 | } else { |
| @@ -17,6 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <linux/interrupt.h> |
| 18 | 18 | #include <linux/module.h> |
| 19 | 19 | #include <linux/platform_device.h> |
| 20 | +#include <linux/regulator/consumer.h> | |
| 20 | 21 | |
| 21 | 22 | #define INT3496_GPIO_USB_ID 0 |
| 22 | 23 | #define INT3496_GPIO_VBUS_EN 1 |
| @@ -30,7 +31,9 @@ struct int3496_data { · 7 unmodified lines | ||
| 30 | 31 | struct gpio_desc *gpio_usb_id; |
| 31 | 32 | struct gpio_desc *gpio_vbus_en; |
| 32 | 33 | struct gpio_desc *gpio_usb_mux; |
| 34 | + struct regulator *vbus_boost; | |
| 33 | 35 | int usb_id_irq; |
| 36 | + bool vbus_boost_enabled; | |
| 34 | 37 | }; |
| 35 | 38 | |
| 36 | 39 | static const unsigned int int3496_cable[] = { |
| @@ -53,6 +56,27 @@ static const struct acpi_gpio_mapping acpi_int3496_default_gpios[] = { · 16 unmodified lines | ||
| 53 | 56 | { }, |
| 54 | 57 | }; |
| 55 | 58 | |
| 59 | +static void int3496_set_vbus_boost(struct int3496_data *data, bool enable) | |
| 60 | +{ | |
| 61 | + int ret; | |
| 62 | + | |
| 63 | + if (IS_ERR_OR_NULL(data->vbus_boost)) | |
| 64 | + return; | |
| 65 | + | |
| 66 | + if (data->vbus_boost_enabled == enable) | |
| 67 | + return; | |
| 68 | + | |
| 69 | + if (enable) | |
| 70 | + ret = regulator_enable(data->vbus_boost); | |
| 71 | + else | |
| 72 | + ret = regulator_disable(data->vbus_boost); | |
| 73 | + | |
| 74 | + if (ret == 0) | |
| 75 | + data->vbus_boost_enabled = enable; | |
| 76 | + else | |
| 77 | + dev_err(data->dev, "Error updating Vbus boost regulator: %d\n", ret); | |
| 78 | +} | |
| 79 | + | |
| 56 | 80 | static void int3496_do_usb_id(struct work_struct *work) |
| 57 | 81 | { |
| 58 | 82 | struct int3496_data *data = |
| @@ -71,6 +95,8 @@ static void int3496_do_usb_id(struct work_struct *work) · 12 unmodified lines | ||
| 71 | 95 | |
| 72 | 96 | if (!IS_ERR(data->gpio_vbus_en)) |
| 73 | 97 | gpiod_direction_output(data->gpio_vbus_en, !id); |
| 98 | + else | |
| 99 | + int3496_set_vbus_boost(data, !id); | |
| 74 | 100 | |
| 75 | 101 | extcon_set_state_sync(data->edev, EXTCON_USB_HOST, !id); |
| 76 | 102 | } |
| @@ -91,10 +117,12 @@ static int int3496_probe(struct platform_device *pdev) · 14 unmodified lines | ||
| 91 | 117 | struct int3496_data *data; |
| 92 | 118 | int ret; |
| 93 | 119 | |
| 94 | − ret = devm_acpi_dev_add_driver_gpios(dev, acpi_int3496_default_gpios); | |
| 95 | − if (ret) { | |
| 96 | − dev_err(dev, "can't add GPIO ACPI mapping\n"); | |
| 97 | − return ret; | |
| 120 | + if (has_acpi_companion(dev)) { | |
| 121 | + ret = devm_acpi_dev_add_driver_gpios(dev, acpi_int3496_default_gpios); | |
| 122 | + if (ret) { | |
| 123 | + dev_err(dev, "can't add GPIO ACPI mapping\n"); | |
| 124 | + return ret; | |
| 125 | + } | |
| 98 | 126 | } |
| 99 | 127 | |
| 100 | 128 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
| @@ -106,7 +134,8 @@ static int int3496_probe(struct platform_device *pdev) · 5 unmodified lines | ||
| 106 | 134 | if (ret) |
| 107 | 135 | return ret; |
| 108 | 136 | |
| 109 | − data->gpio_usb_id = devm_gpiod_get(dev, "id", GPIOD_IN); | |
| 137 | + data->gpio_usb_id = | |
| 138 | + devm_gpiod_get(dev, "id", GPIOD_IN | GPIOD_FLAGS_BIT_NONEXCLUSIVE); | |
| 110 | 139 | if (IS_ERR(data->gpio_usb_id)) { |
| 111 | 140 | ret = PTR_ERR(data->gpio_usb_id); |
| 112 | 141 | dev_err(dev, "can't request USB ID GPIO: %d\n", ret); |
| @@ -120,12 +149,14 @@ static int int3496_probe(struct platform_device *pdev) · 7 unmodified lines | ||
| 120 | 149 | } |
| 121 | 150 | |
| 122 | 151 | data->gpio_vbus_en = devm_gpiod_get(dev, "vbus", GPIOD_ASIS); |
| 123 | − if (IS_ERR(data->gpio_vbus_en)) | |
| 124 | − dev_info(dev, "can't request VBUS EN GPIO\n"); | |
| 152 | + if (IS_ERR(data->gpio_vbus_en)) { | |
| 153 | + dev_dbg(dev, "can't request VBUS EN GPIO\n"); | |
| 154 | + data->vbus_boost = devm_regulator_get_optional(dev, "vbus"); | |
| 155 | + } | |
| 125 | 156 | |
| 126 | 157 | data->gpio_usb_mux = devm_gpiod_get(dev, "mux", GPIOD_ASIS); |
| 127 | 158 | if (IS_ERR(data->gpio_usb_mux)) |
| 128 | − dev_info(dev, "can't request USB MUX GPIO\n"); | |
| 159 | + dev_dbg(dev, "can't request USB MUX GPIO\n"); | |
| 129 | 160 | |
| 130 | 161 | /* register extcon device */ |
| 131 | 162 | data->edev = devm_extcon_dev_allocate(dev, int3496_cable); |
| @@ -164,12 +195,19 @@ static const struct acpi_device_id int3496_acpi_match[] = { · 32 unmodified lines | ||
| 164 | 195 | }; |
| 165 | 196 | MODULE_DEVICE_TABLE(acpi, int3496_acpi_match); |
| 166 | 197 | |
| 198 | +static const struct platform_device_id int3496_ids[] = { | |
| 199 | + { .name = "intel-int3496" }, | |
| 200 | + {}, | |
| 201 | +}; | |
| 202 | +MODULE_DEVICE_TABLE(platform, int3496_ids); | |
| 203 | + | |
| 167 | 204 | static struct platform_driver int3496_driver = { |
| 168 | 205 | .driver = { |
| 169 | 206 | .name = "intel-int3496", |
| 170 | 207 | .acpi_match_table = int3496_acpi_match, |
| 171 | 208 | }, |
| 172 | 209 | .probe = int3496_probe, |
| 210 | + .id_table = int3496_ids, | |
| 173 | 211 | }; |
| 174 | 212 | |
| 175 | 213 | module_platform_driver(int3496_driver); |
| @@ -17,6 +17,7 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <linux/slab.h> |
| 18 | 18 | #include <linux/extcon-provider.h> |
| 19 | 19 | #include <linux/gpio/consumer.h> |
| 20 | +#include <linux/usb/role.h> | |
| 20 | 21 | |
| 21 | 22 | /* PTN5150 registers */ |
| 22 | 23 | #define PTN5150_REG_DEVICE_ID 0x01 |
| @@ -52,6 +53,7 @@ struct ptn5150_info { · 29 unmodified lines | ||
| 52 | 53 | int irq; |
| 53 | 54 | struct work_struct irq_work; |
| 54 | 55 | struct mutex mutex; |
| 56 | + struct usb_role_switch *role_sw; | |
| 55 | 57 | }; |
| 56 | 58 | |
| 57 | 59 | /* List of detectable cables */ |
| @@ -70,6 +72,7 @@ static const struct regmap_config ptn5150_regmap_config = { · 12 unmodified lines | ||
| 70 | 72 | static void ptn5150_check_state(struct ptn5150_info *info) |
| 71 | 73 | { |
| 72 | 74 | unsigned int port_status, reg_data, vbus; |
| 75 | + enum usb_role usb_role = USB_ROLE_NONE; | |
| 73 | 76 | int ret; |
| 74 | 77 | |
| 75 | 78 | ret = regmap_read(info->regmap, PTN5150_REG_CC_STATUS, ®_data); |
| @@ -85,6 +88,7 @@ static void ptn5150_check_state(struct ptn5150_info *info) · 9 unmodified lines | ||
| 85 | 88 | extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false); |
| 86 | 89 | gpiod_set_value_cansleep(info->vbus_gpiod, 0); |
| 87 | 90 | extcon_set_state_sync(info->edev, EXTCON_USB, true); |
| 91 | + usb_role = USB_ROLE_DEVICE; | |
| 88 | 92 | break; |
| 89 | 93 | case PTN5150_UFP_ATTACHED: |
| 90 | 94 | extcon_set_state_sync(info->edev, EXTCON_USB, false); |
| @@ -95,10 +99,18 @@ static void ptn5150_check_state(struct ptn5150_info *info) · 4 unmodified lines | ||
| 95 | 99 | gpiod_set_value_cansleep(info->vbus_gpiod, 1); |
| 96 | 100 | |
| 97 | 101 | extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true); |
| 102 | + usb_role = USB_ROLE_HOST; | |
| 98 | 103 | break; |
| 99 | 104 | default: |
| 100 | 105 | break; |
| 101 | 106 | } |
| 107 | + | |
| 108 | + if (usb_role) { | |
| 109 | + ret = usb_role_switch_set_role(info->role_sw, usb_role); | |
| 110 | + if (ret) | |
| 111 | + dev_err(info->dev, "failed to set %s role: %d\n", | |
| 112 | + usb_role_string(usb_role), ret); | |
| 113 | + } | |
| 102 | 114 | } |
| 103 | 115 | |
| 104 | 116 | static void ptn5150_irq_work(struct work_struct *work) |
| @@ -133,6 +145,13 @@ static void ptn5150_irq_work(struct work_struct *work) · 28 unmodified lines | ||
| 133 | 145 | extcon_set_state_sync(info->edev, |
| 134 | 146 | EXTCON_USB, false); |
| 135 | 147 | gpiod_set_value_cansleep(info->vbus_gpiod, 0); |
| 148 | + | |
| 149 | + ret = usb_role_switch_set_role(info->role_sw, | |
| 150 | + USB_ROLE_NONE); | |
| 151 | + if (ret) | |
| 152 | + dev_err(info->dev, | |
| 153 | + "failed to set none role: %d\n", | |
| 154 | + ret); | |
| 136 | 155 | } |
| 137 | 156 | } |
| 138 | 157 | |
| @@ -194,6 +213,14 @@ static int ptn5150_init_dev_type(struct ptn5150_info *info) · 55 unmodified lines | ||
| 194 | 213 | return 0; |
| 195 | 214 | } |
| 196 | 215 | |
| 216 | +static void ptn5150_work_sync_and_put(void *data) | |
| 217 | +{ | |
| 218 | + struct ptn5150_info *info = data; | |
| 219 | + | |
| 220 | + cancel_work_sync(&info->irq_work); | |
| 221 | + usb_role_switch_put(info->role_sw); | |
| 222 | +} | |
| 223 | + | |
| 197 | 224 | static int ptn5150_i2c_probe(struct i2c_client *i2c) |
| 198 | 225 | { |
| 199 | 226 | struct device *dev = &i2c->dev; |
| @@ -284,6 +311,15 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) · 84 unmodified lines | ||
| 284 | 311 | if (ret) |
| 285 | 312 | return -EINVAL; |
| 286 | 313 | |
| 314 | + info->role_sw = usb_role_switch_get(info->dev); | |
| 315 | + if (IS_ERR(info->role_sw)) | |
| 316 | + return dev_err_probe(info->dev, PTR_ERR(info->role_sw), | |
| 317 | + "failed to get role switch\n"); | |
| 318 | + | |
| 319 | + ret = devm_add_action_or_reset(dev, ptn5150_work_sync_and_put, info); | |
| 320 | + if (ret) | |
| 321 | + return ret; | |
| 322 | + | |
| 287 | 323 | /* |
| 288 | 324 | * Update current extcon state if for example OTG connection was there |
| 289 | 325 | * before the probe |
| @@ -798,6 +798,7 @@ static const struct sm5502_type sm5504_data = { · 797 unmodified lines | ||
| 798 | 798 | static const struct of_device_id sm5502_dt_match[] = { |
| 799 | 799 | { .compatible = "siliconmitus,sm5502-muic", .data = &sm5502_data }, |
| 800 | 800 | { .compatible = "siliconmitus,sm5504-muic", .data = &sm5504_data }, |
| 801 | + { .compatible = "siliconmitus,sm5703-muic", .data = &sm5502_data }, | |
| 801 | 802 | { }, |
| 802 | 803 | }; |
| 803 | 804 | MODULE_DEVICE_TABLE(of, sm5502_dt_match); |
| @@ -830,6 +831,7 @@ static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops, · 26 unmodified lines | ||
| 830 | 831 | static const struct i2c_device_id sm5502_i2c_id[] = { |
| 831 | 832 | { "sm5502", (kernel_ulong_t)&sm5502_data }, |
| 832 | 833 | { "sm5504", (kernel_ulong_t)&sm5504_data }, |
| 834 | + { "sm5703-muic", (kernel_ulong_t)&sm5502_data }, | |
| 833 | 835 | { } |
| 834 | 836 | }; |
| 835 | 837 | MODULE_DEVICE_TABLE(i2c, sm5502_i2c_id); |
| @@ -226,16 +226,6 @@ static int usb_extcon_suspend(struct device *dev) · 225 unmodified lines | ||
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | − /* | |
| 230 | − * We don't want to process any IRQs after this point | |
| 231 | − * as GPIOs used behind I2C subsystem might not be | |
| 232 | − * accessible until resume completes. So disable IRQ. | |
| 233 | − */ | |
| 234 | − if (info->id_gpiod) | |
| 235 | − disable_irq(info->id_irq); | |
| 236 | − if (info->vbus_gpiod) | |
| 237 | − disable_irq(info->vbus_irq); | |
| 238 | − | |
| 239 | 229 | if (!device_may_wakeup(dev)) |
| 240 | 230 | pinctrl_pm_select_sleep_state(dev); |
| 241 | 231 | |
| @@ -267,11 +257,6 @@ static int usb_extcon_resume(struct device *dev) · 25 unmodified lines | ||
| 267 | 257 | } |
| 268 | 258 | } |
| 269 | 259 | |
| 270 | − if (info->id_gpiod) | |
| 271 | − enable_irq(info->id_irq); | |
| 272 | − if (info->vbus_gpiod) | |
| 273 | − enable_irq(info->vbus_irq); | |
| 274 | − | |
| 275 | 260 | queue_delayed_work(system_power_efficient_wq, |
| 276 | 261 | &info->wq_detcable, 0); |
| 277 | 262 | |
| @@ -68,7 +68,7 @@ static int cros_ec_pd_command(struct cros_ec_extcon_info *info, · 67 unmodified lines | ||
| 68 | 68 | struct cros_ec_command *msg; |
| 69 | 69 | int ret; |
| 70 | 70 | |
| 71 | − msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL); | |
| 71 | + msg = kzalloc(struct_size(msg, data, max(outsize, insize)), GFP_KERNEL); | |
| 72 | 72 | if (!msg) |
| 73 | 73 | return -ENOMEM; |
| 74 | 74 | |
| @@ -399,6 +399,7 @@ static ssize_t cable_state_show(struct device *dev, · 398 unmodified lines | ||
| 399 | 399 | /** |
| 400 | 400 | * extcon_sync() - Synchronize the state for an external connector. |
| 401 | 401 | * @edev: the extcon device |
| 402 | + * @id: the unique id indicating an external connector | |
| 402 | 403 | * |
| 403 | 404 | * Note that this function send a notification in order to synchronize |
| 404 | 405 | * the state and property of an external connector. |
| @@ -736,6 +737,9 @@ EXPORT_SYMBOL_GPL(extcon_set_property); · 331 unmodified lines | ||
| 736 | 737 | |
| 737 | 738 | /** |
| 738 | 739 | * extcon_set_property_sync() - Set property of an external connector with sync. |
| 740 | + * @edev: the extcon device | |
| 741 | + * @id: the unique id indicating an external connector | |
| 742 | + * @prop: the property id indicating an extcon property | |
| 739 | 743 | * @prop_val: the pointer including the new value of extcon property |
| 740 | 744 | * |
| 741 | 745 | * Note that when setting the property value of external connector, |
| @@ -851,6 +855,8 @@ EXPORT_SYMBOL_GPL(extcon_set_property_capability); · 109 unmodified lines | ||
| 851 | 855 | * @extcon_name: the extcon name provided with extcon_dev_register() |
| 852 | 856 | * |
| 853 | 857 | * Return the pointer of extcon device if success or ERR_PTR(err) if fail. |
| 858 | + * NOTE: This function returns -EPROBE_DEFER so it may only be called from | |
| 859 | + * probe() functions. | |
| 854 | 860 | */ |
| 855 | 861 | struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) |
| 856 | 862 | { |
| @@ -864,7 +870,7 @@ struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) · 7 unmodified lines | ||
| 864 | 870 | if (!strcmp(sd->name, extcon_name)) |
| 865 | 871 | goto out; |
| 866 | 872 | } |
| 867 | − sd = NULL; | |
| 873 | + sd = ERR_PTR(-EPROBE_DEFER); | |
| 868 | 874 | out: |
| 869 | 875 | mutex_unlock(&extcon_dev_list_lock); |
| 870 | 876 | return sd; |
| @@ -1218,19 +1224,14 @@ int extcon_dev_register(struct extcon_dev *edev) · 347 unmodified lines | ||
| 1218 | 1224 | edev->dev.type = &edev->extcon_dev_type; |
| 1219 | 1225 | } |
| 1220 | 1226 | |
| 1221 | − ret = device_register(&edev->dev); | |
| 1222 | − if (ret) { | |
| 1223 | − put_device(&edev->dev); | |
| 1224 | − goto err_dev; | |
| 1225 | − } | |
| 1226 | − | |
| 1227 | 1227 | spin_lock_init(&edev->lock); |
| 1228 | − edev->nh = devm_kcalloc(&edev->dev, edev->max_supported, | |
| 1229 | − sizeof(*edev->nh), GFP_KERNEL); | |
| 1230 | − if (!edev->nh) { | |
| 1231 | − ret = -ENOMEM; | |
| 1232 | − device_unregister(&edev->dev); | |
| 1233 | − goto err_dev; | |
| 1228 | + if (edev->max_supported) { | |
| 1229 | + edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh), | |
| 1230 | + GFP_KERNEL); | |
| 1231 | + if (!edev->nh) { | |
| 1232 | + ret = -ENOMEM; | |
| 1233 | + goto err_alloc_nh; | |
| 1234 | + } | |
| 1234 | 1235 | } |
| 1235 | 1236 | |
| 1236 | 1237 | for (index = 0; index < edev->max_supported; index++) |
| @@ -1241,6 +1242,12 @@ int extcon_dev_register(struct extcon_dev *edev) · 4 unmodified lines | ||
| 1241 | 1242 | dev_set_drvdata(&edev->dev, edev); |
| 1242 | 1243 | edev->state = 0; |
| 1243 | 1244 | |
| 1245 | + ret = device_register(&edev->dev); | |
| 1246 | + if (ret) { | |
| 1247 | + put_device(&edev->dev); | |
| 1248 | + goto err_dev; | |
| 1249 | + } | |
| 1250 | + | |
| 1244 | 1251 | mutex_lock(&extcon_dev_list_lock); |
| 1245 | 1252 | list_add(&edev->entry, &extcon_dev_list); |
| 1246 | 1253 | mutex_unlock(&extcon_dev_list_lock); |
| @@ -1248,6 +1255,9 @@ int extcon_dev_register(struct extcon_dev *edev) · 1 unmodified line | ||
| 1248 | 1255 | return 0; |
| 1249 | 1256 | |
| 1250 | 1257 | err_dev: |
| 1258 | + if (edev->max_supported) | |
| 1259 | + kfree(edev->nh); | |
| 1260 | +err_alloc_nh: | |
| 1251 | 1261 | if (edev->max_supported) |
| 1252 | 1262 | kfree(edev->extcon_dev_type.groups); |
| 1253 | 1263 | err_alloc_groups: |
| @@ -1308,6 +1318,7 @@ void extcon_dev_unregister(struct extcon_dev *edev) · 54 unmodified lines | ||
| 1308 | 1318 | if (edev->max_supported) { |
| 1309 | 1319 | kfree(edev->extcon_dev_type.groups); |
| 1310 | 1320 | kfree(edev->cables); |
| 1321 | + kfree(edev->nh); | |
| 1311 | 1322 | } |
| 1312 | 1323 | |
| 1313 | 1324 | put_device(&edev->dev); |
| @@ -865,17 +865,20 @@ static int axp288_charger_probe(struct platform_device *pdev) · 864 unmodified lines | ||
| 865 | 865 | info->regmap_irqc = axp20x->regmap_irqc; |
| 866 | 866 | |
| 867 | 867 | info->cable.edev = extcon_get_extcon_dev(AXP288_EXTCON_DEV_NAME); |
| 868 | − if (info->cable.edev == NULL) { | |
| 869 | − dev_dbg(dev, "%s is not ready, probe deferred\n", | |
| 870 | − AXP288_EXTCON_DEV_NAME); | |
| 871 | − return -EPROBE_DEFER; | |
| 868 | + if (IS_ERR(info->cable.edev)) { | |
| 869 | + dev_err_probe(dev, PTR_ERR(info->cable.edev), | |
| 870 | + "extcon_get_extcon_dev(%s) failed\n", | |
| 871 | + AXP288_EXTCON_DEV_NAME); | |
| 872 | + return PTR_ERR(info->cable.edev); | |
| 872 | 873 | } |
| 873 | 874 | |
| 874 | 875 | if (acpi_dev_present(USB_HOST_EXTCON_HID, NULL, -1)) { |
| 875 | 876 | info->otg.cable = extcon_get_extcon_dev(USB_HOST_EXTCON_NAME); |
| 876 | − if (info->otg.cable == NULL) { | |
| 877 | − dev_dbg(dev, "EXTCON_USB_HOST is not ready, probe deferred\n"); | |
| 878 | − return -EPROBE_DEFER; | |
| 877 | + if (IS_ERR(info->otg.cable)) { | |
| 878 | + dev_err_probe(dev, PTR_ERR(info->otg.cable), | |
| 879 | + "extcon_get_extcon_dev(%s) failed\n", | |
| 880 | + USB_HOST_EXTCON_NAME); | |
| 881 | + return PTR_ERR(info->otg.cable); | |
| 879 | 882 | } |
| 880 | 883 | dev_info(dev, "Using " USB_HOST_EXTCON_HID " extcon for usb-id\n"); |
| 881 | 884 | } |
| @@ -985,13 +985,10 @@ static int charger_extcon_init(struct charger_manager *cm, · 984 unmodified lines | ||
| 985 | 985 | cable->nb.notifier_call = charger_extcon_notifier; |
| 986 | 986 | |
| 987 | 987 | cable->extcon_dev = extcon_get_extcon_dev(cable->extcon_name); |
| 988 | − if (IS_ERR_OR_NULL(cable->extcon_dev)) { | |
| 988 | + if (IS_ERR(cable->extcon_dev)) { | |
| 989 | 989 | pr_err("Cannot find extcon_dev for %s (cable: %s)\n", |
| 990 | 990 | cable->extcon_name, cable->name); |
| 991 | − if (cable->extcon_dev == NULL) | |
| 992 | − return -EPROBE_DEFER; | |
| 993 | − else | |
| 994 | − return PTR_ERR(cable->extcon_dev); | |
| 991 | + return PTR_ERR(cable->extcon_dev); | |
| 995 | 992 | } |
| 996 | 993 | |
| 997 | 994 | for (i = 0; i < ARRAY_SIZE(extcon_mapping); i++) { |
| @@ -242,10 +242,10 @@ static int max8997_battery_probe(struct platform_device *pdev) · 241 unmodified lines | ||
| 242 | 242 | dev_info(&pdev->dev, "couldn't get charger regulator\n"); |
| 243 | 243 | } |
| 244 | 244 | charger->edev = extcon_get_extcon_dev("max8997-muic"); |
| 245 | − if (IS_ERR_OR_NULL(charger->edev)) { | |
| 246 | − if (!charger->edev) | |
| 247 | − return -EPROBE_DEFER; | |
| 248 | − dev_info(charger->dev, "couldn't get extcon device\n"); | |
| 245 | + if (IS_ERR(charger->edev)) { | |
| 246 | + dev_err_probe(charger->dev, PTR_ERR(charger->edev), | |
| 247 | + "couldn't get extcon device: max8997-muic\n"); | |
| 248 | + return PTR_ERR(charger->edev); | |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if (!IS_ERR(charger->reg) && !IS_ERR_OR_NULL(charger->edev)) { |
| @@ -455,13 +455,8 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) · 454 unmodified lines | ||
| 455 | 455 | * This device property is for kernel internal use only and |
| 456 | 456 | * is expected to be set by the glue code. |
| 457 | 457 | */ |
| 458 | − if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) { | |
| 459 | − edev = extcon_get_extcon_dev(name); | |
| 460 | − if (!edev) | |
| 461 | − return ERR_PTR(-EPROBE_DEFER); | |
| 462 | − | |
| 463 | − return edev; | |
| 464 | − } | |
| 458 | + if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) | |
| 459 | + return extcon_get_extcon_dev(name); | |
| 465 | 460 | |
| 466 | 461 | /* |
| 467 | 462 | * Try to get an extcon device from the USB PHY controller's "port" |
| @@ -95,8 +95,8 @@ static int omap_otg_probe(struct platform_device *pdev) · 94 unmodified lines | ||
| 95 | 95 | return -ENODEV; |
| 96 | 96 | |
| 97 | 97 | extcon = extcon_get_extcon_dev(config->extcon); |
| 98 | − if (!extcon) | |
| 99 | − return -EPROBE_DEFER; | |
| 98 | + if (IS_ERR(extcon)) | |
| 99 | + return PTR_ERR(extcon); | |
| 100 | 100 | |
| 101 | 101 | otg_dev = devm_kzalloc(&pdev->dev, sizeof(*otg_dev), GFP_KERNEL); |
| 102 | 102 | if (!otg_dev) |
| @@ -1708,8 +1708,8 @@ static int fusb302_probe(struct i2c_client *client, · 1707 unmodified lines | ||
| 1708 | 1708 | */ |
| 1709 | 1709 | if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) { |
| 1710 | 1710 | chip->extcon = extcon_get_extcon_dev(name); |
| 1711 | − if (!chip->extcon) | |
| 1712 | − return -EPROBE_DEFER; | |
| 1711 | + if (IS_ERR(chip->extcon)) | |
| 1712 | + return PTR_ERR(chip->extcon); | |
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | 1715 | chip->vbus = devm_regulator_get(chip->dev, "vbus"); |
| @@ -296,7 +296,7 @@ static inline void devm_extcon_unregister_notifier_all(struct device *dev, · 295 unmodified lines | ||
| 296 | 296 | |
| 297 | 297 | static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) |
| 298 | 298 | { |
| 299 | − return ERR_PTR(-ENODEV); | |
| 299 | + return NULL; | |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | static inline struct extcon_dev *extcon_find_edev_by_node(struct device_node *node) |