From: Johan Hovold <johan@kernel.org>
To: Serge Semin <fancer.lancer@gmail.com>
Cc: Johan Hovold <johan@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Serge Semin <Sergey.Semin@t-platforms.ru>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: cp210x: Add cp2108 GPIOs support
Date: Fri, 28 Jun 2019 10:11:41 +0200 [thread overview]
Message-ID: <20190628081141.GJ508@localhost> (raw)
In-Reply-To: <20190615225634.fyckt4e7gpnd5fid@mobilestation>
On Sun, Jun 16, 2019 at 01:56:36AM +0300, Serge Semin wrote:
> > > +/* CP2108 interfaces, gpio (per interface), port-blocks number, GPIO block. */
> > > +#define CP2108_IFACE_NUM 4
> > > +#define CP2108_GPIO_NUM 4
> > > +#define CP2108_PB_NUM 5
> > > +#define CP2108_GPIO_PB 1
> >
> > Please try to give these more descriptive names; I'd prefer COUNT over
> > NUM when used as a suffix.
> >
> > Perhaps slap an INDEX suffix on CP2108_GPIO_PB etc.
>
> Ok. Added CNT and IDX suffixes.
Please spell out COUNT, no need to be that terse here.
> > > +/*
> > > + * CP2108 default pins state. There are five PBs. Each one is with its specific
> > > + * pins-set (see USB Express SDK sources or SDK-based smt application
> > > + * https://github.com/fancer/smt-cp210x for details).
> > > + */
> > > +struct cp2108_state {
> > > + __le16 mode[CP2108_PB_NUM]; /* 0 - Open-Drain, 1 - Push-Pull */
> > > + __le16 low_power[CP2108_PB_NUM];
> > > + __le16 latch[CP2108_PB_NUM]; /* 0 - Logic Low, 1 - Logic High */
> > > +} __packed;
> >
> > Ok, so you use mode[CP2108_GPIO_PB] to get the pin modes below;
> > what are the other "PB"s used for? Why is it a "port" block, if all 16
> > pins allocated to four different ports are accessible through one block?
> >
> > Please try to make the comment self-contained (even if you leave some
> > details out). And perhaps we shouldn't refer to proprietary code in
> > here, and in any case the link may go away.
> >
>
> Ok added a bit more detailed information regarding the port blocks. But
> I'd prefer to keep the link. First of all I can't provide the complete
> description of the fields here because it would take too much space and
> in fact is pointless since only a single port block with GPIOs is utilized.
> So the link and the SDK info are a good reference to find some details
> (especially due to lacking such an info in the chip datasheet).
I never said it had to be complete, just self-contained for what it's
used for here. I don't want to go browsing random vendor code to figure
out what the code is doing when reviewing or modifying kernel code.
> Secondly even though the code is distributed under the Silicon Labs
> specific license it is open-source.
But it's not necessarily GPL compatible, which is what we care about
here.
Then again, you've already used it as reference for the protocol, so
let's keep it in.
> Finally the link may go away only
> if I removed the application from my github account, which I don't
> intend to.
Ok, didn't notice it was your account.
> > > +/*
> > > + * CP210X_VENDOR_SPECIFIC, CP210X_GET_PORTCONFIG call reads these 73 bytes.
> > > + * Reset/Suspend latches describe default states after reset/suspend of the
> > > + * pins. The rest are responsible for alternate functions settings of the
> > > + * chip pins (see USB Express SDK sources or SDK-based smt application
> > > + * https://github.com/fancer/smt-cp210x for details).
> > > + */
> > > +struct cp2108_config {
> > > + struct cp2108_state reset_latch;
> > > + struct cp2108_state suspend_latch;
> > > + u8 ip_delay[CP2108_IFACE_NUM];
> > > + u8 enhanced_fxn[CP2108_IFACE_NUM];
> > > + u8 enhanced_fxn_dev;
> > > + u8 ext_clock_freq[CP2108_IFACE_NUM];
> > > +} __packed;
> > > +
> > > +/* CP2108 port alternate functions fields */
So it's really the enhanced_fxn field above right (and not about pin
alternate functions only).
> > > +#define CP2108_GPIO_TXLED_MODE BIT(0)
> > > +#define CP2108_GPIO_RXLED_MODE BIT(1)
> > > +#define CP2108_GPIO_RS485_MODE BIT(2)
> > > +#define CP2108_GPIO_RS485_LOGIC BIT(3)
> > > +#define CP2108_GPIO_CLOCK_MODE BIT(4)
> > > +#define CP2108_DYNAMIC_SUSPEND BIT(5)
> >
> > No GPIO infix?
>
> No, because this refers to all pins state when the chip being suspended
> (whether the suspend_latch state is pushed to the pins at the suspend USB
> state), while the rest of the macros are defined for the GPIOs alternative
> functions. I'll add the MODE suffix though.
Ok, does the pins maintain their state if DYNAMIC_SUSPEND is set or cleared?
> > > + int result, bufsize = sizeof(buf.single);
> >
> > One declaration per line please, especially when initialising.
>
> Done. Though I can't remember this being requirement in the kernel
> coding style. Could you give me a link to the corresponding statement?
It's actually mentioned in passing in the coding style, but with a
different motivation.
The general idea is just to avoid unnecessarily terse code.
> > > +
> > > + /*
> > > + * Move the GPIO clock alternative function bit value to the fourth bit
> > > + * as the corresponding GPIO pin reside. It shall make the generic
> > > + * cp210x GPIO request method being suitable for cp2108 as well.
> > > + */
> >
> > This isn't entirely clear, please try to rephrase.
> >
> > Which functions are available on which pins? Do the function defines
> > need to be renamed to reflect the pin numbers as for CP2104?
>
> I wouldn't rename the macros'es, since they describe the functions of
> enhanced_fxn bits. BTW CP2104 doesn't do any renaming anyway, while it
> is doing the same thing as I am here. Instead I added a more descriptive
> comment, so the code hackers would see the reason of the BITs copy-pasting.
My point was that the corresponding macros for cp2104 includes the pin
number in the name (e.g. CP2104_GPIO1_RXLED_MODE), which makes it clear
on which pin each alternate function is available.
> > > + priv->gpio_altfunc &= ~BIT(3);
> > > + if (priv->gpio_altfunc & CP2108_GPIO_CLOCK_MODE)
> > > + priv->gpio_altfunc |= BIT(3);
> > > +
> > > + /*
> > > + * Open-drain mode in combination with a high latch value is used
> > > + * to emulate the GPIO input pin.
> > > + */
> > > + priv->gpio_input &= ~priv->gpio_pushpull;
> >
> > Input mode should only be set when the reset latch value is 1 (see
> > cp2104).
>
> Yes, and this code does the same thing as the loop in cp2104, but in a single
> line. BTW the cp2104 cp2104_gpioconf_init() method can be simplified in the
> same way.stash@{0}stash@{0}
Not in a single line, you initialised gpio_input to the latch values
several lines above. Please keep the logic in one place, and use
temporaries where appropriate to make the code self-documenting.
I'd prefer a comment here along the lines of those in the other gpio
init functions (e.g. "set input mode iff open-drain and high latch
value").
> It should be also noted that in v2 I fixed a cp2108-related bug in the
> cp210x_gpio_get()/cp210x_gpio_set() methods. So aside from the requested
> alterations the logic of the cp2108 GPIOs setter/getter is bit different
> now.
Ah, guess you had only tested the first port's pins? Possibly another
reason for adding a dedicated cp2108 callback.
I'll comment on the patch itself.
Johan
next prev parent reply other threads:[~2019-06-28 8:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-14 10:53 [PATCH] usb: cp210x: Add cp2108 GPIOs support Serge Semin
2019-06-03 12:52 ` Johan Hovold
2019-06-15 22:56 ` Serge Semin
2019-06-28 8:11 ` Johan Hovold [this message]
2019-06-15 23:02 ` [PATCH v2] " Serge Semin
2019-06-28 8:49 ` Johan Hovold
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=20190628081141.GJ508@localhost \
--to=johan@kernel.org \
--cc=Sergey.Semin@t-platforms.ru \
--cc=fancer.lancer@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.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 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.