linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa@the-dreams.de>
To: Jean Delvare <jdelvare@suse.de>
Cc: Yadi Hu <yadi.hu@windriver.com>, linux-i2c@vger.kernel.org
Subject: Re: [PATCH] i2c-eg20t: use dynamically registered adapter number
Date: Sun, 18 Sep 2016 21:22:50 +0200	[thread overview]
Message-ID: <20160918192250.GA1415@katana> (raw)
In-Reply-To: <20160826173019.1f939ce5@endymion>

[-- Attachment #1: Type: text/plain, Size: 1592 bytes --]


> If not, it may make sense to add a helper function exposing
> __i2c_first_dynamic_bus_num to drivers (something like
> i2c_is_dynamic_bus_num().) After all, i2c_add_numbered_adapter() mostly
> makes sense if static i2c device definitions exist. If not,
> i2c_add_adapter() is just as good. So something like:
> 
> 	if (i2c_is_dynamic_bus_num(i))
> 		ret = i2c_add_adapter(pch_adap);
> 	else {
> 		pch_adap->nr = i;
> 		ret = i2c_add_numbered_adapter(pch_adap);
> 	}
> 
> may make sense. Unless someone has a better idea.

PASEMI does:

        smbus->adapter.nr = PCI_FUNC(dev->devfn);

I am unsure if there is any guarantee in what order PCI_FUNCs are
probed, yet I have the feeling we could try a little harder to get the
numbered adapter. What about this (untested, just to get the idea)?

static inline int i2c_add_adapter_try_numbered(struct i2c_adapter *new_adap)
{
	int ret;
	struct i2c_adapter *old_adap = i2c_get_adapter(new_adap->nr);

	if (old_adap && new_adap->nr >= __i2c_first_dynamic_bus_num) {
		i2c_put_adapter(old_adap);
		dev_dbg(&new_adap->dev, "Static bus number occupied, trying dynamic number\n");
		ret = i2c_add_adapter(new_adap);
	} else {
		ret = i2c_add_numbered_adapter(new_adap);
	}

	return ret;
}

I used 'static inline' because I think the drivers needing this should
carry the extra weight. But no major objection to put sth like this also
into the core. The documentation for this function should carry a big
note that this is only a workaround and it should not be used directly.

Thoughts?

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2016-09-18 19:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23  9:05 [PATCH] i2c-eg20t: use dynamically registered adapter number Yadi Hu
2016-08-26 15:30 ` Jean Delvare
2016-09-02  9:44   ` Yadi
2016-09-17 21:49   ` Wolfram Sang
2016-09-19  3:25     ` Yadi
2016-09-19  6:44       ` Wolfram Sang
2016-09-18 19:22   ` Wolfram Sang [this message]
2016-09-19  9:02     ` Jean Delvare
2016-09-20 15:48       ` Jean Delvare
  -- strict thread matches above, loose matches on Subject: below --
2016-08-23  8:55 Yadi Hu

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=20160918192250.GA1415@katana \
    --to=wsa@the-dreams.de \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=yadi.hu@windriver.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).