All of lore.kernel.org
 help / color / mirror / Atom feed
From: MyungJoo Ham <myungjoo.ham@samsung.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: "Arnd Bergmann" <arnd@arndb.de>,
	LKML <linux-kernel@vger.kernel.org>, NeilBrown <neilb@suse.de>,
	"Randy Dunlap" <rdunlap@xenotime.net>,
	"Mike Lockwood" <lockwood@android.com>,
	"Arve Hjønnevag" <arve@android.com>,
	"Kyungmin Park" <kyungmin.park@samsung.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Morten CHRISTIANSEN" <morten.christiansen@stericsson.com>,
	"Mark Brown" <broonie@opensource.wolfsonmicro.com>,
	"John Stultz" <john.stultz@linaro.org>,
	"Joerg Roedel" <joerg.roedel@amd.com>,
	myungjoo.ham@gmail.com, cw00.choi@samsung.com
Subject: [PATCH v8 6/6] Documentation/extcon: porting guide for Android kernel switch driver.
Date: Thu, 19 Apr 2012 11:41:38 +0900	[thread overview]
Message-ID: <1334803298-24260-7-git-send-email-myungjoo.ham@samsung.com> (raw)
In-Reply-To: <1334803298-24260-1-git-send-email-myungjoo.ham@samsung.com>

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 Documentation/extcon/porting-android-switch-class |  124 +++++++++++++++++++++
 1 files changed, 124 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/extcon/porting-android-switch-class

diff --git a/Documentation/extcon/porting-android-switch-class b/Documentation/extcon/porting-android-switch-class
new file mode 100644
index 0000000..eb0fa5f
--- /dev/null
+++ b/Documentation/extcon/porting-android-switch-class
@@ -0,0 +1,124 @@
+
+	Staging/Android Switch Class Porting Guide
+	(linux/drivers/staging/android/switch)
+	(c) Copyright 2012 Samsung Electronics
+
+AUTHORS
+MyungJoo Ham <myungjoo.ham@samsung.com>
+
+/*****************************************************************
+ * CHAPTER 1.                                                    *
+ * PORTING SWITCH CLASS DEVICE DRIVERS                           *
+ *****************************************************************/
+
+****** STEP 1. Basic Functionality
+	No extcon extended feature, but switch features only.
+
+- struct switch_dev (fed to switch_dev_register/unregister)
+    @name: no change
+    @dev: no change
+    @index: drop (not used in switch device driver side anyway)
+    @state: no change
+	If you have used @state with magic numbers, keep it
+	at this step.
+    @print_name: no change but type change (switch_dev->extcon_dev)
+    @print_state: no change but type change (switch_dev->extcon_dev)
+
+- switch_dev_register(sdev, dev)
+	=> extcon_dev_register(edev, dev)
+	: no change but type change (sdev->edev)
+- switch_dev_unregister(sdev)
+	=> extcon_dev_unregister(edev)
+	: no change but type change (sdev->edev)
+- switch_get_state(sdev)
+	=> extcon_get_state(edev)
+	: no change but type change (sdev->edev) and (return: int->u32)
+- switch_set_state(sdev, state)
+	=> extcon_set_state(edev, state)
+	: no change but type change (sdev->edev) and (state: int->u32)
+
+With this changes, the ex-switch extcon class device works as it once
+worked as switch class device. However, it will now have additional
+interfaces (both ABI and in-kernel API) and different ABI locations.
+However, if CONFIG_ANDROID is enabled without CONFIG_ANDROID_SWITCH,
+/sys/class/switch/* will be symbolically linked to /sys/class/extcon/
+so that they are still compatible with legacy userspace processes.
+
+****** STEP 2. Multistate (no more magic numbers in state value)
+	Extcon's extended features for switch device drivers with
+	complex features usually required magic numbers in state
+	value of switch_dev. With extcon, such magic numbers that
+	support multiple cables (
+
+  1. Define cable names at edev->supported_cable.
+  2. (Recommended) remove print_state callback.
+  3. Use extcon_get_cable_state_(edev, index) or
+   extcon_get_cable_state(edev, cable_name) instead of
+   extcon_get_state(edev) if you intend to get a state of a specific
+   cable. Same for set_state. This way, you can remove the usage of
+   magic numbers in state value.
+  4. Use extcon_update_state() if you are updating specific bits of
+   the state value.
+
+Example: a switch device driver w/ magic numbers for two cables.
+	"0x00": no cables connected.
+	"0x01": cable 1 connected
+	"0x02": cable 2 connected
+	"0x03": cable 1 and 2 connected
+  1. edev->supported_cable = {"1", "2", NULL};
+  2. edev->print_state = NULL;
+  3. extcon_get_cable_state_(edev, 0) shows cable 1's state.
+     extcon_get_cable_state(edev, "1") shows cable 1's state.
+     extcon_set_cable_state_(edev, 1) sets cable 2's state.
+     extcon_set_cable_state(edev, "2") sets cable 2's state
+  4. extcon_update_state(edev, 0x01, 0) sets the least bit's 0.
+
+****** STEP 3. Notify other device drivers
+
+  You can notify others of the cable attach/detach events with
+notifier chains.
+
+  At the side of other device drivers (the extcon device itself
+does not need to get notified of its own events), there are two
+methods to register notifier_block for cable events:
+(a) for a specific cable or (b) for every cable.
+
+  (a) extcon_register_interest(obj, extcon_name, cable_name, nb)
+	Example: want to get news of "MAX8997_MUIC"'s "USB" cable
+
+	obj = kzalloc(sizeof(struct extcon_specific_cable_nb),
+		      GFP_KERNEL);
+	nb->notifier_call = the_callback_to_handle_usb;
+
+	extcon_register_intereset(obj, "MAX8997_MUIC", "USB", nb);
+
+  (b) extcon_register_notifier(edev, nb)
+	Call nb for any changes in edev.
+
+  Please note that in order to properly behave with method (a),
+the extcon device driver should support multistate feature (STEP 2).
+
+****** STEP 4. Inter-cable relation (mutually exclusive)
+
+  You can provide inter-cable mutually exclusiveness information
+for an extcon device. When cables A and B are declared to be mutually
+exclusive, the two cables cannot be in ATTACHED state simulteneously.
+
+
+/*****************************************************************
+ * CHAPTER 2.                                                    *
+ * PORTING USERSPACE w/ SWITCH CLASS DEVICE SUPPORT              *
+ *****************************************************************/
+
+****** ABI Location
+
+  If "CONFIG_ANDROID" is enabled and "CONFIG_ANDROID_SWITCH" is
+disabled, /sys/class/switch/* are created as symbolic links to
+/sys/class/extcon/*. Because CONFIG_ANDROID_SWITCH creates
+/sys/class/switch directory, we disable symboling linking if
+CONFIG_ANDROID_SWITCH is enabled.
+
+  The two files of switch class, name and state, are provided with
+extcon, too. When the multistate support (STEP 2 of CHAPTER 1.) is
+not enabled or print_state callback is supplied, the output of
+state ABI is same with switch class.
-- 
1.7.4.1


  parent reply	other threads:[~2012-04-19  2:41 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-23  8:52 [PATCH v7 0/6] Introduce External Connector Class (extcon) MyungJoo Ham
2012-03-23  8:52 ` [PATCH v7 1/6] Extcon (external connector): import Android's switch class and modify MyungJoo Ham
2012-04-18 21:47   ` Greg KH
2012-04-18 23:38     ` Kyungmin Park
2012-04-18 23:40       ` Greg KH
2012-04-18 23:48         ` Kyungmin Park
2012-04-19  0:01           ` Greg KH
2012-04-19  2:36     ` MyungJoo Ham
2012-04-19  2:41     ` [PATCH v8 0/6] Introduce External Connector Class (extcon) MyungJoo Ham
2012-04-19  2:41       ` [PATCH v8 1/6] Extcon (external connector): import Android's switch class and modify MyungJoo Ham
2012-04-19 11:38         ` Mark Brown
2012-04-20  2:37         ` Greg KH
2012-04-20  2:46           ` Kyungmin Park
2012-04-20  2:49             ` Greg KH
2012-04-20  2:57               ` Kyungmin Park
2012-04-20  3:00                 ` Greg KH
2012-04-20  3:08                   ` Kyungmin Park
2012-04-20  3:32                     ` Greg KH
2012-04-20  5:16                       ` [PATCH v8 resend 0/6] Introduce External Connector Class (extcon) MyungJoo Ham
2012-04-20  5:16                         ` [PATCH v8 resend 1/6] Extcon (external connector): import Android's switch class and modify MyungJoo Ham
2012-04-20  7:00                           ` Ryan Mallon
2012-04-20  5:16                         ` [PATCH v8 resend 2/6] Extcon: support generic GPIO extcon driver MyungJoo Ham
2012-04-20  5:16                         ` [PATCH v8 resend 3/6] Extcon: support notification based on the state changes MyungJoo Ham
2012-04-20  5:16                         ` [PATCH v8 resend 4/6] Extcon: support multiple states at a device MyungJoo Ham
2012-04-20  5:16                         ` [PATCH v8 resend 5/6] Extcon: support mutually exclusive relation between cables MyungJoo Ham
2012-04-20  5:16                         ` [PATCH v8 resend 6/6] Documentation/extcon: porting guide for Android kernel switch driver MyungJoo Ham
2012-04-20 16:25                           ` Greg KH
2012-04-20 17:05                             ` Mark Brown
2012-04-20 17:15                               ` Greg KH
2012-04-20 21:59                                 ` Mark Brown
2012-04-20 16:27                         ` [PATCH v8 resend 0/6] Introduce External Connector Class (extcon) Greg KH
2012-04-23 11:18                           ` MyungJoo Ham
2012-04-23 11:19                             ` [PATCH] Remove "switch" class in drivers/staging/android/switch MyungJoo Ham
2012-04-23 20:25                               ` Greg KH
2012-04-19  2:41       ` [PATCH v8 2/6] Extcon: support generic GPIO extcon driver MyungJoo Ham
2012-04-19 11:40         ` Mark Brown
2012-04-19  2:41       ` [PATCH v8 3/6] Extcon: support notification based on the state changes MyungJoo Ham
2012-04-19  2:41       ` [PATCH v8 4/6] Extcon: support multiple states at a device MyungJoo Ham
2012-04-19  2:41       ` [PATCH v8 5/6] Extcon: support mutually exclusive relation between cables MyungJoo Ham
2012-04-19  2:41       ` MyungJoo Ham [this message]
2012-03-23  8:52 ` [PATCH v7 2/6] Extcon: support generic GPIO extcon driver MyungJoo Ham
2012-03-23  8:53 ` [PATCH v7 3/6] Extcon: support notification based on the state changes MyungJoo Ham
2012-03-23  8:53 ` [PATCH v7 4/6] Extcon: support multiple states at a device MyungJoo Ham
2012-03-23  8:53 ` [PATCH v7 5/6] Extcon: support mutually exclusive relation between cables MyungJoo Ham
2012-03-23  8:53 ` [PATCH v7 6/6] Documentation/extcon: porting guide for Android kernel switch driver MyungJoo Ham
2012-03-23  8:53 ` [RFC PATCH] Remove "switch" class in drivers/staging/android/switch MyungJoo Ham
2012-03-28  9:39 ` [PATCH v7 0/6] Introduce External Connector Class (extcon) MyungJoo Ham
2012-03-28 14:44   ` Greg KH
2012-03-28 15:24     ` Arnd Bergmann
2012-03-28 15:28       ` Greg KH
2012-03-29  4:20         ` Kyungmin Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1334803298-24260-7-git-send-email-myungjoo.ham@samsung.com \
    --to=myungjoo.ham@samsung.com \
    --cc=arnd@arndb.de \
    --cc=arve@android.com \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=cw00.choi@samsung.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joerg.roedel@amd.com \
    --cc=john.stultz@linaro.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lockwood@android.com \
    --cc=morten.christiansen@stericsson.com \
    --cc=myungjoo.ham@gmail.com \
    --cc=neilb@suse.de \
    --cc=rdunlap@xenotime.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.