From: Tejun Heo <tj@kernel.org>
To: Mark Langsdorf <mark.langsdorf@calxeda.com>
Cc: linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org,
grant.likely@linaro.org, rob.herring@calxeda.com,
devicetree-discuss@lists.ozlabs.org
Subject: Re: [PATCH 2/2] sata highbank: add bit-banged SGPIO driver support
Date: Fri, 31 May 2013 10:17:37 +0900 [thread overview]
Message-ID: <20130531011737.GA29975@mtj.dyndns.org> (raw)
In-Reply-To: <1369945051-2582-2-git-send-email-mark.langsdorf@calxeda.com>
On Thu, May 30, 2013 at 03:17:31PM -0500, Mark Langsdorf wrote:
> +static DEFINE_SPINLOCK(sgpio_lock);
> +#define SCLOCK 0
> +#define SLOAD 1
> +#define SDATA 2
> +static unsigned ecx_sgpio[3];
> +static unsigned long ecx_sgpio_pattern;
> +static int port_to_sgpio[] = { 4, 0, 1, 2, 3};
> +static int n_ports;
Please use more specific names for global constants and variables.
Defining something like n_ports as a global variable is silly and
can lead to silly bugs later on.
> +#define ACTIVITY_BITS 0x300000 // 0x7
> +#define ACTIVITY_SHIFT 2
> +#define LOCATE_BITS 0x80000 // 0x38
> +#define LOCATE_SHIFT 1
> +#define FAULT_BITS 0x400000 // 0x1c0
No //s please and please pick and use a common prefix. It doesn't
have to be long or complete. Even something as short as HB_ is fine.
> +#define FAULT_SHIFT 1
> +#define SGPIO_BIT(port, shift) 1 << (3 * port_to_sgpio[(port)] + \
> + (shift))
Please make it a function.
> +static void ecx_parse_sgpio(u32 port, u32 state)
> +{
> + if (state == 0) {
> + ecx_sgpio_pattern &= ~(SGPIO_BIT(port, ACTIVITY_SHIFT) |
> + SGPIO_BIT(port, LOCATE_SHIFT) |
> + SGPIO_BIT(port, FAULT_SHIFT));
> + return;
> + }
> + if (state & ACTIVITY_BITS)
> + ecx_sgpio_pattern |= SGPIO_BIT(port, ACTIVITY_SHIFT);
> + if (state & LOCATE_BITS)
> + ecx_sgpio_pattern |= SGPIO_BIT(port, LOCATE_SHIFT);
> + if (state & FAULT_BITS)
> + ecx_sgpio_pattern |= SGPIO_BIT(port, FAULT_SHIFT);
> +}
Maybe I'm misunderstanding the code but things are cleared iff @state
is zero? Is that intentional?
....
> +static ssize_t ecx_transmit_led_message(struct ata_port *ap, u32 state,
> + ssize_t size)
> +{
> + struct ahci_host_priv *hpriv = ap->host->private_data;
> + struct ahci_port_priv *pp = ap->private_data;
> + unsigned long flags;
> + int pmp, i;
> + struct ahci_em_priv *emp;
> + u32 sgpio_out;
> +
> + /* get the slot number from the message */
> + pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
> + if (pmp < EM_MAX_SLOTS)
> + emp = &pp->em_priv[pmp];
> + else
> + return -EINVAL;
> +
> + if (!hpriv->em_msg_type & EM_MSG_TYPE_LED)
Huh? This can't be right.
> + return size;
> +
> + spin_lock_irqsave(&sgpio_lock, flags);
> + ecx_parse_sgpio(ap->port_no, state);
> + sgpio_out = ecx_sgpio_pattern;
Hmmm... global data. Can we at least move it into host private data?
> + gpio_set_value(ecx_sgpio[SLOAD], 1);
> + ecx_led_cycle_clock();
> + gpio_set_value(ecx_sgpio[SLOAD], 0);
> + for (i = 0; i < (3 * n_ports); i++) {
> + gpio_set_value(ecx_sgpio[SDATA], sgpio_out & 1);
> + sgpio_out >>= 1;
> + ecx_led_cycle_clock();
> + }
What's the above loop achieving? Care to add a comment?
> +
> + /* save off new led state for port/slot */
> + emp->led_state = state;
> +
> + spin_unlock_irqrestore(&sgpio_lock, flags);
> + return size;
> +}
> +
> +void highbank_set_em_messages(struct device *dev, struct ahci_host_priv *hpriv,
> + struct ata_port_info *pi)
> +{
> + struct device_node *np = dev->of_node;
> + int i;
> + int err;
> +
> + for (i = 0;i < 3; i++) {
Missing space after ; and what's this magic 3 I keep seeing?
> + ecx_sgpio[i] = of_get_named_gpio(np, "calxeda,sgpio-gpio", i);
> + if (IS_ERR_VALUE(ecx_sgpio[i]))
> + return;
> +
> + err = gpio_request(ecx_sgpio[i], "CX SGPIO");
> + if (err) {
> + printk(KERN_ERR
> + "sata_highbank gpio_request %d failed: %d\n",
> + i, err);
> + return;
pr_err()?
> + }
> + gpio_direction_output(ecx_sgpio[i], 1);
> + }
> + /* there's a default ordering, but give it an optional override */
> + for (i = 0; i < n_ports; i++) {
> + of_property_read_u32_array(np, "calxeda,led-order",
> + port_to_sgpio, i);
> + }
{ } unnecessary.
Thanks.
--
tejun
next prev parent reply other threads:[~2013-05-31 1:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-30 20:17 [PATCH 1/2] ahci: make ahci_transmit_led_message into a function pointer Mark Langsdorf
2013-05-30 20:17 ` [PATCH 2/2] sata highbank: add bit-banged SGPIO driver support Mark Langsdorf
2013-05-31 1:17 ` Tejun Heo [this message]
[not found] ` <1369945051-2582-2-git-send-email-mark.langsdorf-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-06-03 13:35 ` [PATCH 2/2 v2] " Mark Langsdorf
2013-06-03 20:37 ` Tejun Heo
2013-06-04 15:09 ` Mark Langsdorf
2013-06-04 20:32 ` Tejun Heo
[not found] ` <20130604203251.GF14916-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-06-05 20:19 ` Mark Langsdorf
2013-06-05 22:31 ` [PATCH 2/2] " Mark Langsdorf
2013-06-05 23:15 ` Tejun Heo
[not found] ` <20130605231517.GP10693-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2013-06-06 12:14 ` Mark Langsdorf
2013-06-06 12:52 ` [PATCH 2/2 v4] " Mark Langsdorf
2013-06-06 21:06 ` Tejun Heo
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=20130531011737.GA29975@mtj.dyndns.org \
--to=tj@kernel.org \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@linaro.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.langsdorf@calxeda.com \
--cc=rob.herring@calxeda.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).