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

Merge tag 'extcon-next-for-4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon into char-misc-next

Chanwoo writes:

Update extcon for 4.14

Detailed description for this pull request:
1. Add new 'extcon-usbc-cros-ec.c' driver
- ChromeOS Embedded Controller extcon driver supports
the detection of the Display Port (EXTCON_DISP_DP)
through USB C-type and contol it.

2. Update extcon core
- Modify the description for both functions and structures
in order to improve the readability and give the more correct
guide about the role of functions because there are different
explanation even if the same arguments.

- Keep the indentation with tab instead of space

- Remove the following deprecated extcon API. The deprecated API
are exchanged on all of linux tree.
: extcon_get_cable_state_() -> extcon_get_state()
: extcon_set_cable_state_() -> extcon_set_state_sync()

3. Include the two immutable branch as following:
- ib-extcon-mfd-4.14 for the 'extcon-ubsc-cros-ec.c' driver
because the patches of 'extcon-ubsc-cros-ec.c' touch the MFD directory.
- ib-extcon-usb-phy-4.14 for removing the deprecated extcon API
because the usb/phy driver usese the deprecated extcon API.
So, this immutable branch alters the extcon API and then
remove them from extcon.

4. Fix minor issue of extcon driver
- Fix the MHL detection on extcon-max77693.c
- Convert to using %pOF instead of full_name on extcon.c
- Add 'const' kerywod for acpi_device_id on extcon-intel-int3496.c

+760 -276
+24
Documentation/devicetree/bindings/extcon/extcon-usbc-cros-ec.txt
··· 1 + ChromeOS EC USB Type-C cable and accessories detection 2 + 3 + On ChromeOS systems with USB Type C ports, the ChromeOS Embedded Controller is 4 + able to detect the state of external accessories such as display adapters 5 + or USB devices when said accessories are attached or detached. 6 + 7 + The node for this device must be under a cros-ec node like google,cros-ec-spi 8 + or google,cros-ec-i2c. 9 + 10 + Required properties: 11 + - compatible: Should be "google,extcon-usbc-cros-ec". 12 + - google,usb-port-id: Specifies the USB port ID to use. 13 + 14 + Example: 15 + cros-ec@0 { 16 + compatible = "google,cros-ec-i2c"; 17 + 18 + ... 19 + 20 + extcon { 21 + compatible = "google,extcon-usbc-cros-ec"; 22 + google,usb-port-id = <0>; 23 + }; 24 + }
+7
drivers/extcon/Kconfig
··· 150 150 Say Y here to enable GPIO based USB cable detection extcon support. 151 151 Used typically if GPIO is used for USB ID pin detection. 152 152 153 + config EXTCON_USBC_CROS_EC 154 + tristate "ChromeOS Embedded Controller EXTCON support" 155 + depends on MFD_CROS_EC 156 + help 157 + Say Y here to enable USB Type C cable detection extcon support when 158 + using Chrome OS EC based USB Type-C ports. 159 + 153 160 endif
+1
drivers/extcon/Makefile
··· 20 20 obj-$(CONFIG_EXTCON_RT8973A) += extcon-rt8973a.o 21 21 obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o 22 22 obj-$(CONFIG_EXTCON_USB_GPIO) += extcon-usb-gpio.o 23 + obj-$(CONFIG_EXTCON_USBC_CROS_EC) += extcon-usbc-cros-ec.o
+24 -26
drivers/extcon/devres.c
··· 1 1 /* 2 - * drivers/extcon/devres.c - EXTCON device's resource management 2 + * drivers/extcon/devres.c - EXTCON device's resource management 3 3 * 4 4 * Copyright (C) 2016 Samsung Electronics 5 5 * Author: Chanwoo Choi <cw00.choi@samsung.com> ··· 59 59 60 60 /** 61 61 * devm_extcon_dev_allocate - Allocate managed extcon device 62 - * @dev: device owning the extcon device being created 63 - * @supported_cable: Array of supported extcon ending with EXTCON_NONE. 64 - * If supported_cable is NULL, cable name related APIs 65 - * are disabled. 62 + * @dev: the device owning the extcon device being created 63 + * @supported_cable: the array of the supported external connectors 64 + * ending with EXTCON_NONE. 66 65 * 67 66 * This function manages automatically the memory of extcon device using device 68 67 * resource management and simplify the control of freeing the memory of extcon ··· 96 97 97 98 /** 98 99 * devm_extcon_dev_free() - Resource-managed extcon_dev_unregister() 99 - * @dev: device the extcon belongs to 100 - * @edev: the extcon device to unregister 100 + * @dev: the device owning the extcon device being created 101 + * @edev: the extcon device to be freed 101 102 * 102 103 * Free the memory that is allocated with devm_extcon_dev_allocate() 103 104 * function. ··· 111 112 112 113 /** 113 114 * devm_extcon_dev_register() - Resource-managed extcon_dev_register() 114 - * @dev: device to allocate extcon device 115 - * @edev: the new extcon device to register 115 + * @dev: the device owning the extcon device being created 116 + * @edev: the extcon device to be registered 116 117 * 117 - * Managed extcon_dev_register() function. If extcon device is attached with 118 118 * this function, that extcon device is automatically unregistered on driver 119 119 * detach. Internally this function calls extcon_dev_register() function. 120 120 * To get more information, refer that function. ··· 147 149 148 150 /** 149 151 * devm_extcon_dev_unregister() - Resource-managed extcon_dev_unregister() 150 - * @dev: device the extcon belongs to 151 - * @edev: the extcon device to unregister 152 + * @dev: the device owning the extcon device being created 153 + * @edev: the extcon device to unregistered 152 154 * 153 155 * Unregister extcon device that is registered with devm_extcon_dev_register() 154 156 * function. ··· 162 164 163 165 /** 164 166 * devm_extcon_register_notifier() - Resource-managed extcon_register_notifier() 165 - * @dev: device to allocate extcon device 166 - * @edev: the extcon device that has the external connecotr. 167 - * @id: the unique id of each external connector in extcon enumeration. 168 - * @nb: a notifier block to be registered. 167 + * @dev: the device owning the extcon device being created 168 + * @edev: the extcon device 169 + * @id: the unique id among the extcon enumeration 170 + * @nb: a notifier block to be registered 169 171 * 170 172 * This function manages automatically the notifier of extcon device using 171 173 * device resource management and simplify the control of unregistering ··· 206 208 /** 207 209 * devm_extcon_unregister_notifier() 208 210 - Resource-managed extcon_unregister_notifier() 209 - * @dev: device to allocate extcon device 210 - * @edev: the extcon device that has the external connecotr. 211 - * @id: the unique id of each external connector in extcon enumeration. 212 - * @nb: a notifier block to be registered. 211 + * @dev: the device owning the extcon device being created 212 + * @edev: the extcon device 213 + * @id: the unique id among the extcon enumeration 214 + * @nb: a notifier block to be registered 213 215 */ 214 216 void devm_extcon_unregister_notifier(struct device *dev, 215 217 struct extcon_dev *edev, unsigned int id, ··· 223 225 /** 224 226 * devm_extcon_register_notifier_all() 225 227 * - Resource-managed extcon_register_notifier_all() 226 - * @dev: device to allocate extcon device 227 - * @edev: the extcon device that has the external connecotr. 228 - * @nb: a notifier block to be registered. 228 + * @dev: the device owning the extcon device being created 229 + * @edev: the extcon device 230 + * @nb: a notifier block to be registered 229 231 * 230 232 * This function manages automatically the notifier of extcon device using 231 233 * device resource management and simplify the control of unregistering ··· 261 263 /** 262 264 * devm_extcon_unregister_notifier_all() 263 265 * - Resource-managed extcon_unregister_notifier_all() 264 - * @dev: device to allocate extcon device 265 - * @edev: the extcon device that has the external connecotr. 266 - * @nb: a notifier block to be registered. 266 + * @dev: the device owning the extcon device being created 267 + * @edev: the extcon device 268 + * @nb: a notifier block to be registered 267 269 */ 268 270 void devm_extcon_unregister_notifier_all(struct device *dev, 269 271 struct extcon_dev *edev,
+1 -1
drivers/extcon/extcon-intel-int3496.c
··· 171 171 return 0; 172 172 } 173 173 174 - static struct acpi_device_id int3496_acpi_match[] = { 174 + static const struct acpi_device_id int3496_acpi_match[] = { 175 175 { "INT3496" }, 176 176 { } 177 177 };
+2 -3
drivers/extcon/extcon-max77693.c
··· 811 811 */ 812 812 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, 813 813 attached); 814 - if (!cable_attached) 815 - extcon_set_state_sync(info->edev, 816 - EXTCON_DISP_MHL, cable_attached); 814 + extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, 815 + cable_attached); 817 816 break; 818 817 } 819 818
+417
drivers/extcon/extcon-usbc-cros-ec.c
··· 1 + /** 2 + * drivers/extcon/extcon-usbc-cros-ec - ChromeOS Embedded Controller extcon 3 + * 4 + * Copyright (C) 2017 Google, Inc 5 + * Author: Benson Leung <bleung@chromium.org> 6 + * 7 + * This software is licensed under the terms of the GNU General Public 8 + * License version 2, as published by the Free Software Foundation, and 9 + * may be copied, distributed, and modified under those terms. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + */ 16 + 17 + #include <linux/extcon.h> 18 + #include <linux/kernel.h> 19 + #include <linux/mfd/cros_ec.h> 20 + #include <linux/module.h> 21 + #include <linux/notifier.h> 22 + #include <linux/of.h> 23 + #include <linux/platform_device.h> 24 + #include <linux/slab.h> 25 + #include <linux/sched.h> 26 + 27 + struct cros_ec_extcon_info { 28 + struct device *dev; 29 + struct extcon_dev *edev; 30 + 31 + int port_id; 32 + 33 + struct cros_ec_device *ec; 34 + 35 + struct notifier_block notifier; 36 + 37 + bool dp; /* DisplayPort enabled */ 38 + bool mux; /* SuperSpeed (usb3) enabled */ 39 + unsigned int power_type; 40 + }; 41 + 42 + static const unsigned int usb_type_c_cable[] = { 43 + EXTCON_DISP_DP, 44 + EXTCON_NONE, 45 + }; 46 + 47 + /** 48 + * cros_ec_pd_command() - Send a command to the EC. 49 + * @info: pointer to struct cros_ec_extcon_info 50 + * @command: EC command 51 + * @version: EC command version 52 + * @outdata: EC command output data 53 + * @outsize: Size of outdata 54 + * @indata: EC command input data 55 + * @insize: Size of indata 56 + * 57 + * Return: 0 on success, <0 on failure. 58 + */ 59 + static int cros_ec_pd_command(struct cros_ec_extcon_info *info, 60 + unsigned int command, 61 + unsigned int version, 62 + void *outdata, 63 + unsigned int outsize, 64 + void *indata, 65 + unsigned int insize) 66 + { 67 + struct cros_ec_command *msg; 68 + int ret; 69 + 70 + msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL); 71 + if (!msg) 72 + return -ENOMEM; 73 + 74 + msg->version = version; 75 + msg->command = command; 76 + msg->outsize = outsize; 77 + msg->insize = insize; 78 + 79 + if (outsize) 80 + memcpy(msg->data, outdata, outsize); 81 + 82 + ret = cros_ec_cmd_xfer_status(info->ec, msg); 83 + if (ret >= 0 && insize) 84 + memcpy(indata, msg->data, insize); 85 + 86 + kfree(msg); 87 + return ret; 88 + } 89 + 90 + /** 91 + * cros_ec_usb_get_power_type() - Get power type info about PD device attached 92 + * to given port. 93 + * @info: pointer to struct cros_ec_extcon_info 94 + * 95 + * Return: power type on success, <0 on failure. 96 + */ 97 + static int cros_ec_usb_get_power_type(struct cros_ec_extcon_info *info) 98 + { 99 + struct ec_params_usb_pd_power_info req; 100 + struct ec_response_usb_pd_power_info resp; 101 + int ret; 102 + 103 + req.port = info->port_id; 104 + ret = cros_ec_pd_command(info, EC_CMD_USB_PD_POWER_INFO, 0, 105 + &req, sizeof(req), &resp, sizeof(resp)); 106 + if (ret < 0) 107 + return ret; 108 + 109 + return resp.type; 110 + } 111 + 112 + /** 113 + * cros_ec_usb_get_pd_mux_state() - Get PD mux state for given port. 114 + * @info: pointer to struct cros_ec_extcon_info 115 + * 116 + * Return: PD mux state on success, <0 on failure. 117 + */ 118 + static int cros_ec_usb_get_pd_mux_state(struct cros_ec_extcon_info *info) 119 + { 120 + struct ec_params_usb_pd_mux_info req; 121 + struct ec_response_usb_pd_mux_info resp; 122 + int ret; 123 + 124 + req.port = info->port_id; 125 + ret = cros_ec_pd_command(info, EC_CMD_USB_PD_MUX_INFO, 0, 126 + &req, sizeof(req), 127 + &resp, sizeof(resp)); 128 + if (ret < 0) 129 + return ret; 130 + 131 + return resp.flags; 132 + } 133 + 134 + /** 135 + * cros_ec_usb_get_role() - Get role info about possible PD device attached to a 136 + * given port. 137 + * @info: pointer to struct cros_ec_extcon_info 138 + * @polarity: pointer to cable polarity (return value) 139 + * 140 + * Return: role info on success, -ENOTCONN if no cable is connected, <0 on 141 + * failure. 142 + */ 143 + static int cros_ec_usb_get_role(struct cros_ec_extcon_info *info, 144 + bool *polarity) 145 + { 146 + struct ec_params_usb_pd_control pd_control; 147 + struct ec_response_usb_pd_control_v1 resp; 148 + int ret; 149 + 150 + pd_control.port = info->port_id; 151 + pd_control.role = USB_PD_CTRL_ROLE_NO_CHANGE; 152 + pd_control.mux = USB_PD_CTRL_MUX_NO_CHANGE; 153 + ret = cros_ec_pd_command(info, EC_CMD_USB_PD_CONTROL, 1, 154 + &pd_control, sizeof(pd_control), 155 + &resp, sizeof(resp)); 156 + if (ret < 0) 157 + return ret; 158 + 159 + if (!(resp.enabled & PD_CTRL_RESP_ENABLED_CONNECTED)) 160 + return -ENOTCONN; 161 + 162 + *polarity = resp.polarity; 163 + 164 + return resp.role; 165 + } 166 + 167 + /** 168 + * cros_ec_pd_get_num_ports() - Get number of EC charge ports. 169 + * @info: pointer to struct cros_ec_extcon_info 170 + * 171 + * Return: number of ports on success, <0 on failure. 172 + */ 173 + static int cros_ec_pd_get_num_ports(struct cros_ec_extcon_info *info) 174 + { 175 + struct ec_response_usb_pd_ports resp; 176 + int ret; 177 + 178 + ret = cros_ec_pd_command(info, EC_CMD_USB_PD_PORTS, 179 + 0, NULL, 0, &resp, sizeof(resp)); 180 + if (ret < 0) 181 + return ret; 182 + 183 + return resp.num_ports; 184 + } 185 + 186 + static int extcon_cros_ec_detect_cable(struct cros_ec_extcon_info *info, 187 + bool force) 188 + { 189 + struct device *dev = info->dev; 190 + int role, power_type; 191 + bool polarity = false; 192 + bool dp = false; 193 + bool mux = false; 194 + bool hpd = false; 195 + 196 + power_type = cros_ec_usb_get_power_type(info); 197 + if (power_type < 0) { 198 + dev_err(dev, "failed getting power type err = %d\n", 199 + power_type); 200 + return power_type; 201 + } 202 + 203 + role = cros_ec_usb_get_role(info, &polarity); 204 + if (role < 0) { 205 + if (role != -ENOTCONN) { 206 + dev_err(dev, "failed getting role err = %d\n", role); 207 + return role; 208 + } 209 + } else { 210 + int pd_mux_state; 211 + 212 + pd_mux_state = cros_ec_usb_get_pd_mux_state(info); 213 + if (pd_mux_state < 0) 214 + pd_mux_state = USB_PD_MUX_USB_ENABLED; 215 + 216 + dp = pd_mux_state & USB_PD_MUX_DP_ENABLED; 217 + mux = pd_mux_state & USB_PD_MUX_USB_ENABLED; 218 + hpd = pd_mux_state & USB_PD_MUX_HPD_IRQ; 219 + } 220 + 221 + if (force || info->dp != dp || info->mux != mux || 222 + info->power_type != power_type) { 223 + 224 + info->dp = dp; 225 + info->mux = mux; 226 + info->power_type = power_type; 227 + 228 + extcon_set_state(info->edev, EXTCON_DISP_DP, dp); 229 + 230 + extcon_set_property(info->edev, EXTCON_DISP_DP, 231 + EXTCON_PROP_USB_TYPEC_POLARITY, 232 + (union extcon_property_value)(int)polarity); 233 + extcon_set_property(info->edev, EXTCON_DISP_DP, 234 + EXTCON_PROP_USB_SS, 235 + (union extcon_property_value)(int)mux); 236 + extcon_set_property(info->edev, EXTCON_DISP_DP, 237 + EXTCON_PROP_DISP_HPD, 238 + (union extcon_property_value)(int)hpd); 239 + 240 + extcon_sync(info->edev, EXTCON_DISP_DP); 241 + 242 + } else if (hpd) { 243 + extcon_set_property(info->edev, EXTCON_DISP_DP, 244 + EXTCON_PROP_DISP_HPD, 245 + (union extcon_property_value)(int)hpd); 246 + extcon_sync(info->edev, EXTCON_DISP_DP); 247 + } 248 + 249 + return 0; 250 + } 251 + 252 + static int extcon_cros_ec_event(struct notifier_block *nb, 253 + unsigned long queued_during_suspend, 254 + void *_notify) 255 + { 256 + struct cros_ec_extcon_info *info; 257 + struct cros_ec_device *ec; 258 + u32 host_event; 259 + 260 + info = container_of(nb, struct cros_ec_extcon_info, notifier); 261 + ec = info->ec; 262 + 263 + host_event = cros_ec_get_host_event(ec); 264 + if (host_event & (EC_HOST_EVENT_MASK(EC_HOST_EVENT_PD_MCU) | 265 + EC_HOST_EVENT_MASK(EC_HOST_EVENT_USB_MUX))) { 266 + extcon_cros_ec_detect_cable(info, false); 267 + return NOTIFY_OK; 268 + } 269 + 270 + return NOTIFY_DONE; 271 + } 272 + 273 + static int extcon_cros_ec_probe(struct platform_device *pdev) 274 + { 275 + struct cros_ec_extcon_info *info; 276 + struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent); 277 + struct device *dev = &pdev->dev; 278 + struct device_node *np = dev->of_node; 279 + int numports, ret; 280 + 281 + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); 282 + if (!info) 283 + return -ENOMEM; 284 + 285 + info->dev = dev; 286 + info->ec = ec; 287 + 288 + if (np) { 289 + u32 port; 290 + 291 + ret = of_property_read_u32(np, "google,usb-port-id", &port); 292 + if (ret < 0) { 293 + dev_err(dev, "Missing google,usb-port-id property\n"); 294 + return ret; 295 + } 296 + info->port_id = port; 297 + } else { 298 + info->port_id = pdev->id; 299 + } 300 + 301 + numports = cros_ec_pd_get_num_ports(info); 302 + if (numports < 0) { 303 + dev_err(dev, "failed getting number of ports! ret = %d\n", 304 + numports); 305 + return numports; 306 + } 307 + 308 + if (info->port_id >= numports) { 309 + dev_err(dev, "This system only supports %d ports\n", numports); 310 + return -ENODEV; 311 + } 312 + 313 + info->edev = devm_extcon_dev_allocate(dev, usb_type_c_cable); 314 + if (IS_ERR(info->edev)) { 315 + dev_err(dev, "failed to allocate extcon device\n"); 316 + return -ENOMEM; 317 + } 318 + 319 + ret = devm_extcon_dev_register(dev, info->edev); 320 + if (ret < 0) { 321 + dev_err(dev, "failed to register extcon device\n"); 322 + return ret; 323 + } 324 + 325 + extcon_set_property_capability(info->edev, EXTCON_DISP_DP, 326 + EXTCON_PROP_USB_TYPEC_POLARITY); 327 + extcon_set_property_capability(info->edev, EXTCON_DISP_DP, 328 + EXTCON_PROP_USB_SS); 329 + extcon_set_property_capability(info->edev, EXTCON_DISP_DP, 330 + EXTCON_PROP_DISP_HPD); 331 + 332 + platform_set_drvdata(pdev, info); 333 + 334 + /* Get PD events from the EC */ 335 + info->notifier.notifier_call = extcon_cros_ec_event; 336 + ret = blocking_notifier_chain_register(&info->ec->event_notifier, 337 + &info->notifier); 338 + if (ret < 0) { 339 + dev_err(dev, "failed to register notifier\n"); 340 + return ret; 341 + } 342 + 343 + /* Perform initial detection */ 344 + ret = extcon_cros_ec_detect_cable(info, true); 345 + if (ret < 0) { 346 + dev_err(dev, "failed to detect initial cable state\n"); 347 + goto unregister_notifier; 348 + } 349 + 350 + return 0; 351 + 352 + unregister_notifier: 353 + blocking_notifier_chain_unregister(&info->ec->event_notifier, 354 + &info->notifier); 355 + return ret; 356 + } 357 + 358 + static int extcon_cros_ec_remove(struct platform_device *pdev) 359 + { 360 + struct cros_ec_extcon_info *info = platform_get_drvdata(pdev); 361 + 362 + blocking_notifier_chain_unregister(&info->ec->event_notifier, 363 + &info->notifier); 364 + 365 + return 0; 366 + } 367 + 368 + #ifdef CONFIG_PM_SLEEP 369 + static int extcon_cros_ec_suspend(struct device *dev) 370 + { 371 + return 0; 372 + } 373 + 374 + static int extcon_cros_ec_resume(struct device *dev) 375 + { 376 + int ret; 377 + struct cros_ec_extcon_info *info = dev_get_drvdata(dev); 378 + 379 + ret = extcon_cros_ec_detect_cable(info, true); 380 + if (ret < 0) 381 + dev_err(dev, "failed to detect cable state on resume\n"); 382 + 383 + return 0; 384 + } 385 + 386 + static const struct dev_pm_ops extcon_cros_ec_dev_pm_ops = { 387 + SET_SYSTEM_SLEEP_PM_OPS(extcon_cros_ec_suspend, extcon_cros_ec_resume) 388 + }; 389 + 390 + #define DEV_PM_OPS (&extcon_cros_ec_dev_pm_ops) 391 + #else 392 + #define DEV_PM_OPS NULL 393 + #endif /* CONFIG_PM_SLEEP */ 394 + 395 + #ifdef CONFIG_OF 396 + static const struct of_device_id extcon_cros_ec_of_match[] = { 397 + { .compatible = "google,extcon-usbc-cros-ec" }, 398 + { /* sentinel */ } 399 + }; 400 + MODULE_DEVICE_TABLE(of, extcon_cros_ec_of_match); 401 + #endif /* CONFIG_OF */ 402 + 403 + static struct platform_driver extcon_cros_ec_driver = { 404 + .driver = { 405 + .name = "extcon-usbc-cros-ec", 406 + .of_match_table = of_match_ptr(extcon_cros_ec_of_match), 407 + .pm = DEV_PM_OPS, 408 + }, 409 + .remove = extcon_cros_ec_remove, 410 + .probe = extcon_cros_ec_probe, 411 + }; 412 + 413 + module_platform_driver(extcon_cros_ec_driver); 414 + 415 + MODULE_DESCRIPTION("ChromeOS Embedded Controller extcon driver"); 416 + MODULE_AUTHOR("Benson Leung <bleung@chromium.org>"); 417 + MODULE_LICENSE("GPL");
+136 -143
drivers/extcon/extcon.c
··· 1 1 /* 2 - * drivers/extcon/extcon.c - External Connector (extcon) framework. 3 - * 4 - * External connector (extcon) class driver 2 + * drivers/extcon/extcon.c - External Connector (extcon) framework. 5 3 * 6 4 * Copyright (C) 2015 Samsung Electronics 7 5 * Author: Chanwoo Choi <cw00.choi@samsung.com> ··· 35 37 #include "extcon.h" 36 38 37 39 #define SUPPORTED_CABLE_MAX 32 38 - #define CABLE_NAME_MAX 30 39 40 40 41 struct __extcon_info { 41 42 unsigned int type; ··· 197 200 }; 198 201 199 202 /** 200 - * struct extcon_cable - An internal data for each cable of extcon device. 201 - * @edev: The extcon device 202 - * @cable_index: Index of this cable in the edev 203 - * @attr_g: Attribute group for the cable 203 + * struct extcon_cable - An internal data for an external connector. 204 + * @edev: the extcon device 205 + * @cable_index: the index of this cable in the edev 206 + * @attr_g: the attribute group for the cable 204 207 * @attr_name: "name" sysfs entry 205 208 * @attr_state: "state" sysfs entry 206 - * @attrs: Array pointing to attr_name and attr_state for attr_g 209 + * @attrs: the array pointing to attr_name and attr_state for attr_g 207 210 */ 208 211 struct extcon_cable { 209 212 struct extcon_dev *edev; ··· 231 234 static LIST_HEAD(extcon_dev_list); 232 235 static DEFINE_MUTEX(extcon_dev_list_lock); 233 236 234 - /** 235 - * check_mutually_exclusive - Check if new_state violates mutually_exclusive 236 - * condition. 237 - * @edev: the extcon device 238 - * @new_state: new cable attach status for @edev 239 - * 240 - * Returns 0 if nothing violates. Returns the index + 1 for the first 241 - * violated condition. 242 - */ 243 237 static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state) 244 238 { 245 239 int i = 0; ··· 405 417 } 406 418 407 419 /** 408 - * extcon_sync() - Synchronize the states for both the attached/detached 409 - * @edev: the extcon device that has the cable. 420 + * extcon_sync() - Synchronize the state for an external connector. 421 + * @edev: the extcon device 410 422 * 411 - * This function send a notification to synchronize the all states of a 412 - * specific external connector 423 + * Note that this function send a notification in order to synchronize 424 + * the state and property of an external connector. 425 + * 426 + * Returns 0 if success or error number if fail. 413 427 */ 414 428 int extcon_sync(struct extcon_dev *edev, unsigned int id) 415 429 { ··· 487 497 EXPORT_SYMBOL_GPL(extcon_sync); 488 498 489 499 /** 490 - * extcon_get_state() - Get the state of a external connector. 491 - * @edev: the extcon device that has the cable. 492 - * @id: the unique id of each external connector in extcon enumeration. 500 + * extcon_get_state() - Get the state of an external connector. 501 + * @edev: the extcon device 502 + * @id: the unique id indicating an external connector 503 + * 504 + * Returns 0 if success or error number if fail. 493 505 */ 494 506 int extcon_get_state(struct extcon_dev *edev, const unsigned int id) 495 507 { ··· 514 522 EXPORT_SYMBOL_GPL(extcon_get_state); 515 523 516 524 /** 517 - * extcon_set_state() - Set the state of a external connector. 518 - * without a notification. 519 - * @edev: the extcon device that has the cable. 520 - * @id: the unique id of each external connector 521 - * in extcon enumeration. 522 - * @state: the new cable status. The default semantics is 523 - * true: attached / false: detached. 525 + * extcon_set_state() - Set the state of an external connector. 526 + * @edev: the extcon device 527 + * @id: the unique id indicating an external connector 528 + * @state: the new state of an external connector. 529 + * the default semantics is true: attached / false: detached. 524 530 * 525 - * This function only set the state of a external connector without 526 - * a notification. To synchronize the data of a external connector, 527 - * use extcon_set_state_sync() and extcon_sync(). 531 + * Note that this function set the state of an external connector without 532 + * a notification. To synchronize the state of an external connector, 533 + * have to use extcon_set_state_sync() and extcon_sync(). 534 + * 535 + * Returns 0 if success or error number if fail. 528 536 */ 529 - int extcon_set_state(struct extcon_dev *edev, unsigned int id, 530 - bool cable_state) 537 + int extcon_set_state(struct extcon_dev *edev, unsigned int id, bool state) 531 538 { 532 539 unsigned long flags; 533 540 int index, ret = 0; ··· 541 550 spin_lock_irqsave(&edev->lock, flags); 542 551 543 552 /* Check whether the external connector's state is changed. */ 544 - if (!is_extcon_changed(edev, index, cable_state)) 553 + if (!is_extcon_changed(edev, index, state)) 545 554 goto out; 546 555 547 556 if (check_mutually_exclusive(edev, 548 - (edev->state & ~BIT(index)) | (cable_state & BIT(index)))) { 557 + (edev->state & ~BIT(index)) | (state & BIT(index)))) { 549 558 ret = -EPERM; 550 559 goto out; 551 560 } ··· 554 563 * Initialize the value of extcon property before setting 555 564 * the detached state for an external connector. 556 565 */ 557 - if (!cable_state) 566 + if (!state) 558 567 init_property(edev, id, index); 559 568 560 - /* Update the state for a external connector. */ 561 - if (cable_state) 569 + /* Update the state for an external connector. */ 570 + if (state) 562 571 edev->state |= BIT(index); 563 572 else 564 573 edev->state &= ~(BIT(index)); ··· 570 579 EXPORT_SYMBOL_GPL(extcon_set_state); 571 580 572 581 /** 573 - * extcon_set_state_sync() - Set the state of a external connector 574 - * with a notification. 575 - * @edev: the extcon device that has the cable. 576 - * @id: the unique id of each external connector 577 - * in extcon enumeration. 578 - * @state: the new cable status. The default semantics is 579 - * true: attached / false: detached. 582 + * extcon_set_state_sync() - Set the state of an external connector with sync. 583 + * @edev: the extcon device 584 + * @id: the unique id indicating an external connector 585 + * @state: the new state of external connector. 586 + * the default semantics is true: attached / false: detached. 580 587 * 581 - * This function set the state of external connector and synchronize the data 582 - * by usning a notification. 588 + * Note that this function set the state of external connector 589 + * and synchronize the state by sending a notification. 590 + * 591 + * Returns 0 if success or error number if fail. 583 592 */ 584 - int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, 585 - bool cable_state) 593 + int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, bool state) 586 594 { 587 595 int ret, index; 588 596 unsigned long flags; ··· 592 602 593 603 /* Check whether the external connector's state is changed. */ 594 604 spin_lock_irqsave(&edev->lock, flags); 595 - ret = is_extcon_changed(edev, index, cable_state); 605 + ret = is_extcon_changed(edev, index, state); 596 606 spin_unlock_irqrestore(&edev->lock, flags); 597 607 if (!ret) 598 608 return 0; 599 609 600 - ret = extcon_set_state(edev, id, cable_state); 610 + ret = extcon_set_state(edev, id, state); 601 611 if (ret < 0) 602 612 return ret; 603 613 ··· 606 616 EXPORT_SYMBOL_GPL(extcon_set_state_sync); 607 617 608 618 /** 609 - * extcon_get_property() - Get the property value of a specific cable. 610 - * @edev: the extcon device that has the cable. 611 - * @id: the unique id of each external connector 612 - * in extcon enumeration. 613 - * @prop: the property id among enum extcon_property. 614 - * @prop_val: the pointer which store the value of property. 619 + * extcon_get_property() - Get the property value of an external connector. 620 + * @edev: the extcon device 621 + * @id: the unique id indicating an external connector 622 + * @prop: the property id indicating an extcon property 623 + * @prop_val: the pointer which store the value of extcon property 615 624 * 616 - * When getting the property value of external connector, the external connector 617 - * should be attached. If detached state, function just return 0 without 618 - * property value. Also, the each property should be included in the list of 619 - * supported properties according to the type of external connectors. 625 + * Note that when getting the property value of external connector, 626 + * the external connector should be attached. If detached state, function 627 + * return 0 without property value. Also, the each property should be 628 + * included in the list of supported properties according to extcon type. 620 629 * 621 - * Returns 0 if success or error number if fail 630 + * Returns 0 if success or error number if fail. 622 631 */ 623 632 int extcon_get_property(struct extcon_dev *edev, unsigned int id, 624 633 unsigned int prop, ··· 687 698 EXPORT_SYMBOL_GPL(extcon_get_property); 688 699 689 700 /** 690 - * extcon_set_property() - Set the property value of a specific cable. 691 - * @edev: the extcon device that has the cable. 692 - * @id: the unique id of each external connector 693 - * in extcon enumeration. 694 - * @prop: the property id among enum extcon_property. 695 - * @prop_val: the pointer including the new value of property. 701 + * extcon_set_property() - Set the property value of an external connector. 702 + * @edev: the extcon device 703 + * @id: the unique id indicating an external connector 704 + * @prop: the property id indicating an extcon property 705 + * @prop_val: the pointer including the new value of extcon property 696 706 * 697 - * The each property should be included in the list of supported properties 698 - * according to the type of external connectors. 707 + * Note that each property should be included in the list of supported 708 + * properties according to the extcon type. 699 709 * 700 - * Returns 0 if success or error number if fail 710 + * Returns 0 if success or error number if fail. 701 711 */ 702 712 int extcon_set_property(struct extcon_dev *edev, unsigned int id, 703 713 unsigned int prop, ··· 754 766 EXPORT_SYMBOL_GPL(extcon_set_property); 755 767 756 768 /** 757 - * extcon_set_property_sync() - Set the property value of a specific cable 758 - with a notification. 759 - * @prop_val: the pointer including the new value of property. 769 + * extcon_set_property_sync() - Set property of an external connector with sync. 770 + * @prop_val: the pointer including the new value of extcon property 760 771 * 761 - * When setting the property value of external connector, the external connector 762 - * should be attached. The each property should be included in the list of 763 - * supported properties according to the type of external connectors. 772 + * Note that when setting the property value of external connector, 773 + * the external connector should be attached. The each property should 774 + * be included in the list of supported properties according to extcon type. 764 775 * 765 - * Returns 0 if success or error number if fail 776 + * Returns 0 if success or error number if fail. 766 777 */ 767 778 int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id, 768 779 unsigned int prop, ··· 778 791 EXPORT_SYMBOL_GPL(extcon_set_property_sync); 779 792 780 793 /** 781 - * extcon_get_property_capability() - Get the capability of property 782 - * of an external connector. 783 - * @edev: the extcon device that has the cable. 784 - * @id: the unique id of each external connector 785 - * in extcon enumeration. 786 - * @prop: the property id among enum extcon_property. 794 + * extcon_get_property_capability() - Get the capability of the property 795 + * for an external connector. 796 + * @edev: the extcon device 797 + * @id: the unique id indicating an external connector 798 + * @prop: the property id indicating an extcon property 787 799 * 788 800 * Returns 1 if the property is available or 0 if not available. 789 801 */ ··· 808 822 EXPORT_SYMBOL_GPL(extcon_get_property_capability); 809 823 810 824 /** 811 - * extcon_set_property_capability() - Set the capability of a property 812 - * of an external connector. 813 - * @edev: the extcon device that has the cable. 814 - * @id: the unique id of each external connector 815 - * in extcon enumeration. 816 - * @prop: the property id among enum extcon_property. 825 + * extcon_set_property_capability() - Set the capability of the property 826 + * for an external connector. 827 + * @edev: the extcon device 828 + * @id: the unique id indicating an external connector 829 + * @prop: the property id indicating an extcon property 817 830 * 818 - * This function set the capability of a property for an external connector 819 - * to mark the bit in capability bitmap which mean the available state of 820 - * a property. 831 + * Note that this function set the capability of the property 832 + * for an external connector in order to mark the bit in capability 833 + * bitmap which mean the available state of the property. 821 834 * 822 - * Returns 0 if success or error number if fail 835 + * Returns 0 if success or error number if fail. 823 836 */ 824 837 int extcon_set_property_capability(struct extcon_dev *edev, unsigned int id, 825 838 unsigned int prop) ··· 866 881 EXPORT_SYMBOL_GPL(extcon_set_property_capability); 867 882 868 883 /** 869 - * extcon_get_extcon_dev() - Get the extcon device instance from the name 870 - * @extcon_name: The extcon name provided with extcon_dev_register() 884 + * extcon_get_extcon_dev() - Get the extcon device instance from the name. 885 + * @extcon_name: the extcon name provided with extcon_dev_register() 886 + * 887 + * Return the pointer of extcon device if success or ERR_PTR(err) if fail. 871 888 */ 872 889 struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) 873 890 { ··· 891 904 EXPORT_SYMBOL_GPL(extcon_get_extcon_dev); 892 905 893 906 /** 894 - * extcon_register_notifier() - Register a notifiee to get notified by 895 - * any attach status changes from the extcon. 896 - * @edev: the extcon device that has the external connecotr. 897 - * @id: the unique id of each external connector in extcon enumeration. 898 - * @nb: a notifier block to be registered. 907 + * extcon_register_notifier() - Register a notifier block to get notified by 908 + * any state changes from the extcon. 909 + * @edev: the extcon device 910 + * @id: the unique id indicating an external connector 911 + * @nb: a notifier block to be registered 899 912 * 900 913 * Note that the second parameter given to the callback of nb (val) is 901 - * "old_state", not the current state. The current state can be retrieved 902 - * by looking at the third pameter (edev pointer)'s state value. 914 + * the current state of an external connector and the third pameter 915 + * is the pointer of extcon device. 916 + * 917 + * Returns 0 if success or error number if fail. 903 918 */ 904 919 int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, 905 920 struct notifier_block *nb) ··· 925 936 EXPORT_SYMBOL_GPL(extcon_register_notifier); 926 937 927 938 /** 928 - * extcon_unregister_notifier() - Unregister a notifiee from the extcon device. 929 - * @edev: the extcon device that has the external connecotr. 930 - * @id: the unique id of each external connector in extcon enumeration. 931 - * @nb: a notifier block to be registered. 939 + * extcon_unregister_notifier() - Unregister a notifier block from the extcon. 940 + * @edev: the extcon device 941 + * @id: the unique id indicating an external connector 942 + * @nb: a notifier block to be registered 943 + * 944 + * Returns 0 if success or error number if fail. 932 945 */ 933 946 int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, 934 947 struct notifier_block *nb) ··· 954 963 EXPORT_SYMBOL_GPL(extcon_unregister_notifier); 955 964 956 965 /** 957 - * extcon_register_notifier_all() - Register a notifier block for all connectors 958 - * @edev: the extcon device that has the external connector. 959 - * @nb: a notifier block to be registered. 966 + * extcon_register_notifier_all() - Register a notifier block for all connectors. 967 + * @edev: the extcon device 968 + * @nb: a notifier block to be registered 960 969 * 961 - * This function registers a notifier block in order to receive the state 962 - * change of all supported external connectors from extcon device. 970 + * Note that this function registers a notifier block in order to receive 971 + * the state change of all supported external connectors from extcon device. 963 972 * And the second parameter given to the callback of nb (val) is 964 - * the current state and third parameter is the edev pointer. 973 + * the current state and the third pameter is the pointer of extcon device. 965 974 * 966 - * Returns 0 if success or error number if fail 975 + * Returns 0 if success or error number if fail. 967 976 */ 968 977 int extcon_register_notifier_all(struct extcon_dev *edev, 969 978 struct notifier_block *nb) ··· 984 993 985 994 /** 986 995 * extcon_unregister_notifier_all() - Unregister a notifier block from extcon. 987 - * @edev: the extcon device that has the external connecotr. 988 - * @nb: a notifier block to be registered. 996 + * @edev: the extcon device 997 + * @nb: a notifier block to be registered 989 998 * 990 - * Returns 0 if success or error number if fail 999 + * Returns 0 if success or error number if fail. 991 1000 */ 992 1001 int extcon_unregister_notifier_all(struct extcon_dev *edev, 993 1002 struct notifier_block *nb) ··· 1036 1045 1037 1046 /* 1038 1047 * extcon_dev_allocate() - Allocate the memory of extcon device. 1039 - * @supported_cable: Array of supported extcon ending with EXTCON_NONE. 1040 - * If supported_cable is NULL, cable name related APIs 1041 - * are disabled. 1048 + * @supported_cable: the array of the supported external connectors 1049 + * ending with EXTCON_NONE. 1042 1050 * 1043 - * This function allocates the memory for extcon device without allocating 1044 - * memory in each extcon provider driver and initialize default setting for 1045 - * extcon device. 1051 + * Note that this function allocates the memory for extcon device 1052 + * and initialize default setting for the extcon device. 1046 1053 * 1047 - * Return the pointer of extcon device if success or ERR_PTR(err) if fail 1054 + * Returns the pointer memory of allocated extcon_dev if success 1055 + * or ERR_PTR(err) if fail. 1048 1056 */ 1049 1057 struct extcon_dev *extcon_dev_allocate(const unsigned int *supported_cable) 1050 1058 { ··· 1064 1074 1065 1075 /* 1066 1076 * extcon_dev_free() - Free the memory of extcon device. 1067 - * @edev: the extcon device to free 1077 + * @edev: the extcon device 1068 1078 */ 1069 1079 void extcon_dev_free(struct extcon_dev *edev) 1070 1080 { ··· 1073 1083 EXPORT_SYMBOL_GPL(extcon_dev_free); 1074 1084 1075 1085 /** 1076 - * extcon_dev_register() - Register a new extcon device 1077 - * @edev : the new extcon device (should be allocated before calling) 1086 + * extcon_dev_register() - Register an new extcon device 1087 + * @edev: the extcon device to be registered 1078 1088 * 1079 1089 * Among the members of edev struct, please set the "user initializing data" 1080 - * in any case and set the "optional callbacks" if required. However, please 1081 1090 * do not set the values of "internal data", which are initialized by 1082 1091 * this function. 1092 + * 1093 + * Note that before calling this funciton, have to allocate the memory 1094 + * of an extcon device by using the extcon_dev_allocate(). And the extcon 1095 + * dev should include the supported_cable information. 1096 + * 1097 + * Returns 0 if success or error number if fail. 1083 1098 */ 1084 1099 int extcon_dev_register(struct extcon_dev *edev) 1085 1100 { ··· 1291 1296 1292 1297 /** 1293 1298 * extcon_dev_unregister() - Unregister the extcon device. 1294 - * @edev: the extcon device instance to be unregistered. 1299 + * @edev: the extcon device to be unregistered. 1295 1300 * 1296 1301 * Note that this does not call kfree(edev) because edev was not allocated 1297 1302 * by this class. ··· 1337 1342 1338 1343 #ifdef CONFIG_OF 1339 1344 /* 1340 - * extcon_get_edev_by_phandle - Get the extcon device from devicetree 1341 - * @dev - instance to the given device 1342 - * @index - index into list of extcon_dev 1345 + * extcon_get_edev_by_phandle - Get the extcon device from devicetree. 1346 + * @dev : the instance to the given device 1347 + * @index : the index into list of extcon_dev 1343 1348 * 1344 - * return the instance of extcon device 1349 + * Return the pointer of extcon device if success or ERR_PTR(err) if fail. 1345 1350 */ 1346 1351 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) 1347 1352 { ··· 1358 1363 1359 1364 node = of_parse_phandle(dev->of_node, "extcon", index); 1360 1365 if (!node) { 1361 - dev_dbg(dev, "failed to get phandle in %s node\n", 1362 - dev->of_node->full_name); 1366 + dev_dbg(dev, "failed to get phandle in %pOF node\n", 1367 + dev->of_node); 1363 1368 return ERR_PTR(-ENODEV); 1364 1369 } 1365 1370 ··· 1406 1411 module_exit(extcon_class_exit); 1407 1412 1408 1413 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>"); 1409 - MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>"); 1410 - MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); 1411 1414 MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); 1412 - MODULE_DESCRIPTION("External connector (extcon) class driver"); 1413 - MODULE_LICENSE("GPL"); 1415 + MODULE_DESCRIPTION("External Connector (extcon) framework"); 1416 + MODULE_LICENSE("GPL v2");
+4 -4
drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
··· 253 253 vbus = gpiod_get_value_cansleep(driver->vbus_gpiod); 254 254 255 255 if (!id && vbus) { /* Host connected */ 256 - extcon_set_cable_state_(driver->edev, EXTCON_USB_HOST, true); 256 + extcon_set_state_sync(driver->edev, EXTCON_USB_HOST, true); 257 257 pr_debug("Host cable connected\n"); 258 258 driver->data->new_state = EVT_HOST; 259 259 connect_change(driver); 260 260 } else if (id && !vbus) { /* Disconnected */ 261 - extcon_set_cable_state_(driver->edev, EXTCON_USB_HOST, false); 262 - extcon_set_cable_state_(driver->edev, EXTCON_USB, false); 261 + extcon_set_state_sync(driver->edev, EXTCON_USB_HOST, false); 262 + extcon_set_state_sync(driver->edev, EXTCON_USB, false); 263 263 pr_debug("Cable disconnected\n"); 264 264 } else if (id && vbus) { /* Device connected */ 265 - extcon_set_cable_state_(driver->edev, EXTCON_USB, true); 265 + extcon_set_state_sync(driver->edev, EXTCON_USB, true); 266 266 pr_debug("Device cable connected\n"); 267 267 driver->data->new_state = EVT_DEVICE; 268 268 connect_change(driver);
+3 -11
drivers/phy/qualcomm/phy-qcom-usb-hs.c
··· 155 155 } 156 156 157 157 if (uphy->vbus_edev) { 158 - state = extcon_get_cable_state_(uphy->vbus_edev, EXTCON_USB); 158 + state = extcon_get_state(uphy->vbus_edev, EXTCON_USB); 159 159 /* setup initial state */ 160 160 qcom_usb_hs_phy_vbus_notifier(&uphy->vbus_notify, state, 161 161 uphy->vbus_edev); 162 - ret = extcon_register_notifier(uphy->vbus_edev, EXTCON_USB, 163 - &uphy->vbus_notify); 162 + ret = devm_extcon_register_notifier(&ulpi->dev, uphy->vbus_edev, 163 + EXTCON_USB, &uphy->vbus_notify); 164 164 if (ret) 165 165 goto err_ulpi; 166 166 } ··· 179 179 180 180 static int qcom_usb_hs_phy_power_off(struct phy *phy) 181 181 { 182 - int ret; 183 182 struct qcom_usb_hs_phy *uphy = phy_get_drvdata(phy); 184 - 185 - if (uphy->vbus_edev) { 186 - ret = extcon_unregister_notifier(uphy->vbus_edev, EXTCON_USB, 187 - &uphy->vbus_notify); 188 - if (ret) 189 - return ret; 190 - } 191 183 192 184 regulator_disable(uphy->v3p3); 193 185 regulator_disable(uphy->v1p8);
+5 -5
drivers/phy/rockchip/phy-rockchip-inno-usb2.c
··· 545 545 rockchip_usb2phy_power_off(rport->phy); 546 546 /* fall through */ 547 547 case OTG_STATE_B_IDLE: 548 - if (extcon_get_cable_state_(rphy->edev, EXTCON_USB_HOST) > 0) { 548 + if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) > 0) { 549 549 dev_dbg(&rport->phy->dev, "usb otg host connect\n"); 550 550 rport->state = OTG_STATE_A_HOST; 551 551 rockchip_usb2phy_power_on(rport->phy); ··· 598 598 rport->vbus_attached = vbus_attach; 599 599 600 600 if (notify_charger && rphy->edev) { 601 - extcon_set_cable_state_(rphy->edev, 601 + extcon_set_state_sync(rphy->edev, 602 602 cable, vbus_attach); 603 603 if (cable == EXTCON_CHG_USB_SDP) 604 604 extcon_set_state_sync(rphy->edev, ··· 619 619 sch_work = true; 620 620 break; 621 621 case OTG_STATE_A_HOST: 622 - if (extcon_get_cable_state_(rphy->edev, EXTCON_USB_HOST) == 0) { 622 + if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) == 0) { 623 623 dev_dbg(&rport->phy->dev, "usb otg host disconnect\n"); 624 624 rport->state = OTG_STATE_B_IDLE; 625 625 rockchip_usb2phy_power_off(rport->phy); ··· 1006 1006 if (!IS_ERR(rphy->edev)) { 1007 1007 rport->event_nb.notifier_call = rockchip_otg_event; 1008 1008 1009 - ret = extcon_register_notifier(rphy->edev, EXTCON_USB_HOST, 1010 - &rport->event_nb); 1009 + ret = devm_extcon_register_notifier(rphy->dev, rphy->edev, 1010 + EXTCON_USB_HOST, &rport->event_nb); 1011 1011 if (ret) 1012 1012 dev_err(rphy->dev, "register USB HOST notifier failed\n"); 1013 1013 }
+3 -3
drivers/usb/gadget/udc/snps_udc_plat.c
··· 184 184 goto exit_phy; 185 185 } 186 186 187 - ret = extcon_get_cable_state_(udc->edev, EXTCON_USB); 187 + ret = extcon_get_state(udc->edev, EXTCON_USB); 188 188 if (ret < 0) { 189 189 dev_err(dev, "Can't get cable state\n"); 190 190 goto exit_extcon; ··· 273 273 udc = dev_get_drvdata(dev); 274 274 stop_udc(udc); 275 275 276 - if (extcon_get_cable_state_(udc->edev, EXTCON_USB) > 0) { 276 + if (extcon_get_state(udc->edev, EXTCON_USB) > 0) { 277 277 dev_dbg(udc->dev, "device -> idle\n"); 278 278 stop_udc(udc); 279 279 } ··· 303 303 return ret; 304 304 } 305 305 306 - if (extcon_get_cable_state_(udc->edev, EXTCON_USB) > 0) { 306 + if (extcon_get_state(udc->edev, EXTCON_USB) > 0) { 307 307 dev_dbg(udc->dev, "idle -> device\n"); 308 308 start_udc(udc); 309 309 }
+58 -80
include/linux/extcon.h
··· 1 1 /* 2 - * External connector (extcon) class driver 2 + * External Connector (extcon) framework 3 3 * 4 4 * Copyright (C) 2015 Samsung Electronics 5 5 * Author: Chanwoo Choi <cw00.choi@samsung.com> ··· 20 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 22 * GNU General Public License for more details. 23 - * 24 - */ 23 + */ 25 24 26 25 #ifndef __LINUX_EXTCON_H__ 27 26 #define __LINUX_EXTCON_H__ ··· 92 93 #define EXTCON_NUM 63 93 94 94 95 /* 95 - * Define the property of supported external connectors. 96 + * Define the properties of supported external connectors. 96 97 * 97 98 * When adding the new extcon property, they *must* have 98 99 * the type/value/default information. Also, you *have to* ··· 175 176 176 177 #if IS_ENABLED(CONFIG_EXTCON) 177 178 178 - /* 179 - * Following APIs are for notifiers or configurations. 180 - * Notifiers are the external port and connection devices. 181 - */ 179 + /* Following APIs register/unregister the extcon device. */ 182 180 extern int extcon_dev_register(struct extcon_dev *edev); 183 181 extern void extcon_dev_unregister(struct extcon_dev *edev); 184 182 extern int devm_extcon_dev_register(struct device *dev, 185 - struct extcon_dev *edev); 183 + struct extcon_dev *edev); 186 184 extern void devm_extcon_dev_unregister(struct device *dev, 187 - struct extcon_dev *edev); 188 - extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name); 185 + struct extcon_dev *edev); 189 186 190 - /* 191 - * Following APIs control the memory of extcon device. 192 - */ 187 + /* Following APIs allocate/free the memory of the extcon device. */ 193 188 extern struct extcon_dev *extcon_dev_allocate(const unsigned int *cable); 194 189 extern void extcon_dev_free(struct extcon_dev *edev); 195 190 extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, 196 - const unsigned int *cable); 191 + const unsigned int *cable); 197 192 extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev); 198 193 199 - /* 200 - * get/set_state access each bit of the 32b encoded state value. 201 - * They are used to access the status of each cable based on the cable id. 202 - */ 203 - extern int extcon_get_state(struct extcon_dev *edev, unsigned int id); 204 - extern int extcon_set_state(struct extcon_dev *edev, unsigned int id, 205 - bool cable_state); 206 - extern int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, 207 - bool cable_state); 208 - /* 209 - * Synchronize the state and property data for a specific external connector. 210 - */ 194 + /* Synchronize the state and property value for each external connector. */ 211 195 extern int extcon_sync(struct extcon_dev *edev, unsigned int id); 212 196 213 197 /* 214 - * get/set_property access the property value of each external connector. 215 - * They are used to access the property of each cable based on the property id. 198 + * Following APIs get/set the connected state of each external connector. 199 + * The 'id' argument indicates the defined external connector. 200 + */ 201 + extern int extcon_get_state(struct extcon_dev *edev, unsigned int id); 202 + extern int extcon_set_state(struct extcon_dev *edev, unsigned int id, 203 + bool state); 204 + extern int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, 205 + bool state); 206 + 207 + /* 208 + * Following APIs get/set the property of each external connector. 209 + * The 'id' argument indicates the defined external connector 210 + * and the 'prop' indicates the extcon property. 211 + * 212 + * And extcon_get/set_property_capability() set the capability of the property 213 + * for each external connector. They are used to set the capability of the 214 + * property of each external connector based on the id and property. 216 215 */ 217 216 extern int extcon_get_property(struct extcon_dev *edev, unsigned int id, 218 217 unsigned int prop, ··· 221 224 extern int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id, 222 225 unsigned int prop, 223 226 union extcon_property_value prop_val); 224 - 225 - /* 226 - * get/set_property_capability set the capability of the property for each 227 - * external connector. They are used to set the capability of the property 228 - * of each external connector based on the id and property. 229 - */ 230 227 extern int extcon_get_property_capability(struct extcon_dev *edev, 231 228 unsigned int id, unsigned int prop); 232 229 extern int extcon_set_property_capability(struct extcon_dev *edev, 233 230 unsigned int id, unsigned int prop); 234 231 235 232 /* 236 - * Following APIs are to monitor the status change of the external connectors. 233 + * Following APIs register the notifier block in order to detect 234 + * the change of both state and property value for each external connector. 235 + * 237 236 * extcon_register_notifier(*edev, id, *nb) : Register a notifier block 238 237 * for specific external connector of the extcon. 239 238 * extcon_register_notifier_all(*edev, *nb) : Register a notifier block 240 239 * for all supported external connectors of the extcon. 241 240 */ 242 241 extern int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, 243 - struct notifier_block *nb); 242 + struct notifier_block *nb); 244 243 extern int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, 245 - struct notifier_block *nb); 244 + struct notifier_block *nb); 246 245 extern int devm_extcon_register_notifier(struct device *dev, 247 246 struct extcon_dev *edev, unsigned int id, 248 247 struct notifier_block *nb); ··· 258 265 struct notifier_block *nb); 259 266 260 267 /* 261 - * Following API get the extcon device from devicetree. 262 - * This function use phandle of devicetree to get extcon device directly. 268 + * Following APIs get the extcon_dev from devicetree or by through extcon name. 263 269 */ 270 + extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name); 264 271 extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, 265 272 int index); 266 273 267 - /* Following API to get information of extcon device */ 274 + /* Following API get the name of extcon device. */ 268 275 extern const char *extcon_get_edev_name(struct extcon_dev *edev); 269 - 270 276 271 277 #else /* CONFIG_EXTCON */ 272 278 static inline int extcon_dev_register(struct extcon_dev *edev) ··· 276 284 static inline void extcon_dev_unregister(struct extcon_dev *edev) { } 277 285 278 286 static inline int devm_extcon_dev_register(struct device *dev, 279 - struct extcon_dev *edev) 287 + struct extcon_dev *edev) 280 288 { 281 289 return -EINVAL; 282 290 } 283 291 284 292 static inline void devm_extcon_dev_unregister(struct device *dev, 285 - struct extcon_dev *edev) { } 293 + struct extcon_dev *edev) { } 286 294 287 295 static inline struct extcon_dev *extcon_dev_allocate(const unsigned int *cable) 288 296 { ··· 292 300 static inline void extcon_dev_free(struct extcon_dev *edev) { } 293 301 294 302 static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, 295 - const unsigned int *cable) 303 + const unsigned int *cable) 296 304 { 297 305 return ERR_PTR(-ENOSYS); 298 306 } ··· 306 314 } 307 315 308 316 static inline int extcon_set_state(struct extcon_dev *edev, unsigned int id, 309 - bool cable_state) 317 + bool state) 310 318 { 311 319 return 0; 312 320 } 313 321 314 322 static inline int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id, 315 - bool cable_state) 323 + bool state) 316 324 { 317 325 return 0; 318 326 } ··· 323 331 } 324 332 325 333 static inline int extcon_get_property(struct extcon_dev *edev, unsigned int id, 326 - unsigned int prop, 327 - union extcon_property_value *prop_val) 334 + unsigned int prop, 335 + union extcon_property_value *prop_val) 328 336 { 329 337 return 0; 330 338 } 331 339 static inline int extcon_set_property(struct extcon_dev *edev, unsigned int id, 332 - unsigned int prop, 333 - union extcon_property_value prop_val) 340 + unsigned int prop, 341 + union extcon_property_value prop_val) 334 342 { 335 343 return 0; 336 344 } 337 345 338 346 static inline int extcon_set_property_sync(struct extcon_dev *edev, 339 - unsigned int id, unsigned int prop, 340 - union extcon_property_value prop_val) 347 + unsigned int id, unsigned int prop, 348 + union extcon_property_value prop_val) 341 349 { 342 350 return 0; 343 351 } 344 352 345 353 static inline int extcon_get_property_capability(struct extcon_dev *edev, 346 - unsigned int id, unsigned int prop) 354 + unsigned int id, unsigned int prop) 347 355 { 348 356 return 0; 349 357 } 350 358 351 359 static inline int extcon_set_property_capability(struct extcon_dev *edev, 352 - unsigned int id, unsigned int prop) 360 + unsigned int id, unsigned int prop) 353 361 { 354 362 return 0; 355 363 } 356 364 357 - static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) 358 - { 359 - return NULL; 360 - } 361 - 362 365 static inline int extcon_register_notifier(struct extcon_dev *edev, 363 - unsigned int id, 364 - struct notifier_block *nb) 366 + unsigned int id, struct notifier_block *nb) 365 367 { 366 368 return 0; 367 369 } 368 370 369 371 static inline int extcon_unregister_notifier(struct extcon_dev *edev, 370 - unsigned int id, 371 - struct notifier_block *nb) 372 + unsigned int id, struct notifier_block *nb) 372 373 { 373 374 return 0; 374 375 } ··· 377 392 struct extcon_dev *edev, unsigned int id, 378 393 struct notifier_block *nb) { } 379 394 395 + static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) 396 + { 397 + return ERR_PTR(-ENODEV); 398 + } 399 + 380 400 static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, 381 - int index) 401 + int index) 382 402 { 383 403 return ERR_PTR(-ENODEV); 384 404 } ··· 401 411 }; 402 412 403 413 static inline int extcon_register_interest(struct extcon_specific_cable_nb *obj, 404 - const char *extcon_name, const char *cable_name, 405 - struct notifier_block *nb) 414 + const char *extcon_name, const char *cable_name, 415 + struct notifier_block *nb) 406 416 { 407 417 return -EINVAL; 408 418 } 409 419 410 - static inline int extcon_unregister_interest(struct extcon_specific_cable_nb 411 - *obj) 420 + static inline int extcon_unregister_interest(struct extcon_specific_cable_nb *obj) 412 421 { 413 422 return -EINVAL; 414 - } 415 - 416 - static inline int extcon_get_cable_state_(struct extcon_dev *edev, unsigned int id) 417 - { 418 - return extcon_get_state(edev, id); 419 - } 420 - 421 - static inline int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id, 422 - bool cable_state) 423 - { 424 - return extcon_set_state_sync(edev, id, cable_state); 425 423 } 426 424 #endif /* __LINUX_EXTCON_H__ */
+75
include/linux/mfd/cros_ec_commands.h
··· 285 285 EC_HOST_EVENT_HANG_DETECT = 20, 286 286 /* Hang detect logic detected a hang and warm rebooted the AP */ 287 287 EC_HOST_EVENT_HANG_REBOOT = 21, 288 + /* PD MCU triggering host event */ 289 + EC_HOST_EVENT_PD_MCU = 22, 290 + 291 + /* EC desires to change state of host-controlled USB mux */ 292 + EC_HOST_EVENT_USB_MUX = 28, 288 293 289 294 /* 290 295 * The high bit of the event mask is not used as a host event code. If ··· 2908 2903 uint8_t port; 2909 2904 uint8_t role; 2910 2905 uint8_t mux; 2906 + } __packed; 2907 + 2908 + #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */ 2909 + #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */ 2910 + #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */ 2911 + 2912 + struct ec_response_usb_pd_control_v1 { 2913 + uint8_t enabled; 2914 + uint8_t role; 2915 + uint8_t polarity; 2916 + char state[32]; 2917 + } __packed; 2918 + 2919 + #define EC_CMD_USB_PD_PORTS 0x102 2920 + 2921 + struct ec_response_usb_pd_ports { 2922 + uint8_t num_ports; 2923 + } __packed; 2924 + 2925 + #define EC_CMD_USB_PD_POWER_INFO 0x103 2926 + 2927 + #define PD_POWER_CHARGING_PORT 0xff 2928 + struct ec_params_usb_pd_power_info { 2929 + uint8_t port; 2930 + } __packed; 2931 + 2932 + enum usb_chg_type { 2933 + USB_CHG_TYPE_NONE, 2934 + USB_CHG_TYPE_PD, 2935 + USB_CHG_TYPE_C, 2936 + USB_CHG_TYPE_PROPRIETARY, 2937 + USB_CHG_TYPE_BC12_DCP, 2938 + USB_CHG_TYPE_BC12_CDP, 2939 + USB_CHG_TYPE_BC12_SDP, 2940 + USB_CHG_TYPE_OTHER, 2941 + USB_CHG_TYPE_VBUS, 2942 + USB_CHG_TYPE_UNKNOWN, 2943 + }; 2944 + 2945 + struct usb_chg_measures { 2946 + uint16_t voltage_max; 2947 + uint16_t voltage_now; 2948 + uint16_t current_max; 2949 + uint16_t current_lim; 2950 + } __packed; 2951 + 2952 + struct ec_response_usb_pd_power_info { 2953 + uint8_t role; 2954 + uint8_t type; 2955 + uint8_t dualrole; 2956 + uint8_t reserved1; 2957 + struct usb_chg_measures meas; 2958 + uint32_t max_power; 2959 + } __packed; 2960 + 2961 + /* Get info about USB-C SS muxes */ 2962 + #define EC_CMD_USB_PD_MUX_INFO 0x11a 2963 + 2964 + struct ec_params_usb_pd_mux_info { 2965 + uint8_t port; /* USB-C port number */ 2966 + } __packed; 2967 + 2968 + /* Flags representing mux state */ 2969 + #define USB_PD_MUX_USB_ENABLED (1 << 0) 2970 + #define USB_PD_MUX_DP_ENABLED (1 << 1) 2971 + #define USB_PD_MUX_POLARITY_INVERTED (1 << 2) 2972 + #define USB_PD_MUX_HPD_IRQ (1 << 3) 2973 + 2974 + struct ec_response_usb_pd_mux_info { 2975 + uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ 2911 2976 } __packed; 2912 2977 2913 2978 /*****************************************************************************/