25 #include <linux/module.h>
26 #include <linux/types.h>
28 #include <linux/device.h>
32 #include <linux/slab.h>
67 static struct class *extcon_class;
68 #if defined(CONFIG_ANDROID)
124 count +=
sprintf(buf + count,
"%s=%d\n",
126 !!(edev->
state & (1 << i)));
134 const char *buf,
size_t count)
140 ret =
sscanf(buf,
"0x%x", &state);
164 return sprintf(buf,
"%s\n", dev_name(edev->
dev));
196 ret =
sscanf(buf,
"%d", &state);
235 if (edev->
state != ((edev->
state & ~mask) | (state & mask))) {
238 if (check_mutually_exclusive(edev, (edev->
state & ~mask) |
240 spin_unlock_irqrestore(&edev->
lock, flags);
244 edev->
state &= ~mask;
252 length = name_show(edev->
dev,
NULL, prop_buf);
254 if (prop_buf[length - 1] ==
'\n')
255 prop_buf[length - 1] = 0;
256 snprintf(name_buf,
sizeof(name_buf),
257 "NAME=%s", prop_buf);
258 envp[env_offset++] = name_buf;
260 length = state_show(edev->
dev,
NULL, prop_buf);
262 if (prop_buf[length - 1] ==
'\n')
263 prop_buf[length - 1] = 0;
264 snprintf(state_buf,
sizeof(state_buf),
265 "STATE=%s", prop_buf);
266 envp[env_offset++] = state_buf;
268 envp[env_offset] =
NULL;
270 spin_unlock_irqrestore(&edev->
lock, flags);
276 spin_unlock_irqrestore(&edev->
lock, flags);
278 dev_err(edev->
dev,
"out of memory in extcon_set_state\n");
283 spin_unlock_irqrestore(&edev->
lock, flags);
366 int index,
bool cable_state)
373 state = cable_state ? (1 <<
index) : 0;
388 const char *cable_name,
bool cable_state)
391 (edev, cable_name), cable_state);
424 bool cable_state =
true;
462 const char *extcon_name,
const char *cable_name,
465 if (!obj || !cable_name || !nb)
554 static int create_extcon_class(
void)
558 if (IS_ERR(extcon_class))
559 return PTR_ERR(extcon_class);
562 #if defined(CONFIG_ANDROID)
564 if (
WARN(!switch_class,
"cannot allocate"))
572 static void extcon_dev_release(
struct device *dev)
577 static const char *muex_name =
"mutually_exclusive";
578 static void dummy_sysfs_dev_release(
struct device *dev)
597 ret = create_extcon_class();
611 if (index > SUPPORTED_CABLE_MAX) {
612 dev_err(edev->
dev,
"extcon: maximum number of supported cables exceeded.\n");
620 edev->
dev->class = extcon_class;
621 edev->
dev->release = extcon_dev_release;
634 goto err_sysfs_alloc;
639 snprintf(buf, 10,
"cable.%d", index);
640 str = kzalloc(
sizeof(
char) * (
strlen(buf) + 1),
643 for (index--; index >= 0; index--) {
649 goto err_alloc_cables;
699 name = kzalloc(
sizeof(
char) * (
strlen(buf) + 1),
702 for (index--; index >= 0; index--) {
729 goto err_alloc_groups;
737 &edev->
cables[index].attr_g;
750 #if defined(CONFIG_ANDROID)
764 list_add(&edev->
entry, &extcon_dev_list);
807 dev_err(edev->
dev,
"Failed to unregister extcon_dev (%s)\n",
808 dev_name(edev->
dev));
828 #if defined(CONFIG_ANDROID)
837 static int __init extcon_class_init(
void)
839 return create_extcon_class();
843 static void __exit extcon_class_exit(
void)
845 #if defined(CONFIG_ANDROID)