mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Platform: x86: chromeos_laptop: defer probing if no i2c busses found
@ 2013-04-18 21:55 Olof Johansson
  2013-04-18 22:00 ` Benson Leung
  2013-04-18 22:05 ` Olof Johansson
  0 siblings, 2 replies; 4+ messages in thread
From: Olof Johansson @ 2013-04-18 21:55 UTC (permalink / raw)
  To: Matthew Garrett
  Cc: torvalds, platform-driver-x86, linux-kernel, bleung, dirk,
	Olof Johansson

If chromeos_laptop is loaded before the DRM driver, the i2c busses will
not yet be available. Defer probe for that case and try again later.

Trickling the error up to the module init function is unfortuantely a
little awkward, since the i2c bus lookup and device registration happens
as a dmi callback.

Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Olof Johansson <olof@lixom.net>
---
 drivers/platform/x86/chromeos_laptop.c |   33 ++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
index 3e5b4497..7ff12fa 100644
--- a/drivers/platform/x86/chromeos_laptop.c
+++ b/drivers/platform/x86/chromeos_laptop.c
@@ -39,6 +39,7 @@
 static struct i2c_client *als;
 static struct i2c_client *tp;
 static struct i2c_client *ts;
+static int setup_error;
 
 const char *i2c_adapter_names[] = {
 	"SMBus I801 adapter",
@@ -191,7 +192,8 @@ static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
 	if (!dev) {
 		pr_err("%s: i2c adapter %s not found on system.\n", __func__,
 		       name);
+		setup_error = -EPROBE_DEFER;
 		return -ENODEV;
 	}
 	adapter = to_i2c_adapter(dev);
 	return adapter->nr;
@@ -381,23 +383,38 @@ static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
 };
 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
 
+static void chromeos_laptop_unregister(void)
+{
+	if (als)
+		i2c_unregister_device(als);
+	if (tp)
+		i2c_unregister_device(tp);
+	if (ts)
+		i2c_unregister_device(ts);
+
+	als = NULL;
+	tp = NULL;
+	ts = NULL;
+}
+
 static int __init chromeos_laptop_init(void)
 {
+	setup_error = 0;
+
 	if (!dmi_check_system(chromeos_laptop_dmi_table)) {
 		pr_debug("%s unsupported system.\n", __func__);
 		return -ENODEV;
 	}
-	return 0;
+
+	if (setup_error)
+		chromeos_laptop_unregister();
+
+	return setup_error;
 }
 
 static void __exit chromeos_laptop_exit(void)
 {
-	if (als)
-		i2c_unregister_device(als);
-	if (tp)
-		i2c_unregister_device(tp);
-	if (ts)
-		i2c_unregister_device(ts);
+	chromeos_laptop_unregister();
 }
 
 module_init(chromeos_laptop_init);
-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Platform: x86: chromeos_laptop: defer probing if no i2c busses found
  2013-04-18 21:55 [PATCH] Platform: x86: chromeos_laptop: defer probing if no i2c busses found Olof Johansson
@ 2013-04-18 22:00 ` Benson Leung
  2013-04-18 22:05 ` Olof Johansson
  1 sibling, 0 replies; 4+ messages in thread
From: Benson Leung @ 2013-04-18 22:00 UTC (permalink / raw)
  To: Olof Johansson
  Cc: Matthew Garrett, Linus Torvalds, platform-driver-x86, linux-kernel, dirk

 Acked-by: Benson Leung <bleung@chromium.org>

On Thu, Apr 18, 2013 at 2:55 PM, Olof Johansson <olof@lixom.net> wrote:
> If chromeos_laptop is loaded before the DRM driver, the i2c busses will
> not yet be available. Defer probe for that case and try again later.
>
> Trickling the error up to the module init function is unfortuantely a
> little awkward, since the i2c bus lookup and device registration happens
> as a dmi callback.
>
> Reported-by: Dirk Hohndel <dirk@hohndel.org>
> Signed-off-by: Olof Johansson <olof@lixom.net>
> ---
>  drivers/platform/x86/chromeos_laptop.c |   33 ++++++++++++++++++++++++--------
>  1 file changed, 25 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
> index 3e5b4497..7ff12fa 100644
> --- a/drivers/platform/x86/chromeos_laptop.c
> +++ b/drivers/platform/x86/chromeos_laptop.c
> @@ -39,6 +39,7 @@
>  static struct i2c_client *als;
>  static struct i2c_client *tp;
>  static struct i2c_client *ts;
> +static int setup_error;
>
>  const char *i2c_adapter_names[] = {
>         "SMBus I801 adapter",
> @@ -191,7 +192,8 @@ static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
>         if (!dev) {
>                 pr_err("%s: i2c adapter %s not found on system.\n", __func__,
>                        name);
> +               setup_error = -EPROBE_DEFER;
>                 return -ENODEV;
>         }
>         adapter = to_i2c_adapter(dev);
>         return adapter->nr;
> @@ -381,23 +383,38 @@ static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
>  };
>  MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
>
> +static void chromeos_laptop_unregister(void)
> +{
> +       if (als)
> +               i2c_unregister_device(als);
> +       if (tp)
> +               i2c_unregister_device(tp);
> +       if (ts)
> +               i2c_unregister_device(ts);
> +
> +       als = NULL;
> +       tp = NULL;
> +       ts = NULL;
> +}
> +
>  static int __init chromeos_laptop_init(void)
>  {
> +       setup_error = 0;
> +
>         if (!dmi_check_system(chromeos_laptop_dmi_table)) {
>                 pr_debug("%s unsupported system.\n", __func__);
>                 return -ENODEV;
>         }
> -       return 0;
> +
> +       if (setup_error)
> +               chromeos_laptop_unregister();
> +
> +       return setup_error;
>  }
>
>  static void __exit chromeos_laptop_exit(void)
>  {
> -       if (als)
> -               i2c_unregister_device(als);
> -       if (tp)
> -               i2c_unregister_device(tp);
> -       if (ts)
> -               i2c_unregister_device(ts);
> +       chromeos_laptop_unregister();
>  }
>
>  module_init(chromeos_laptop_init);
> --
> 1.7.10.4
>



-- 
Benson Leung
Software Engineer, Chrom* OS
bleung@chromium.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Platform: x86: chromeos_laptop: defer probing if no i2c busses found
  2013-04-18 21:55 [PATCH] Platform: x86: chromeos_laptop: defer probing if no i2c busses found Olof Johansson
  2013-04-18 22:00 ` Benson Leung
@ 2013-04-18 22:05 ` Olof Johansson
  2013-04-18 22:44   ` Olof Johansson
  1 sibling, 1 reply; 4+ messages in thread
From: Olof Johansson @ 2013-04-18 22:05 UTC (permalink / raw)
  To: Matthew Garrett
  Cc: Linus Torvalds, platform-driver-x86, linux-kernel, Benson Leung,
	dirk, Olof Johansson

On Thu, Apr 18, 2013 at 2:55 PM, Olof Johansson <olof@lixom.net> wrote:
> If chromeos_laptop is loaded before the DRM driver, the i2c busses will
> not yet be available. Defer probe for that case and try again later.
>
> Trickling the error up to the module init function is unfortuantely a
> little awkward, since the i2c bus lookup and device registration happens
> as a dmi callback.

Uh, wait, hold off on this. I'm returning -EPROBE_DEFER from the
module init function. It's not valid outside of the driver model.


-Olof

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Platform: x86: chromeos_laptop: defer probing if no i2c busses found
  2013-04-18 22:05 ` Olof Johansson
@ 2013-04-18 22:44   ` Olof Johansson
  0 siblings, 0 replies; 4+ messages in thread
From: Olof Johansson @ 2013-04-18 22:44 UTC (permalink / raw)
  To: Matthew Garrett
  Cc: Linus Torvalds, platform-driver-x86, linux-kernel, Benson Leung,
	dirk, Olof Johansson

On Thu, Apr 18, 2013 at 3:05 PM, Olof Johansson <olof@lixom.net> wrote:
> On Thu, Apr 18, 2013 at 2:55 PM, Olof Johansson <olof@lixom.net> wrote:
>> If chromeos_laptop is loaded before the DRM driver, the i2c busses will
>> not yet be available. Defer probe for that case and try again later.
>>
>> Trickling the error up to the module init function is unfortuantely a
>> little awkward, since the i2c bus lookup and device registration happens
>> as a dmi callback.
>
> Uh, wait, hold off on this. I'm returning -EPROBE_DEFER from the
> module init function. It's not valid outside of the driver model.

Ugh. Ok, so that worked just because any error seem to re-trigger an
attempt to load the module later on my system (three times, it seems),
and most of the reproductions I had happened to work out on the second
load.

Looks like keeping the module loaded and adding a bus notifier to wait
for the right busses to show up is the only way to do this in a
foolproof way. Revised patch tonight or tomorrow.


-Olof

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-04-18 22:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-18 21:55 [PATCH] Platform: x86: chromeos_laptop: defer probing if no i2c busses found Olof Johansson
2013-04-18 22:00 ` Benson Leung
2013-04-18 22:05 ` Olof Johansson
2013-04-18 22:44   ` Olof Johansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®