linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastien Bourdelin <sebastien.bourdelin@savoirfairelinux.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-watchdog@vger.kernel.org,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	kernel <kernel@savoirfairelinux.com>,
	mark@embeddedarm.com, kris@embeddedarm.com,
	Simon Horman <horms+renesas@verge.net.au>,
	Thierry Reding <treding@nvidia.com>,
	Jon Hunter <jonathanh@nvidia.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Fabio Estevam <fabio.estevam@nxp.com>,
	Sascha Hauer <kernel@pengutronix.de>,
	Shawn Guo <shawnguo@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	Guenter Roeck <linux@roeck-us.net>,
	Wim Van Sebroeck <wim@iguana.be>,
	Mark Rutland <mark.rutland@arm.com>,
	Rob Herring <robh+dt@kernel.org>,
	damien.riegel@savoirfairelinux.com,
	Lucile Quirion <lucile.quirion@savoirfairelinux.com>,
	Olof Johansson <olof@lixom.net>, Arnd Bergmann <arnd@arndb.de>,
	"Suzuki K. Poulose" <suzuki.poulose@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>
Subject: Re: [PATCH 4/6] bus: add driver for the Technologic Systems NBUS
Date: Wed, 1 Feb 2017 14:56:11 -0500	[thread overview]
Message-ID: <7bc0871f-ac0a-e8a0-0c84-a0e61b3991a8@savoirfairelinux.com> (raw)
In-Reply-To: <CACRpkdYHHrYY-fAPnNmV94ejFJ36rhSF0SqSVHkTNq+YCRNNZw@mail.gmail.com>

Hi Linus,

Thanks for your feedback.
I have a question regarding your recommendation, see below.

On 12/30/2016 02:58 AM, Linus Walleij wrote:

>> +
>> +static DEFINE_MUTEX(ts_nbus_lock);
>> +static bool ts_nbus_ready;
> 
> Why not move this to the struct ts_nbus state container?
> 
> It seems to be per-bus not per-system.
> 
>> +#define TS_NBUS_READ_MODE  0
>> +#define TS_NBUS_WRITE_MODE 1
>> +#define TS_NBUS_DIRECTION_IN  0
>> +#define TS_NBUS_DIRECTION_OUT 1
>> +#define TS_NBUS_WRITE_ADR 0
>> +#define TS_NBUS_WRITE_VAL 1
>> +
>> +struct ts_nbus {
>> +       struct pwm_device *pwm;
>> +       int num_data;
>> +       int *data;
>> +       int csn;
>> +       int txrx;
>> +       int strobe;
>> +       int ale;
>> +       int rdy;
>> +};
>> +
>> +static struct ts_nbus *ts_nbus;
> 
> Nopes. No singletons please.
> 
> Use the state container pattern:
> Documentation/driver-model/design-patterns.txt
> 

I understand the idea but have problem to find a good way to implement it.

Other drivers using the NBUS which are child nodes in the device tree
will use the ts_nbus_write() and ts_nbus_read() functions, it means these
drivers should have a pointer to the allocated ts_nbus and pass it to
the write() and read() functions as an argument if i'm not using a
singleton here.
But i'm lacking knowledge on how to properly share this pointer when
initializing the NBUS driver with the child nodes.

Perhaps my design is not appropriate for what i'm doing, if someone can
point me on a similar problematic it will be really helpful.

Best Regards,
Sebastien.

  reply	other threads:[~2017-02-01 19:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-14 23:12 [PATCH 0/6] Add board support for TS-4600 Sebastien Bourdelin
2016-12-14 23:12 ` [PATCH 1/6] of: documentation: add bindings documentation " Sebastien Bourdelin
2016-12-19 22:05   ` Rob Herring
2016-12-14 23:12 ` [PATCH 2/6] ARM: dts: TS-4600: add basic device tree Sebastien Bourdelin
2016-12-14 23:12 ` [PATCH 3/6] dt-bindings: bus: Add documentation for the Technologic Systems NBUS Sebastien Bourdelin
2016-12-19 22:12   ` Rob Herring
2016-12-14 23:12 ` [PATCH 4/6] bus: add driver " Sebastien Bourdelin
2016-12-30  7:58   ` Linus Walleij
2017-02-01 19:56     ` Sebastien Bourdelin [this message]
2017-02-03 13:51       ` Linus Walleij
2017-02-03 15:56         ` Sebastien Bourdelin
2016-12-14 23:12 ` [PATCH 5/6] ARM: dts: TS-4600: add NBUS support Sebastien Bourdelin
2016-12-30  8:01   ` Linus Walleij
2016-12-14 23:12 ` [PATCH 6/6] watchdog: ts4600: add driver for TS-4600 watchdog Sebastien Bourdelin
2016-12-15 10:28   ` kbuild test robot
2016-12-19 22:13   ` Rob Herring
2016-12-23  1:53   ` Guenter Roeck
2016-12-14 23:12 ` [PATCH 2/6] ARM: dts: TS-4600: add basic device tree Sebastien Bourdelin

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=7bc0871f-ac0a-e8a0-0c84-a0e61b3991a8@savoirfairelinux.com \
    --to=sebastien.bourdelin@savoirfairelinux.com \
    --cc=arnd@arndb.de \
    --cc=damien.riegel@savoirfairelinux.com \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=fabio.estevam@nxp.com \
    --cc=horms+renesas@verge.net.au \
    --cc=jonathanh@nvidia.com \
    --cc=kernel@pengutronix.de \
    --cc=kernel@savoirfairelinux.com \
    --cc=kris@embeddedarm.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@roeck-us.net \
    --cc=lucile.quirion@savoirfairelinux.com \
    --cc=mark.rutland@arm.com \
    --cc=mark@embeddedarm.com \
    --cc=olof@lixom.net \
    --cc=robh+dt@kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=treding@nvidia.com \
    --cc=will.deacon@arm.com \
    --cc=wim@iguana.be \
    --cc=yamada.masahiro@socionext.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).