extcon: Add the extcon_type to gather each connector into five category
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 11 Jul 2016 07:34:52 +0000 (16:34 +0900)
committerKishon Vijay Abraham I <kishon@ti.com>
Sat, 10 Sep 2016 11:18:51 +0000 (16:48 +0530)
This patch adds the new extcon type to group the each connecotr
into following five category. This type would be used to handle
the connectors as a group unit instead of a connector unit.
- EXTCON_TYPE_USB  : USB connector
- EXTCON_TYPE_CHG  : Charger connector
- EXTCON_TYPE_JACK : Jack connector
- EXTCON_TYPE_DISP : Display connector
- EXTCON_TYPE_MISC : Miscellaneous connector

Also, each external connector is possible to belong to one more extcon type.
In caes of EXTCON_CHG_USB_SDP, it have the EXTCON_TYPE_CHG and EXTCON_TYPE_USB.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Tested-by: Chris Zhong <zyw@rock-chips.com>
Tested-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
drivers/extcon/extcon.c
include/linux/extcon.h

index 9a266e5c7e105dc533bf51d8ed5b5538ee8727aa..f209a6959fededa24a745a8554a6252b9a98bbe6 100644 (file)
 #define SUPPORTED_CABLE_MAX    32
 #define CABLE_NAME_MAX         30
 
-static const char *extcon_name[] =  {
-       [EXTCON_NONE]                   = "NONE",
+struct __extcon_info {
+       unsigned int type;
+       unsigned int id;
+       const char *name;
+
+} extcon_info[] = {
+       [EXTCON_NONE] = {
+               .type = EXTCON_TYPE_MISC,
+               .id = EXTCON_NONE,
+               .name = "NONE",
+       },
 
        /* USB external connector */
-       [EXTCON_USB]                    = "USB",
-       [EXTCON_USB_HOST]               = "USB-HOST",
+       [EXTCON_USB] = {
+               .type = EXTCON_TYPE_USB,
+               .id = EXTCON_USB,
+               .name = "USB",
+       },
+       [EXTCON_USB_HOST] = {
+               .type = EXTCON_TYPE_USB,
+               .id = EXTCON_USB_HOST,
+               .name = "USB_HOST",
+       },
 
        /* Charging external connector */
-       [EXTCON_CHG_USB_SDP]            = "SDP",
-       [EXTCON_CHG_USB_DCP]            = "DCP",
-       [EXTCON_CHG_USB_CDP]            = "CDP",
-       [EXTCON_CHG_USB_ACA]            = "ACA",
-       [EXTCON_CHG_USB_FAST]           = "FAST-CHARGER",
-       [EXTCON_CHG_USB_SLOW]           = "SLOW-CHARGER",
+       [EXTCON_CHG_USB_SDP] = {
+               .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
+               .id = EXTCON_CHG_USB_SDP,
+               .name = "SDP",
+       },
+       [EXTCON_CHG_USB_DCP] = {
+               .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
+               .id = EXTCON_CHG_USB_DCP,
+               .name = "DCP",
+       },
+       [EXTCON_CHG_USB_CDP] = {
+               .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
+               .id = EXTCON_CHG_USB_CDP,
+               .name = "CDP",
+       },
+       [EXTCON_CHG_USB_ACA] = {
+               .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
+               .id = EXTCON_CHG_USB_ACA,
+               .name = "ACA",
+       },
+       [EXTCON_CHG_USB_FAST] = {
+               .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
+               .id = EXTCON_CHG_USB_FAST,
+               .name = "FAST-CHARGER",
+       },
+       [EXTCON_CHG_USB_SLOW] = {
+               .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
+               .id = EXTCON_CHG_USB_SLOW,
+               .name = "SLOW-CHARGER",
+       },
 
        /* Jack external connector */
-       [EXTCON_JACK_MICROPHONE]        = "MICROPHONE",
-       [EXTCON_JACK_HEADPHONE]         = "HEADPHONE",
-       [EXTCON_JACK_LINE_IN]           = "LINE-IN",
-       [EXTCON_JACK_LINE_OUT]          = "LINE-OUT",
-       [EXTCON_JACK_VIDEO_IN]          = "VIDEO-IN",
-       [EXTCON_JACK_VIDEO_OUT]         = "VIDEO-OUT",
-       [EXTCON_JACK_SPDIF_IN]          = "SPDIF-IN",
-       [EXTCON_JACK_SPDIF_OUT]         = "SPDIF-OUT",
+       [EXTCON_JACK_MICROPHONE] = {
+               .type = EXTCON_TYPE_JACK,
+               .id = EXTCON_JACK_MICROPHONE,
+               .name = "MICROPHONE",
+       },
+       [EXTCON_JACK_HEADPHONE] = {
+               .type = EXTCON_TYPE_JACK,
+               .id = EXTCON_JACK_HEADPHONE,
+               .name = "HEADPHONE",
+       },
+       [EXTCON_JACK_LINE_IN] = {
+               .type = EXTCON_TYPE_JACK,
+               .id = EXTCON_JACK_LINE_IN,
+               .name = "LINE-IN",
+       },
+       [EXTCON_JACK_LINE_OUT] = {
+               .type = EXTCON_TYPE_JACK,
+               .id = EXTCON_JACK_LINE_OUT,
+               .name = "LINE-OUT",
+       },
+       [EXTCON_JACK_VIDEO_IN] = {
+               .type = EXTCON_TYPE_JACK,
+               .id = EXTCON_JACK_VIDEO_IN,
+               .name = "VIDEO-IN",
+       },
+       [EXTCON_JACK_VIDEO_OUT] = {
+               .type = EXTCON_TYPE_JACK,
+               .id = EXTCON_JACK_VIDEO_OUT,
+               .name = "VIDEO-OUT",
+       },
+       [EXTCON_JACK_SPDIF_IN] = {
+               .type = EXTCON_TYPE_JACK,
+               .id = EXTCON_JACK_SPDIF_IN,
+               .name = "SPDIF-IN",
+       },
+       [EXTCON_JACK_SPDIF_OUT] = {
+               .type = EXTCON_TYPE_JACK,
+               .id = EXTCON_JACK_SPDIF_OUT,
+               .name = "SPDIF-OUT",
+       },
 
        /* Display external connector */
-       [EXTCON_DISP_HDMI]              = "HDMI",
-       [EXTCON_DISP_MHL]               = "MHL",
-       [EXTCON_DISP_DVI]               = "DVI",
-       [EXTCON_DISP_VGA]               = "VGA",
+       [EXTCON_DISP_HDMI] = {
+               .type = EXTCON_TYPE_DISP,
+               .id = EXTCON_DISP_HDMI,
+               .name = "HDMI",
+       },
+       [EXTCON_DISP_MHL] = {
+               .type = EXTCON_TYPE_DISP,
+               .id = EXTCON_DISP_MHL,
+               .name = "MHL",
+       },
+       [EXTCON_DISP_DVI] = {
+               .type = EXTCON_TYPE_DISP,
+               .id = EXTCON_DISP_DVI,
+               .name = "DVI",
+       },
+       [EXTCON_DISP_VGA] = {
+               .type = EXTCON_TYPE_DISP,
+               .id = EXTCON_DISP_VGA,
+               .name = "VGA",
+       },
 
        /* Miscellaneous external connector */
-       [EXTCON_DOCK]                   = "DOCK",
-       [EXTCON_JIG]                    = "JIG",
-       [EXTCON_MECHANICAL]             = "MECHANICAL",
-
-       NULL,
+       [EXTCON_DOCK] = {
+               .type = EXTCON_TYPE_MISC,
+               .id = EXTCON_DOCK,
+               .name = "DOCK",
+       },
+       [EXTCON_JIG] = {
+               .type = EXTCON_TYPE_MISC,
+               .id = EXTCON_JIG,
+               .name = "JIG",
+       },
+       [EXTCON_MECHANICAL] = {
+               .type = EXTCON_TYPE_MISC,
+               .id = EXTCON_MECHANICAL,
+               .name = "MECHANICAL",
+       },
+
+       { /* sentinel */ }
 };
 
 /**
@@ -168,7 +269,7 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
 
        for (i = 0; i < edev->max_supported; i++) {
                count += sprintf(buf + count, "%s=%d\n",
-                               extcon_name[edev->supported_cable[i]],
+                               extcon_info[edev->supported_cable[i]].name,
                                 !!(edev->state & (1 << i)));
        }
 
@@ -193,7 +294,7 @@ static ssize_t cable_name_show(struct device *dev,
        int i = cable->cable_index;
 
        return sprintf(buf, "%s\n",
-                       extcon_name[cable->edev->supported_cable[i]]);
+                       extcon_info[cable->edev->supported_cable[i]].name);
 }
 
 static ssize_t cable_state_show(struct device *dev,
index 667b1d35af12785beea30968ee9aa9271e1a66ae..46d802892c8231427440f84520c954f700e85353 100644 (file)
 
 #include <linux/device.h>
 
+/*
+ * Define the type of supported external connectors
+ */
+#define EXTCON_TYPE_USB                BIT(0)  /* USB connector */
+#define EXTCON_TYPE_CHG                BIT(1)  /* Charger connector */
+#define EXTCON_TYPE_JACK       BIT(2)  /* Jack connector */
+#define EXTCON_TYPE_DISP       BIT(3)  /* Display connector */
+#define EXTCON_TYPE_MISC       BIT(4)  /* Miscellaneous connector */
+
 /*
  * Define the unique id of supported external connectors
  */