From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Daniel Vetter <daniel.vetter-/w4YWyX8dFk@public.gmane.org>
Cc: Intel Graphics Development
<intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
DRI Development
<dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 3/7] i2c: export bit-banging algo functions
Date: Mon, 27 Feb 2012 23:20:40 +0100 [thread overview]
Message-ID: <20120227232040.0476d508@endymion.delvare> (raw)
In-Reply-To: <1329255445-6312-3-git-send-email-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
Hi Daniel,
Sorry for the late reply.
On Tue, 14 Feb 2012 22:37:21 +0100, Daniel Vetter wrote:
> i915 has a hw i2c controller (gmbus) but for a bunch of stupid reasons
> we need to be able to fall back to the bit-banging algo on gpio pins.
>
> The current code sets up a 2nd i2c controller for the same i2c bus using
> the bit-banging algo. This has a bunch of issues, the major one being
> that userspace can directly access this fallback i2c adaptor behind
> the drivers back.
>
> But we need to frob a few registers before and after using fallback
> gpio bit-banging, so this horribly fails.
You could use the pre_xfer and post_xfer hooks together with a shared
mutex to solve the problem. But I agree its much cleaner to expose a
single adapter in the first place.
If you need to hot-switch between hardware and bit-banged I2C, I suggest
that you lock the bus while doing so, to avoid switching while a
transaction is in progress. This can be achieved with
i2c_lock_adapter() and i2c_unlock_adapter().
> The new plan is to only set up one i2c adaptor and transparently fall
> back to bit-banging by directly calling the xfer function of the bit-
> banging algo in the i2c core.
>
> To make that possible, export the 2 i2c algo functions.
>
> Signed-off-by: Daniel Vetter <daniel.vetter-/w4YWyX8dFk@public.gmane.org>
> ---
> drivers/i2c/algos/i2c-algo-bit.c | 12 +++++++-----
> include/linux/i2c-algo-bit.h | 4 ++++
> 2 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
> index 525c734..ec1651a 100644
> --- a/drivers/i2c/algos/i2c-algo-bit.c
> +++ b/drivers/i2c/algos/i2c-algo-bit.c
> @@ -531,8 +531,8 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
> return 0;
> }
>
> -static int bit_xfer(struct i2c_adapter *i2c_adap,
> - struct i2c_msg msgs[], int num)
> +int i2c_bit_xfer(struct i2c_adapter *i2c_adap,
> + struct i2c_msg msgs[], int num)
> {
> struct i2c_msg *pmsg;
> struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
> @@ -598,21 +598,23 @@ bailout:
> adap->post_xfer(i2c_adap);
> return ret;
> }
> +EXPORT_SYMBOL(i2c_bit_xfer);
>
> -static u32 bit_func(struct i2c_adapter *adap)
> +u32 i2c_bit_func(struct i2c_adapter *adap)
> {
> return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
> I2C_FUNC_SMBUS_READ_BLOCK_DATA |
> I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
> I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
> }
> +EXPORT_SYMBOL(i2c_bit_func);
>
>
> /* -----exported algorithm data: ------------------------------------- */
>
> static const struct i2c_algorithm i2c_bit_algo = {
> - .master_xfer = bit_xfer,
> - .functionality = bit_func,
> + .master_xfer = i2c_bit_xfer,
> + .functionality = i2c_bit_func,
> };
>
> /*
> diff --git a/include/linux/i2c-algo-bit.h b/include/linux/i2c-algo-bit.h
> index 4f98148..cdd6336 100644
> --- a/include/linux/i2c-algo-bit.h
> +++ b/include/linux/i2c-algo-bit.h
> @@ -47,6 +47,10 @@ struct i2c_algo_bit_data {
> int timeout; /* in jiffies */
> };
>
> +int i2c_bit_xfer(struct i2c_adapter *i2c_adap,
> + struct i2c_msg msgs[], int num);
> +u32 i2c_bit_func(struct i2c_adapter *adap);
> +
> int i2c_bit_add_bus(struct i2c_adapter *);
> int i2c_bit_add_numbered_bus(struct i2c_adapter *);
I have no problem with this in the principle. In the details, I don't
understand why you don't simply export i2c_bit_algo? This is one fewer
export and should serve the same purpose - even allowing faster
initializations in some cases.
Looking a bit more to the i2c-algo-bit code, I also notice that
bypassing i2c_bit_add_bus() means you'll miss some of its features,
namely bus testing, default retries value and warning on non-compliant
buses. While none of these are mandatory, it may make sense to export a
new function i2c_bit_add_numbered_bus() which would call
__i2c_bit_add_bus() with no callback function. If you do that, you may
not have to export anything else.
I leave it up to you which way you want to implement it, all are fine
with me, and we can always change later if more use cases show up which
would work better with a different implementation.
--
Jean Delvare
next prev parent reply other threads:[~2012-02-27 22:20 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-14 21:37 [PATCH 1/7] drm/i915: add dev_priv to intel_gmbus Daniel Vetter
[not found] ` <1329255445-6312-1-git-send-email-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2012-02-14 21:37 ` [PATCH 2/7] drm/nouveau: do a better job at hiding the NIH i2c bit-banging algo Daniel Vetter
[not found] ` <1329255445-6312-2-git-send-email-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2012-02-27 17:25 ` Daniel Vetter
2012-02-14 21:37 ` [PATCH 3/7] i2c: export bit-banging algo functions Daniel Vetter
[not found] ` <1329255445-6312-3-git-send-email-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2012-02-27 17:27 ` Daniel Vetter
2012-02-27 22:20 ` Jean Delvare [this message]
[not found] ` <20120227232040.0476d508-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-02-27 22:52 ` Daniel Vetter
[not found] ` <20120227225223.GB1050-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2012-02-27 23:39 ` [PATCH] " Daniel Vetter
[not found] ` <1330385979-19406-1-git-send-email-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2012-02-28 8:08 ` Jean Delvare
[not found] ` <20120228090817.1a95c28b-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2012-02-29 19:48 ` Daniel Vetter
2012-02-28 8:06 ` [PATCH 3/7] " Jean Delvare
2012-02-14 21:37 ` [PATCH 4/7] drm/i915: merge struct intel_gpio into struct intel_gmbus Daniel Vetter
2012-02-14 21:37 ` [PATCH 5/7] drm/i915: merge gmbus and gpio i2c adpater into one Daniel Vetter
2012-02-14 21:37 ` [PATCH 6/7] drm/i915: i2c: unconditionally set up gpio fallback Daniel Vetter
[not found] ` <1329255445-6312-6-git-send-email-daniel.vetter-/w4YWyX8dFk@public.gmane.org>
2012-02-14 22:53 ` [PATCH] " Daniel Vetter
2012-02-14 23:47 ` [PATCH 6/7] " Eugeni Dodonov
[not found] ` <CAC7LmnvP0wUroQq6VJ3QeoWDy=WEk_UcfkKiuYx=hWZ8WT6tMQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-27 18:22 ` [PATCH] " Daniel Vetter
2012-02-27 18:29 ` Eugeni Dodonov
2012-02-14 21:37 ` [PATCH 7/7] drm/i915: reenable gmbus on gen3+ again Daniel Vetter
2012-02-27 17:53 ` [Intel-gfx] [PATCH 1/7] drm/i915: add dev_priv to intel_gmbus Eugeni Dodonov
[not found] ` <CAC7LmnupmYAs-+pUQw-wYh7+rzeK5wowDQKrmE7hh3j=pvHdvA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-29 19:56 ` Daniel Vetter
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=20120227232040.0476d508@endymion.delvare \
--to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
--cc=daniel.vetter-/w4YWyX8dFk@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=intel-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/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).