spi: add Intel Mid SSP driver
Subsystems (2)
PATCH 1/2 spi: add Intel Mid SSP driver
From: Fei Yang <[email protected]>
This patch adds driver for ssp spi interface on Intel Mid platform.
--- drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-intel-mid-ssp.c | 1506 +++++++++++++++++++++++++++++++++ include/linux/spi/intel_mid_ssp_spi.h | 330 ++++++++ 4 files changed, 1849 insertions(+) create mode 100644 drivers/spi/spi-intel-mid-ssp.c create mode 100644 include/linux/spi/intel_mid_ssp_spi.h
drivers/spi/Kconfig +12 -0
@@ -211,6 +211,18 @@ config SPI_IMX This enables using the Freescale i.MX SPI controllers in master mode. +config SPI_INTEL_MID_SSP + tristate "SSP SPI controller driver for Intel MID platforms (EXPERIMENTAL)" + depends on X86_INTEL_MID && SPI_MASTER && INTEL_MID_DMAC + help + Select Y or M to build the unified SSP SPI slave controller driver + for the Intel MID platforms (Medfield, Clovertrail and Merrifield), + primarily used to implement a SPI host controller driver over a SSP + host controller. + + If you choose to build this driver as module it will be called + spi-intel-mid-ssp.ko + config SPI_LM70_LLP tristate "Parallel port adapter for LM70 eval board (DEVELOPMENT)" depends on PARPORT
drivers/spi/Makefile +1 -0
@@ -38,6 +38,7 @@ obj-$(CONFIG_SPI_FSL_ESPI) += spi-fsl-espi.o obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o obj-$(CONFIG_SPI_GPIO) += spi-gpio.o obj-$(CONFIG_SPI_IMX) += spi-imx.o +obj-$(CONFIG_SPI_INTEL_MID_SSP) += spi-intel-mid-ssp.o obj-$(CONFIG_SPI_LM70_LLP) += spi-lm70llp.o obj-$(CONFIG_SPI_MPC512x_PSC) += spi-mpc512x-psc.o obj-$(CONFIG_SPI_MPC52xx_PSC) += spi-mpc52xx-psc.o
drivers/spi/spi-intel-mid-ssp.c new file +1506 -0
1,506 lines not on this page · raw message
include/linux/spi/intel_mid_ssp_spi.h new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.8.4.rc3
PATCH 2/2 MAINTAINERS: add Intel MID SSP SPI maintainers
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1916,6 +1916,14 @@ L: [email protected] S: Maintained F: drivers/gpio/gpio-intel-mid.c +INTEL-MID SSP SPI DRIVER +M: Ning Li <[email protected]> +M: David Cohen <[email protected]> +L: [email protected] +S: Maintained +F: drivers/spi/spi-intel-mid-ssp.c +F: include/linux/spi/intel_mid_ssp_spi.h + BTRFS FILE SYSTEM M: Chris Mason <[email protected]> L: [email protected]
Signature · 1 line
1.8.4.rc3
Joe Perches
maintainerRe: [PATCH 2/2] MAINTAINERS: add Intel MID SSP SPI maintainers
On Tue, 2013-10-29 at 11:05 -0700, David Cohen wrote:
[]
MAINTAINERS
Quoted 1 line
MAINTAINERS +0
-0
[]
MAINTAINERS L: [email protected] · line 1917
Quoted 3 lines
MAINTAINERS +0
-0@@ -1916,6 +1916,14 @@ L: [email protected] S: Maintained F: drivers/gpio/gpio-intel-mid.c
Please insert this section in alphabetic order.
MAINTAINERS L: [email protected] · line 1923
Quoted 5 lines
MAINTAINERS +5
-0+INTEL-MID SSP SPI DRIVER +M: Ning Li <[email protected]> +M: David Cohen <[email protected]> +L: [email protected] +S: Maintained
Supported?
Quoted 6 lines
MAINTAINERS +3
-0+F: drivers/spi/spi-intel-mid-ssp.c +F: include/linux/spi/intel_mid_ssp_spi.h + BTRFS FILE SYSTEM M: Chris Mason <[email protected]> L: [email protected]
Re: [PATCH 2/2] MAINTAINERS: add Intel MID SSP SPI maintainers
Quoted 9 lines · Joe Perches
On Tue, 2013-10-29 at 11:05 -0700, David Cohen wrote:
[]MAINTAINERS
Quoted 1 line
MAINTAINERS +0
-0[]
MAINTAINERS L: [email protected] · line 1917
Quoted 3 lines
MAINTAINERS +0
-0@@ -1916,6 +1916,14 @@ L: [email protected] S: Maintained F: drivers/gpio/gpio-intel-mid.cPlease insert this section in alphabetic order.
It supposed to be. But this patch got messed up with another one. I'll fix it.
Quoted 8 lines
MAINTAINERS L: [email protected] · line 1923
Quoted 6 lines
MAINTAINERS +5
-0+INTEL-MID SSP SPI DRIVER +M: Ning Li <[email protected]> +M: David Cohen <[email protected]> +L: [email protected] +S: MaintainedSupported?
Supported from my side but maintained on Ning Li's. But I can change to supported.
Thanks,
David Cohen
Mark Brown
maintainerRe: [PATCH 2/2] MAINTAINERS: add Intel MID SSP SPI maintainers
In reply to David CohenQuoted 1 line · David Cohen
Signed-off-by David Cohen <[email protected]>
Don't send something like this as a separate patch, include it in the main patch.
Joe Perches
maintainerQuoted 1 line · David Cohen
This patch adds driver for ssp spi interface on Intel Mid platform.
A few simple notes:
Please consider using checkpatch.
Quoted 5 lines
--- drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-intel-mid-ssp.c | 1506 +++++++++++++++++++++++++++++++++ include/linux/spi/intel_mid_ssp_spi.h | 330 ++++++++
Shouldn't this include file be in the drivers/spi directory?
[]
drivers/spi/spi-intel-mid-ssp.c
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c +0
-0
[]
drivers/spi/spi-intel-mid-ssp.c line 56
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c +3
-0+#ifdef DUMP_RX +static void dump_trailer (const struct device *dev,char *buf,int len,int sz) +{
You could save a couple of later #ifdefs by
moving the #ifdef inside the function
static void dump_trailer(etc)
{
#ifdef DUMP_RX ...
#endif
}
drivers/spi/spi-intel-mid-ssp.c
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c +2
-0+static int map_dma_buffers (struct ssp_drv_context *sspc) +{
[]
drivers/spi/spi-intel-mid-ssp.c line 622
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c +5
-0+#ifdef DUMP_RX +dump_trailer (&sspc->pdev->dev, sspc->tx, sspc->len,16 ); +#endif +static void int_transfer_complete (struct ssp_drv_context *sspc) +{
[]
drivers/spi/spi-intel-mid-ssp.c line 690
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c +5
-0+#ifdef DUMP_RX +dump_trailer (dev, sspc->rx, sspc->len,16 ); +#endif +static int setup (struct spi_device *spi) +{
[]
drivers/spi/spi-intel-mid-ssp.c line 1040
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c +5
-0+if (!chip) { + chip =kzalloc (sizeof (struct chip_data ),GFP_KERNEL ); +if (!chip) { +dev_err (&spi->dev, +"failed setup: can't allocate chip data\n" );
OOM messages aren't necessary as a generic OOM message is already emitted along with a dump_stack();
Hi Joe,
Quoted 6 lines · Joe Perches
Quoted 1 line · David Cohen
This patch adds driver for ssp spi interface on Intel Mid platform.
A few simple notes:
Please consider using checkpatch.
I did and got no warnings. But haven't used --strict option.
Quoted 8 lines
Quoted 6 lines
--- drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-intel-mid-ssp.c | 1506 +++++++++++++++++++++++++++++++++ include/linux/spi/intel_mid_ssp_spi.h | 330 ++++++++Shouldn't this include file be in the
drivers/spidirectory?
I can't be. This header file will be needed by Intel MID platform code located under arch/x86/platform/intel-mid/ directory.
Quoted 11 lines
[]
drivers/spi/spi-intel-mid-ssp.c
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c +0
-0[]
drivers/spi/spi-intel-mid-ssp.c line 56
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c +3
-0+#ifdef DUMP_RX +static void dump_trailer (const struct device *dev,char *buf,int len,int sz) +{You could save a couple of later #ifdefs by
moving the #ifdef inside the function
I can do that.
Quoted 25 lines
static void
dump_trailer(etc)
{#ifdef DUMP_RX ...#endif
}drivers/spi/spi-intel-mid-ssp.c
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c +2
-0+static int map_dma_buffers (struct ssp_drv_context *sspc) +{[]
drivers/spi/spi-intel-mid-ssp.c line 622
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c +5
-0+#ifdef DUMP_RX +dump_trailer (&sspc->pdev->dev, sspc->tx, sspc->len,16 ); +#endif +static void int_transfer_complete (struct ssp_drv_context *sspc) +{[]
drivers/spi/spi-intel-mid-ssp.c line 690
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c +5
-0+#ifdef DUMP_RX +dump_trailer (dev, sspc->rx, sspc->len,16 ); +#endif +static int setup (struct spi_device *spi) +{[]
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 1040
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c +5
-0+if (!chip) { + chip =kzalloc (sizeof (struct chip_data ),GFP_KERNEL ); +if (!chip) { +dev_err (&spi->dev, +"failed setup: can't allocate chip data\n" );OOM messages aren't necessary as a generic OOM message is already emitted along with a
dump_stack();
So I'll remove the message.
Thanks for your feedback. A new version is coming soon.
Br, David Cohen
Joe Perches
maintainerQuoted 11 lines · David Cohen
Hi Joe,
Quoted 6 lines · Joe Perches
Quoted 1 line · David Cohen
This patch adds driver for ssp spi interface on Intel Mid platform.
A few simple notes:
Please consider using checkpatch.
I did and got no warnings. But haven't used --strict option.
Interesting. I thought there was a return (foo); statement that should have been marked, but I didn't actually run checkpatch.
static inline u32 is_rx_fifo_empty(struct ssp_drv_context *sspc) +{
+ return ((read_SSSR(sspc->ioaddr) & SSSR_RNE) == 0);
+}
This could be bool too
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Joe Perches
Quoted 8 lines · David Cohen
Hi Joe,
Quoted 5 lines · Joe Perches
Quoted 1 line · David Cohen
This patch adds driver for ssp spi interface on Intel Mid platform.
A few simple notes:
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Please consider using checkpatch.
I did and got no warnings. But haven't used --strict option.
Interesting. I thought there was a return (foo); statement that should have been marked, but I didn't actually run checkpatch.
It seems odd checkpatch didn't catch it. I'll investigate.
Quoted 7 lines
static inline u32
is_rx_fifo_empty(struct ssp_drv_context *sspc)drivers/spi/spi-intel-mid-ssp.c new file +3
-0+{ +return ((read_SSSR (sspc->ioaddr) &SSSR_RNE ) ==0 ); +}This could be bool too
u32 seems unusual, but I'd prefer 'int' if it's fine for you.
Br, David
Joe Perches
maintainerQuoted 5 lines · David Cohen
Quoted 4 lines · Joe Perches
Quoted 3 lines · David Cohen
Quoted 2 lines · Joe Perches
Quoted 1 line · David Cohen
This patch adds driver for ssp spi interface on Intel Mid platform.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
A few simple notes:
Please consider using checkpatch.I did and got no warnings. But haven't used --strict option.
Interesting. I thought there was a return (foo); statement that should have been marked, but I didn't actually run checkpatch.
It seems odd checkpatch didn't catch it. I'll investigate.
No need. I believe I know why.
checkpatch doesn't use "$balanced_parens" checks for return tests. I'm not sure it's worth fixing right now, but it could be tested as:
if ($^V && $^V ge 5.10.0 && $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/)
Quoted 6 lines
Quoted 5 lines
static inline u32
is_rx_fifo_empty(struct ssp_drv_context *sspc)drivers/spi/spi-intel-mid-ssp.c new file +3
-0+{ +return ((read_SSSR (sspc->ioaddr) &SSSR_RNE ) ==0 ); +}This could be bool too
u32 seems unusual, but I'd prefer 'int' if it's fine for you.
Anything is_<foo> that returns what seems to be true/false I think could be bool.
But, no worries, it's your code. Do what you think best.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Joe Perches
maintainerPATCH 1/1 checkpatch: Improve "return is not a function" test
Find a few more cases where parentheses are used around the value of a return statement.
This also makes the test depend on perl v5.10 and higher.
--- scripts/checkpatch.pl | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
scripts/checkpatch.pl +4 -14
@@ -3221,21 +3221,10 @@ sub process { } # Return is not a function. - if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) { + if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { my $spacing = $1; - my $value = $2; - - # Flatten any parentheses - $value =~ s/\(/ \(/g; - $value =~ s/\)/\) /g; - while ($value =~ s/\[[^\[\]]*\]/1/ || - $value !~ /(?:$Ident|-?$Constant)\s* - $Compare\s* - (?:$Ident|-?$Constant)/x && - $value =~ s/\([^\(\)]*\)/1/) { - } -#print "value<$value>\n"; - if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) { + if ($^V && $^V ge 5.10.0 && + $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) { ERROR("RETURN_PARENTHESES", "return is not a function, parentheses are not required\n" . $herecurr);
@@ -3244,6 +3233,7 @@ sub process { "space required before the open parenthesis '('\n" . $herecurr); } } + # Return of what appears to be an errno should normally be -'ve if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { my $name = $1;
Joe Perches
maintainerPATCH v2 1/1 checkpatch: Improve "return is not a function" test
In reply to Joe PerchesFind a few more cases where parentheses are used around the value of a return statement.
This now uses the "$balanced_parens" test and also makes the test depend on perl v5.10 and higher.
This now finds return with parenthesis uses the old code did not find like:
ERROR: return is not a function, parentheses are not required #211: FILE: arch/m68k/include/asm/sun3xflop.h:211:
+ return ((error == 0) ? 0 : -1);
---
V2: Add example to commit message.
No change in patch itself.
scripts/checkpatch.pl | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
scripts/checkpatch.pl +4 -14
@@ -3221,21 +3221,10 @@ sub process { } # Return is not a function. - if (defined($stat) && $stat =~ /^.\s*return(\s*)(\(.*);/s) { + if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { my $spacing = $1; - my $value = $2; - - # Flatten any parentheses - $value =~ s/\(/ \(/g; - $value =~ s/\)/\) /g; - while ($value =~ s/\[[^\[\]]*\]/1/ || - $value !~ /(?:$Ident|-?$Constant)\s* - $Compare\s* - (?:$Ident|-?$Constant)/x && - $value =~ s/\([^\(\)]*\)/1/) { - } -#print "value<$value>\n"; - if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) { + if ($^V && $^V ge 5.10.0 && + $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) { ERROR("RETURN_PARENTHESES", "return is not a function, parentheses are not required\n" . $herecurr);
@@ -3244,6 +3233,7 @@ sub process { "space required before the open parenthesis '('\n" . $herecurr); } } + # Return of what appears to be an errno should normally be -'ve if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { my $name = $1;
Re: [PATCH V2] checkpatch: Improve "return is not a function" test
Quoted 13 lines · Joe Perches
Find a few more cases where parentheses are used around the value of a return statement.
This now uses the "$balanced_parens" test and also makes the test depend on perl v5.10 and higher.
This now finds return with parenthesis uses the old code did not find like:
ERROR: return is not a function, parentheses are not required #211: FILE:
arch/m68k/include/asm/sun3xflop.h:211:(quoted diff) +1
-0+ return ((error == 0) ? 0 : -1);
Quoted 1 line
Signed-off-by Joe Perches <[email protected]>
It catches the previous false-negative I had.
Re: [PATCH V2] checkpatch: Improve "return is not a function" test
In reply to Joe PerchesQuoted 2 lines · On Thu, 31 Oct 2013 16:12:44 -0700 Joe Perches <[email protected]> wrote:
This now uses the "$balanced_parens" test and also makes the test depend on perl v5.10 and higher.
What happens if one uses an older perl version? A mysterious-looking splat, I assume?
It would be nicer to have some explicit perl version test which tells user what the problem is, and which perl version is needed?
Joe Perches
maintainerRe: [PATCH V2] checkpatch: Improve "return is not a function" test
Quoted 11 lines · Andrew Morton
Quoted 2 lines · On Thu, 31 Oct 2013 16:12:44 -0700 Joe Perches <[email protected]> wrote:
This now uses the "$balanced_parens" test and also makes the test depend on perl v5.10 and higher.
What happens if one uses an older perl version? A mysterious-looking splat, I assume?
It would be nicer to have some explicit perl version test which tells user what the problem is, and which perl version is needed?
There is such a test already.
You Signed-off on it.
commit d62a201f24cba74e2fbf9f6f7af86ff5f5e276fc
Author: Dave Hansen <[email protected]> Date: Wed Sep 11 14:23:56 2013 -0700
checkpatch: enforce sane perl version
I got a bug report from a couple of users who said checkpatch.pl was broken for them. It was erroring out on fairly random lines most commonly with messages like:
Nested quantifiers in regex; marked by <--HERE in m/(\((?:[^\(\)]++ <-
The bug reporter was running a version of perl 5.8 which was end-of-lifed in 2008: http://www.cpan.org/src/. Versions of perl this old are at _best_ quite untested. At worst, they are crusty and known to be completely broken.
If folks have a system _that_ old, then we should have mercy on them and give them a half-decent error message rather than fail with nutty error messages.
This patch enforces that checkpatch.pl is run with perl 5.10, which was end-of-lifed in 2009. The new --ignore-perl-version command-line switch will let folks override this if they want.
Hi,
Here are a few comments for your next version.
Quoted 21 lines · David Cohen
From: Fei Yang <[email protected]>
This patch adds driver for ssp spi interface on Intel Mid platform.
Signed-off-by Fei Yang <[email protected]>Reviewed-by Ning Li <[email protected]>--- drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-intel-mid-ssp.c | 1506 +++++++++++++++++++++++++++++++++ include/linux/spi/intel_mid_ssp_spi.h | 330 ++++++++ 4 files changed, 1849 insertions(+) create mode 100644 drivers/spi/spi-intel-mid-ssp.c create mode 100644 include/linux/spi/intel_mid_ssp_spi.hdrivers/spi/Kconfig +0
-0
drivers/spi/Kconfig config SPI_IMX · line 220
Quoted 10 lines
drivers/spi/Kconfig +7
-0@@ -211,6 +211,18 @@ config SPI_IMX This enables using the Freescale i.MX SPI controllers in master mode. +config SPI_INTEL_MID_SSP + tristate "SSP SPI controller driver for Intel MID platforms (EXPERIMENTAL)" + depends on X86_INTEL_MID && SPI_MASTER && INTEL_MID_DMAC + help + Select Y or M to build the unified SSP SPI slave controller driver + for the Intel MID platforms (Medfield, Clovertrail and Merrifield), + primarily used to implement a SPI host controller driver over a SSP
I would say:
an SPI an SSP
Quoted 77 lines
drivers/spi/Kconfig +5
-0+ host controller. + + If you choose to build this driver as module it will be called + spi-intel-mid-ssp.ko + config SPI_LM70_LLP tristate "Parallel port adapter for LM70 eval board (DEVELOPMENT)" depends on PARPORTdrivers/spi/Makefile +1
-0@@ -38,6 +38,7 @@ obj-$(CONFIG_SPI_FSL_ESPI) += spi-fsl-espi.o obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o obj-$(CONFIG_SPI_GPIO) += spi-gpio.o obj-$(CONFIG_SPI_IMX) += spi-imx.o +obj-$(CONFIG_SPI_INTEL_MID_SSP) += spi-intel-mid-ssp.o obj-$(CONFIG_SPI_LM70_LLP) += spi-lm70llp.o obj-$(CONFIG_SPI_MPC512x_PSC) += spi-mpc512x-psc.o obj-$(CONFIG_SPI_MPC52xx_PSC) += spi-mpc52xx-psc.odrivers/spi/spi-intel-mid-ssp.c new file +51
-0@@ -0,0 +1,1506 @@ +/* +* spi-intel-mid-ssp.c +* This driver supports Bulverde SSP core used on Intel MID platforms +* It supports SSP of Moorestown & Medfield platforms and handles clock +* slave & master modes. +* +* Copyright (c) 2013, Intel Corporation. +* Contacts: Ning Li <[email protected]> +* David Cohen <david.a.cohen-VuQAYsv1563Yd54FQh9/[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +* +*/ + +/* +* Note: +* +* Supports DMA and non-interrupt polled transfers. +* +*/ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/highmem.h> +#include <linux/pci.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/dma-mapping.h> +#include <linux/intel_mid_dma.h> +#include <linux/pm_qos.h> +#include <linux/pm_runtime.h> +#include <linux/completion.h> +#include <asm/intel-mid.h> + +#include <linux/spi/spi.h> +#include <linux/spi/intel_mid_ssp_spi.h> + +#define DRIVER_NAME "intel_mid_ssp_spi_unified" +
drivers/spi/spi-intel-mid-ssp.c line 61
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+static int ssp_timing_wr; + +#ifdef DUMP_RX +static void dump_trailer (const struct device *dev,char *buf,int len,int sz) +{ +int tlen1 = (len < sz ? len : sz); +int tlen2 = ((len - sz) > sz) ? sz : (len - sz); +unsigned char *p; +static char msg[MAX_SPI_TRANSFER_SIZE ]; +
#include <linux/printk.h>
and try to use print_hex_dump() for this instead of rolling your own...
Quoted 25 lines
drivers/spi/spi-intel-mid-ssp.c new file +25
-0+memset (msg,'\0' ,sizeof (msg)); + p = buf; +while (p < buf + tlen1) +sprintf (msg,"%s%02x" , msg, (unsigned int )*p++); + +if (tlen2 >0 ) { +sprintf (msg,"%s ....." , msg); + p = (buf+len) - tlen2; +while (p < buf + len) +sprintf (msg,"%s%02x" , msg, (unsigned int )*p++); + } + +dev_info (dev,"DUMP: %p[0:%d ... %d:%d]:%s" , buf, tlen1 -1 , + len-tlen2, len - 1, msg); +} +#endif + +static void flush (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr; +u32 i =0 ; + +/* If the transmit fifo is not empty, reset the interface. */ +if (!is_tx_fifo_empty (sspc)) { +dev_err (&sspc->pdev->dev,"TX FIFO not empty. Reset of SPI IF" );
drivers/spi/spi-intel-mid-ssp.c line 148
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+disable_interface (sspc); +return ; + } + +dev_dbg (&sspc->pdev->dev," SSSR=%x\r\n" ,read_SSSR (reg)); +while (!is_rx_fifo_empty (sspc) && (i <SPI_FIFO_SIZE +1 )) { +read_SSDR (reg); + i++; + } +WARN (i >0 ,"%d words flush occured\n" , i);
occurred
drivers/spi/spi-intel-mid-ssp.c line 423
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +7
-0+ +return ; +} + + + +/* set the dma done bit to 1 */
unneeded comment (obvious)
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+ sspc->txdma_done =1 ; + sspc->rxdma_done =1 ; + + sspc->tx_param.drv_context = sspc;
drivers/spi/spi-intel-mid-ssp.c
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+ sspc->tx_param.direction =TX_DIRECTION ; + sspc->rx_param.drv_context = sspc; + sspc->rx_param.direction =RX_DIRECTION ; + + sspc->dma_initialized =1 ; +return ; +/** +* map_dma_buffers() - Map DMA buffer before a transfer +* @sspc: Pointer to the private drivzer context
driver
drivers/spi/spi-intel-mid-ssp.c line 701
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+static void poll_transfer_complete (struct ssp_drv_context *sspc) +{ +struct spi_message *msg; + +/* Update total byte transfered return count actual bytes read */
transferred;
drivers/spi/spi-intel-mid-ssp.c line 714
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +13
-0+ sspc->cur_msg->actual_length += sspc->len - (sspc->rx_end - sspc->rx); + + sspc->cur_msg->status =0 ; + msg = sspc->cur_msg; +if (likely (msg->complete)) + msg->complete (msg->context); +complete (&sspc->msg_done); +} + +/** +* ssp_int() - Interrupt handler +* @irq +* @dev_id
Please finish the kernel-doc notation (or drop it).
Quoted 5 lines
+ *
+ * The SSP interrupt is not used for transfer which are handled by
+ * DMA or polling: only under/over run are catched to detect
+ * broken transfers.
+ */
drivers/spi/spi-intel-mid-ssp.c line 728
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static irqreturn_t ssp_int (int irq,void *dev_id) +{ +struct ssp_drv_context *sspc = dev_id; +void *reg = sspc->ioaddr; +struct device *dev = &sspc->pdev->dev; +u32 status =read_SSSR (reg); + +/* It should never be our interrupt since SSP will */ +/* only trigs interrupt for under/over run. */
trigger
Quoted 56 lines
drivers/spi/spi-intel-mid-ssp.c new file +22
-0+if (likely (!(status & sspc->mask_sr))) +return IRQ_NONE ; + +if (status &SSSR_ROR || status &SSSR_TUR ) { +dev_err (dev,"--- SPI ROR or TUR occurred : SSSR=%x\n" , status); +WARN_ON (1 ); +if (status &SSSR_ROR ) +dev_err (dev,"we have Overrun\n" ); +if (status &SSSR_TUR ) +dev_err (dev,"we have Underrun\n" ); + } + +/* We can fall here when not using DMA mode */ +if (!sspc->cur_msg) { +disable_interface (sspc); +disable_triggers (sspc); + } +/* clear status register */ +write_SSSR (sspc->clear_sr, reg); +return IRQ_HANDLED ; +} +include/linux/spi/intel_mid_ssp_spi.h new file +26
-0@@ -0,0 +1,330 @@ +/* +* Copyright (C) Intel 2013 +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +*/ +#ifndef INTEL_MID_SSP_SPI_H_ +#define INTEL_MID_SSP_SPI_H_ + +#include <linux/completion.h>
include/linux/spi/intel_mid_ssp_spi.h
Quoted 10 lines
include/linux/spi/intel_mid_ssp_spi.h new file +9
-0+#include <linux/intel_mid_dma.h> +#include <linux/interrupt.h> +#include <linux/pm_qos.h> +#include <linux/spi/spi.h> + +#define SSCR0_DSS (0x0000000f)/* Data Size Select (mask) */ +#define SSCR0_DataSize (x) ((x) - 1)/* Data Size Select [4..16] */ +#define SSCR0_FRF (0x00000030)/* FRame Format (mask) */ +#define SSCR0_Motorola (0x0 << 4)/* Motorola's SPI mode */
#include <linux/bitops.h>
Quoted 1 line
+#define
SSCR0_ECS(1 << 6) /* External clock select */
#define SSCR0_ECS BIT(6) /* External clock select */
etc.
Quoted 73 lines
include/linux/spi/intel_mid_ssp_spi.h new file +73
-0+#define SSCR0_SSE (1 << 7)/* Synchronous Serial Port Enable */ + +#define SSCR0_SCR (0x000fff00)/* Serial Clock Rate (mask) */ +#define SSCR0_SerClkDiv (x) (((x) - 1) << 8)/* Divisor [1..4096] */ +#define SSCR0_EDSS (1 << 20)/* Extended data size select */ +#define SSCR0_NCS (1 << 21)/* Network clock select */ +#define SSCR0_RIM (1 << 22)/* Receive FIFO overrrun int mask */ +#define SSCR0_TUM (1 << 23)/* Transmit FIFO underrun int mask */ +#define SSCR0_FRDC (0x07000000)/* Frame rate divider control (mask) */ +#define SSCR0_SlotsPerFrm (x) (((x) - 1) << 24)/* Time slots per frame */ +#define SSCR0_ADC (1 << 30)/* Audio clock select */ +#define SSCR0_MOD (1 << 31)/* Mode (normal or network) */ + +#define SSCR1_RIE (1 << 0)/* Receive FIFO Interrupt Enable */ +#define SSCR1_TIE (1 << 1)/* Transmit FIFO Interrupt Enable */ +#define SSCR1_LBM (1 << 2)/* Loop-Back Mode */ +#define SSCR1_SPO (1 << 3)/* SSPSCLK polarity setting */ +#define SSCR1_SPH (1 << 4)/* Motorola SPI SSPSCLK phase setting */ +#define SSCR1_MWDS (1 << 5)/* Microwire Transmit Data Size */ +#define SSCR1_TFT (0x000003c0)/* Transmit FIFO Threshold (mask) */ +#define SSCR1_TxTresh (x) (((x) - 1) << 6)/* level [1..16] */ +#define SSCR1_RFT (0x00003c00)/* Receive FIFO Threshold (mask) */ +#define SSCR1_RxTresh (x) (((x) - 1) << 10)/* level [1..16] */ + +#define SSSR_TNF (1 << 2)/* Tx FIFO Not Full */ +#define SSSR_RNE (1 << 3)/* Rx FIFO Not Empty */ +#define SSSR_BSY (1 << 4)/* SSP Busy */ +#define SSSR_TFS (1 << 5)/* Tx FIFO Service Request */ +#define SSSR_RFS (1 << 6)/* Rx FIFO Service Request */ +#define SSSR_ROR (1 << 7)/* Rx FIFO Overrun */ +#define SSSR_TFL_MASK (0x0f << 8)/* Tx FIFO level field mask */ + +#define SSCR0_TIM (1 << 23)/* Transmit FIFO Under Run Int Mask */ +#define SSCR0_RIM (1 << 22)/* Receive FIFO Over Run int Mask */ +#define SSCR0_NCS (1 << 21)/* Network Clock Select */ +#define SSCR0_EDSS (1 << 20)/* Extended Data Size Select */ + +#define SSCR0_TISSP (1 << 4)/* TI Sync Serial Protocol */ +#define SSCR0_PSP (3 << 4)/* PSP - Programmable Serial Protocol */ +#define SSCR1_TTELP (1 << 31)/* TXD Tristate Enable Last Phase */ +#define SSCR1_TTE (1 << 30)/* TXD Tristate Enable */ +#define SSCR1_EBCEI (1 << 29)/* Enable Bit Count Error interrupt */ +#define SSCR1_SCFR (1 << 28)/* Slave Clock free Running */ +#define SSCR1_ECRA (1 << 27)/* Enable Clock Request A */ +#define SSCR1_ECRB (1 << 26)/* Enable Clock request B */ +#define SSCR1_SCLKDIR (1 << 25)/* Serial Bit Rate Clock Direction */ +#define SSCR1_SFRMDIR (1 << 24)/* Frame Direction */ +#define SSCR1_RWOT (1 << 23)/* Receive Without Transmit */ +#define SSCR1_TRAIL (1 << 22)/* Trailing Byte */ +#define SSCR1_TSRE (1 << 21)/* Transmit Service Request Enable */ +#define SSCR1_RSRE (1 << 20)/* Receive Service Request Enable */ +#define SSCR1_TINTE (1 << 19)/* Receiver Time-out Interrupt enable */ +#define SSCR1_PINTE (1 << 18)/* Trailing Byte Interupt Enable */ +#define SSCR1_STRF (1 << 15)/* Select FIFO or EFWR */ +#define SSCR1_EFWR (1 << 14)/* Enable FIFO Write/Read */ +#define SSCR1_IFS (1 << 16)/* Invert Frame Signal */ + +#define SSSR_BCE (1 << 23)/* Bit Count Error */ +#define SSSR_CSS (1 << 22)/* Clock Synchronisation Status */ +#define SSSR_TUR (1 << 21)/* Transmit FIFO Under Run */ +#define SSSR_EOC (1 << 20)/* End Of Chain */ +#define SSSR_TINT (1 << 19)/* Receiver Time-out Interrupt */ +#define SSSR_PINT (1 << 18)/* Peripheral Trailing Byte Interrupt */ + +#define SSPSP_FSRT (1 << 25)/* Frame Sync Relative Timing */ +#define SSPSP_DMYSTOP (x) ((x) << 23)/* Dummy Stop */ +#define SSPSP_SFRMWDTH (x)((x) << 16)/* Serial Frame Width */ +#define SSPSP_SFRMDLY (x) ((x) << 9)/* Serial Frame Delay */ +#define SSPSP_DMYSTRT (x) ((x) << 7)/* Dummy Start */ +#define SSPSP_STRTDLY (x) ((x) << 4)/* Start Delay */ +#define SSPSP_ETDS (1 << 3)/* End of Transfer data State */ +#define SSPSP_SFRMP (1 << 2)/* Serial Frame Polarity */ +#define SSPSP_SCMODE (x) ((x) << 0)/* Serial Bit Rate Clock Mode */
Signature · 5 lines
~Randy -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Randy,
Quoted 2 lines · Randy Dunlap
Hi,
Here are a few comments for your next version.
Ack for all of your comments. I'll consider them on next version.
Br, David Cohen
Hi,
Quoted 48 lines · David Cohen
drivers/spi/spi-intel-mid-ssp.c new file +42
-0@@ -0,0 +1,1506 @@ +/* +* spi-intel-mid-ssp.c +* This driver supports Bulverde SSP core used on Intel MID platforms +* It supports SSP of Moorestown & Medfield platforms and handles clock +* slave & master modes. +* +* Copyright (c) 2013, Intel Corporation. +* Contacts: Ning Li <[email protected]> +* David Cohen <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +* +*/ + +/* +* Note: +* +* Supports DMA and non-interrupt polled transfers. +* +*/ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/highmem.h> +#include <linux/pci.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/dma-mapping.h> +#include <linux/intel_mid_dma.h> +#include <linux/pm_qos.h>
drivers/spi/spi-intel-mid-ssp.c line 52
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+#include <linux/pm_runtime.h> +#include <linux/completion.h> +#include <asm/intel-mid.h> + +#include <linux/spi/spi.h> +#include <linux/spi/intel_mid_ssp_spi.h> + +#define DRIVER_NAME "intel_mid_ssp_spi_unified" + +static int ssp_timing_wr;
this will prevent multiple instances of the same driver.
Quoted 14 lines
drivers/spi/spi-intel-mid-ssp.c new file +14
-0+#ifdef DUMP_RX +static void dump_trailer (const struct device *dev,char *buf,int len,int sz) +{ +int tlen1 = (len < sz ? len : sz); +int tlen2 = ((len - sz) > sz) ? sz : (len - sz); +unsigned char *p; +static char msg[MAX_SPI_TRANSFER_SIZE ]; + +memset (msg,'\0' ,sizeof (msg)); + p = buf; +while (p < buf + tlen1) +sprintf (msg,"%s%02x" , msg, (unsigned int )*p++); + +if (tlen2 >0 ) {
drivers/spi/spi-intel-mid-ssp.c line 77
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+sprintf (msg,"%s ....." , msg); + p = (buf+len) - tlen2; +while (p < buf + len) + sprintf(msg, "%s%02x", msg, (unsigned int)*p++); + } + +dev_info (dev,"DUMP: %p[0:%d ... %d:%d]:%s" , buf, tlen1 -1 , + len-tlen2, len -1 , msg); +} +#endif
either move this to debugfs or stub the function out ifndef DUMP_RX, then you don't need the ifdefs when calling it.
drivers/spi/spi-intel-mid-ssp.c line 81
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u8 ssp_cfg_get_mode (u8 ssp_cfg) +{ +if (intel_mid_identify_cpu () ==INTEL_MID_CPU_CHIP_TANGIER )
instead, couldn't you use driver data to pass some flags to the driver ? I can't see intel_mid_identify_cpu and having drivers depend on arch-specific code is usually a bad practice.
drivers/spi/spi-intel-mid-ssp.c line 81
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+return (ssp_cfg) &0x03 ; + else
else isn't needed here
drivers/spi/spi-intel-mid-ssp.c line 105
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u32 is_tx_fifo_empty (struct ssp_drv_context *sspc) +{ +u32 sssr;
blank line here would aid readability
drivers/spi/spi-intel-mid-ssp.c line 109
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+ sssr =read_SSSR (sspc->ioaddr); +if ((sssr &SSSR_TFL_MASK ) || (sssr &SSSR_TNF ) ==0 ) +return 0 ; +else
else isn't necessary
drivers/spi/spi-intel-mid-ssp.c line 115
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u32 is_rx_fifo_empty (struct ssp_drv_context *sspc) +{ +return ((read_SSSR (sspc->ioaddr) &SSSR_RNE ) ==0 );
you don't need the outter parenthesis here, GCC should've warned you, even.
drivers/spi/spi-intel-mid-ssp.c line 120
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline void disable_interface (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;
blank line here
drivers/spi/spi-intel-mid-ssp.c line 126
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+write_SSCR0 (read_SSCR0 (reg) & ~SSCR0_SSE , reg); +} + +static inline void disable_triggers (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;
and here...
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+write_SSCR1 (read_SSCR1 (reg) & ~sspc->cr1_sig, reg); +} + + +static void flush (struct ssp_drv_context *sspc)
drivers/spi/spi-intel-mid-ssp.c line 141
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+{ +void *reg = sspc->ioaddr; +u32 i =0 ; + +/* If the transmit fifo is not empty, reset the interface. */ +if (!is_tx_fifo_empty (sspc)) { +dev_err (&sspc->pdev->dev,"TX FIFO not empty. Reset of SPI IF" ); +disable_interface (sspc); +return ; + }
not so sure, if the transmit fifo isn't empty and you reset it, you could end up corrupting data which is about to be shifted into the wire, couldn't you ?
Is this a case which would *really* happen in normal conditions ? If so, why ?
drivers/spi/spi-intel-mid-ssp.c line 148
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+dev_dbg (&sspc->pdev->dev," SSSR=%x\r\n" ,read_SSSR (reg)); +while (!is_rx_fifo_empty (sspc) && (i <SPI_FIFO_SIZE +1 )) { +read_SSDR (reg); + i++; + } +WARN (i >0 ,"%d words flush occured\n" , i);
similarly, you could be ignoring data you *should* indeed be handling.
drivers/spi/spi-intel-mid-ssp.c line 123
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+ +return ;
return statement is unnecessary.
drivers/spi/spi-intel-mid-ssp.c line 153
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+static int null_writer (struct ssp_drv_context *sspc)
looks like these two functions (null_\(writer\|reader\)) need some documentation. Why do they exist ?
drivers/spi/spi-intel-mid-ssp.c line 184
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static int u8_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;
blank line
drivers/spi/spi-intel-mid-ssp.c line 197
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +13
-0+if (((read_SSSR (reg) &SSSR_TFL_MASK ) ==SSSR_TFL_MASK ) + || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u8 *)(sspc->tx), reg); + ++sspc->tx; + +return 1 ; +} + +static int u8_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;
blank line
drivers/spi/spi-intel-mid-ssp.c line 209
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+while ((read_SSSR (reg) &SSSR_RNE ) + && (sspc->rx < sspc->rx_end)) { + *(u8 *)(sspc->rx) =read_SSDR (reg); + ++sspc->rx; + } + +return sspc->rx == sspc->rx_end; +} + +static int u16_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;
blank line
drivers/spi/spi-intel-mid-ssp.c line 153
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
the extra comparisson here is superfluous.
drivers/spi/spi-intel-mid-ssp.c line 222
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+ || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u16 *)(sspc->tx), reg); + sspc->tx +=2 ; + +return 1 ; +} + +static int u16_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;
blank line
drivers/spi/spi-intel-mid-ssp.c line 233
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c new file +11
-0+while ((read_SSSR (reg) &SSSR_RNE ) && (sspc->rx < sspc->rx_end)) { + *(u16 *)(sspc->rx) =read_SSDR (reg); + sspc->rx +=2 ; + } + +return sspc->rx == sspc->rx_end; +} + +static int u32_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;
blank line
drivers/spi/spi-intel-mid-ssp.c line 177
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
the extra comparisson here is superfluous.
drivers/spi/spi-intel-mid-ssp.c line 246
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+ || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u32 *)(sspc->tx), reg); + sspc->tx +=4 ; + +return 1 ; +} + +static int u32_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;
blank line
Quoted 18 lines
drivers/spi/spi-intel-mid-ssp.c new file +18
-0+while ((read_SSSR (reg) &SSSR_RNE ) && (sspc->rx < sspc->rx_end)) { + *(u32 *)(sspc->rx) =read_SSDR (reg); + sspc->rx +=4 ; + } + +return sspc->rx == sspc->rx_end; +} + +static bool chan_filter (struct dma_chan *chan,void *param) +{ +struct ssp_drv_context *sspc = param; + +if (sspc->dmac1 && chan->device->dev == &sspc->dmac1->dev) +return true; + +return false; +} +
drivers/spi/spi-intel-mid-ssp.c line 274
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+/** +* unmap_dma_buffers() - Unmap the DMA buffers used during the last transfer. +* @sspc: Pointer to the private driver context +*/ +static void unmap_dma_buffers (struct ssp_drv_context *sspc) +{ +struct device *dev = &sspc->pdev->dev; + +if (!sspc->dma_mapped) +return ;
blank line
drivers/spi/spi-intel-mid-ssp.c line 277
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+dma_unmap_single (dev, sspc->rx_dma, sspc->len,PCI_DMA_FROMDEVICE ); +dma_unmap_single (dev, sspc->tx_dma, sspc->len,PCI_DMA_TODEVICE ); + sspc->dma_mapped =0 ;
you shouldn't need this dma_mapped flag here...
Quoted 15 lines
drivers/spi/spi-intel-mid-ssp.c new file +15
-0+static void ssp_spi_dma_done (void *arg) +{ +struct callback_param *cb_param = (struct callback_param *)arg; +struct ssp_drv_context *sspc = cb_param->drv_context; +struct device *dev = &sspc->pdev->dev; +void *reg = sspc->ioaddr; + +if (cb_param->direction ==TX_DIRECTION ) + sspc->txdma_done =1 ; +else + sspc->rxdma_done =1 ; + +dev_dbg (dev,"DMA callback for direction %d [RX done:%d] [TX done:%d]\n" , + cb_param->direction, sspc->rxdma_done, + sspc->txdma_done);
drivers/spi/spi-intel-mid-ssp.c line 313
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+ +if (sspc->txdma_done && sspc->rxdma_done) { +/* Clear Status Register */ +write_SSSR (sspc->clear_sr, reg); +dev_dbg (dev,"DMA done\n" ); +/* Disable Triggers to DMA or to CPU*/ +disable_triggers (sspc); +unmap_dma_buffers (sspc); + +queue_work (sspc->dma_wq, &sspc->complete_work);
I fail to see the need for this workstruct, why can't you call complete() directly ?
drivers/spi/spi-intel-mid-ssp.c line 728
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static irqreturn_t ssp_int (int irq,void *dev_id) +{ +struct ssp_drv_context *sspc = dev_id; +void *reg = sspc->ioaddr; +struct device *dev = &sspc->pdev->dev; +u32 status =read_SSSR (reg); + +/* It should never be our interrupt since SSP will */ +/* only trigs interrupt for under/over run. */
wrong comment style
drivers/spi/spi-intel-mid-ssp.c line 739
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c new file +11
-0+if (likely (!(status & sspc->mask_sr))) +return IRQ_NONE ; + +if (status &SSSR_ROR || status &SSSR_TUR ) { +dev_err (dev,"--- SPI ROR or TUR occurred : SSSR=%x\n" , status); +WARN_ON (1 ); +if (status &SSSR_ROR ) +dev_err (dev,"we have Overrun\n" ); +if (status &SSSR_TUR ) +dev_err (dev,"we have Underrun\n" ); + }
I would split these two caes here:
if (status & ROR)
dev_WARN(dev, "Overrun\n");
if (status & TUR)
dev_WARN(dev, "Underrun\n");
no need for nested ifs.
drivers/spi/spi-intel-mid-ssp.c line 763
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +13
-0+static void poll_transfer (unsigned long data) +{ +struct ssp_drv_context *sspc = (void *)data; + +if (sspc->tx) { +while (sspc->tx != sspc->tx_end) { +if (ssp_timing_wr) { +int timeout =100 ; +/* It is used as debug UART on Tangier. Since +baud rate = 115200, it needs at least 312us +for one word transferring. Becuase of silicon +issue, it MUST check SFIFOL here instead of +TNF. It is the workaround for A0 stepping*/
wrong comment style.
drivers/spi/spi-intel-mid-ssp.c line 771
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c new file +8
-0+while (--timeout && + ((read_SFIFOL (sspc->ioaddr)) &0xFFFF )) +udelay (10 ); + } + sspc->write (sspc); + sspc->read (sspc); + } + }
you can make this look sligthly better if you:
if (!sspc->tx)
bail();
while (sspc->tx != sspc->tx_end) {
if (sspc->timing_wr) {
int timeout = 100;
....
}
}it'll decrease one indentation level.
drivers/spi/spi-intel-mid-ssp.c line 786
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+static void start_bitbanging (struct ssp_drv_context *sspc)
I would prefix with ssp_
drivers/spi/spi-intel-mid-ssp.c line 889
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +13
-0+static int handle_message (struct ssp_drv_context *sspc) +{ +struct chip_data *chip =NULL ; +struct spi_transfer *transfer =NULL ; +void *reg = sspc->ioaddr; +u32 cr1; +struct device *dev = &sspc->pdev->dev; +struct spi_message *msg = sspc->cur_msg; + + chip =spi_get_ctldata (msg->spi); + +/* We handle only one transfer message since the protocol module has to +control the out of band signaling. */
wrong comment style.
Quoted 37 lines
drivers/spi/spi-intel-mid-ssp.c new file +37
-0+ transfer = list_entry(msg->transfers.next, struct spi_transfer, + transfer_list); + +/* Check transfer length */ +if (unlikely ((transfer->len >MAX_SPI_TRANSFER_SIZE ) || + (transfer->len ==0 ))) { +dev_warn (dev,"transfer length null or greater than %d\n" , +MAX_SPI_TRANSFER_SIZE ); +dev_warn (dev,"length = %d\n" , transfer->len); + msg->status = -EINVAL ; + +if (msg->complete) + msg->complete (msg->context); +complete (&sspc->msg_done); +return 0 ; + } + +/* Flush any remaining data (in case of failed previous transfer) */ +flush (sspc); + + sspc->tx = (void *)transfer->tx_buf; + sspc->rx = (void *)transfer->rx_buf; + sspc->len = transfer->len; + sspc->write = chip->write; + sspc->read = chip->read; + +if (likely (chip->dma_enabled)) { + sspc->dma_mapped =map_dma_buffers (sspc); +if (unlikely (!sspc->dma_mapped)) +return 0 ; + }else { + sspc->write = sspc->tx ? chip->write : null_writer; + sspc->read = sspc->rx ? chip->read : null_reader; + } + sspc->tx_end = sspc->tx + transfer->len; + sspc->rx_end = sspc->rx + transfer->len; +write_SSSR (sspc->clear_sr, reg);
drivers/spi/spi-intel-mid-ssp.c line 936
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+ +/* setup the CR1 control register */ + cr1 = chip->cr1 | sspc->cr1_sig; + +if (likely (sspc->quirks &QUIRKS_DMA_USE_NO_TRAIL )) { +/* in case of len smaller than burst size, adjust the RX */ +/* threshold. All other cases will use the default threshold */ +/* value. The RX fifo threshold must be aligned with the DMA */ +/* RX transfer size, which may be limited to a multiple of 4 */ +/* bytes due to 32bits DDR access. */
wrong comment style
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +7
-0+static int ssp_spi_probe (struct pci_dev *pdev, +const struct pci_device_id *ent) +{ +struct device *dev = &pdev->dev; +struct spi_master *master; +struct ssp_drv_context *sspc =0 ; +int status;
drivers/spi/spi-intel-mid-ssp.c line 1196
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+u32 iolen =0 ; +u8 ssp_cfg; +int pos; +void __iomem *syscfg_ioaddr; +unsigned long syscfg; + +/* Check if the SSP we are probed for has been allocated */ +/* to operate as SPI. This information is retreived from */ +/* the field adid of the Vendor-Specific PCI capability */ +/* which is used as a configuration register. */
wrong comment style
drivers/spi/spi-intel-mid-ssp.c line 1442
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static int ssp_spi_runtime_suspend (struct device *dev) +{ +return 0 ; +} + +static int ssp_spi_runtime_resume (struct device *dev) +{ +return 0 ; +}
why even add these if they're no-ops ?
drivers/spi/spi-intel-mid-ssp.c line 1495
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+static int __init ssp_spi_init (void ) +{ +return pci_register_driver (&ssp_spi_driver); +} + +late_initcall (ssp_spi_init);
does it have to be late ? Can't you just use module_pci_driver() instead ?
drivers/spi/spi-intel-mid-ssp.c line 9
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0@@ -0,0 +1,330 @@ +/* +* Copyright (C) Intel 2013 +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version.
companies usually don't like this "at your option any later version" statement. Usually it's GPL2 only...
Signature · 1 line
balbi
Hi Felipe,
Quoted 55 lines · Felipe Balbi
Hi,
Quoted 52 lines · David Cohen
drivers/spi/spi-intel-mid-ssp.c new file +46
-0@@ -0,0 +1,1506 @@ +/* +* spi-intel-mid-ssp.c +* This driver supports Bulverde SSP core used on Intel MID platforms +* It supports SSP of Moorestown & Medfield platforms and handles clock +* slave & master modes. +* +* Copyright (c) 2013, Intel Corporation. +* Contacts: Ning Li <[email protected]> +* David Cohen <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +* +*/ + +/* +* Note: +* +* Supports DMA and non-interrupt polled transfers. +* +*/ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/highmem.h> +#include <linux/pci.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/dma-mapping.h> +#include <linux/intel_mid_dma.h> +#include <linux/pm_qos.h> +#include <linux/pm_runtime.h> +#include <linux/completion.h> +#include <asm/intel-mid.h> +
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 52
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+#include <linux/spi/spi.h> +#include <linux/spi/intel_mid_ssp_spi.h> + +#define DRIVER_NAME "intel_mid_ssp_spi_unified" + +static int ssp_timing_wr;this will prevent multiple instances of the same driver.
Yeah. I'll fix it.
Quoted 20 lines
Quoted 20 lines
drivers/spi/spi-intel-mid-ssp.c new file +19
-0+#ifdef DUMP_RX +static void dump_trailer (const struct device *dev,char *buf,int len,int sz) +{ +int tlen1 = (len < sz ? len : sz); +int tlen2 = ((len - sz) > sz) ? sz : (len - sz); +unsigned char *p; +static char msg[MAX_SPI_TRANSFER_SIZE ]; + +memset (msg,'\0' ,sizeof (msg)); + p = buf; +while (p < buf + tlen1) +sprintf (msg,"%s%02x" , msg, (unsigned int )*p++); + +if (tlen2 >0 ) { +sprintf (msg,"%s ....." , msg); + p = (buf+len) - tlen2; +while (p < buf + len) +sprintf (msg,"%s%02x" , msg, (unsigned int )*p++); + }
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 77
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+ +dev_info (dev,"DUMP: %p[0:%d ... %d:%d]:%s" , buf, tlen1 -1 , + len-tlen2, len - 1, msg); +} +#endif either move this to debugfs or stub the function out ifndef
DUMP_RX, then you don't need the ifdefs when calling it.
Agreed.
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 81
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u8 ssp_cfg_get_mode (u8 ssp_cfg) +{ +if (intel_mid_identify_cpu () ==INTEL_MID_CPU_CHIP_TANGIER )instead, couldn't you use driver data to pass some flags to the driver ? I can't see
intel_mid_identify_cpuand having drivers depend on arch-specific code is usually a bad practice.
I'll find a way to get rid of this.
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c line 81
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+return (ssp_cfg) &0x03 ; + elseelse isn't needed here
Agreed.
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c line 105
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u32 is_tx_fifo_empty (struct ssp_drv_context *sspc) +{ +u32 sssr;blank line here would aid readability
Agreed.
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c line 109
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+ sssr =read_SSSR (sspc->ioaddr); +if ((sssr &SSSR_TFL_MASK ) || (sssr &SSSR_TNF ) ==0 ) +return 0 ; +else else isn't necessary
Agreed.
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c line 115
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u32 is_rx_fifo_empty (struct ssp_drv_context *sspc) +{ +return ((read_SSSR (sspc->ioaddr) &SSSR_RNE ) ==0 );you don't need the outter parenthesis here, GCC should've warned you, even.
Yeah. checkpatch supposed to warn too. I'll fix it.
Quoted 36 lines
drivers/spi/spi-intel-mid-ssp.c line 120
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline void disable_interface (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line here
drivers/spi/spi-intel-mid-ssp.c line 126
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+write_SSCR0 (read_SSCR0 (reg) & ~SSCR0_SSE , reg); +} + +static inline void disable_triggers (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;and here...
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+write_SSCR1 (read_SSCR1 (reg) & ~sspc->cr1_sig, reg); +} + + +static void flush (struct ssp_drv_context *sspc)drivers/spi/spi-intel-mid-ssp.c line 141
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+{ +void *reg = sspc->ioaddr; +u32 i =0 ; + +/* If the transmit fifo is not empty, reset the interface. */ +if (!is_tx_fifo_empty (sspc)) { +dev_err (&sspc->pdev->dev,"TX FIFO not empty. Reset of SPI IF" ); +disable_interface (sspc); +return ; + }not so sure, if the transmit fifo isn't empty and you reset it, you could end up corrupting data which is about to be shifted into the wire, couldn't you ?
Quoted 2 lines
Is this a case which would *really* happen in normal conditions ? If so, why ?
I'll leave this question to Ning.
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c line 148
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+dev_dbg (&sspc->pdev->dev," SSSR=%x\r\n" ,read_SSSR (reg)); +while (!is_rx_fifo_empty (sspc) && (i <SPI_FIFO_SIZE +1 )) { +read_SSDR (reg); + i++; + } +WARN (i >0 ,"%d words flush occured\n" , i);similarly, you could be ignoring data you *should* indeed be handling.
That seems the case, yes.
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c line 123
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+ +return ;return statement is unnecessary.
Agreed.
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c line 153
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+static int null_writer (struct ssp_drv_context *sspc)looks like these two functions (null_\(writer\|reader\)) need some documentation. Why do they exist ?
I'll make sure next version has comments for it.
Quoted 38 lines
drivers/spi/spi-intel-mid-ssp.c line 184
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static int u8_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
drivers/spi/spi-intel-mid-ssp.c line 197
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +13
-0+if (((read_SSSR (reg) &SSSR_TFL_MASK ) ==SSSR_TFL_MASK ) + || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u8 *)(sspc->tx), reg); + ++sspc->tx; + +return 1 ; +} + +static int u8_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
drivers/spi/spi-intel-mid-ssp.c line 209
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+while ((read_SSSR (reg) &SSSR_RNE ) + && (sspc->rx < sspc->rx_end)) { + *(u8 *)(sspc->rx) =read_SSDR (reg); + ++sspc->rx; + } + +return sspc->rx == sspc->rx_end; +} + +static int u16_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c line 153
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)the extra comparisson here is superfluous.
Agreed.
Quoted 30 lines
drivers/spi/spi-intel-mid-ssp.c line 222
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+ || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u16 *)(sspc->tx), reg); + sspc->tx +=2 ; + +return 1 ; +} + +static int u16_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
drivers/spi/spi-intel-mid-ssp.c line 233
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c new file +11
-0+while ((read_SSSR (reg) &SSSR_RNE ) && (sspc->rx < sspc->rx_end)) { + *(u16 *)(sspc->rx) =read_SSDR (reg); + sspc->rx +=2 ; + } + +return sspc->rx == sspc->rx_end; +} + +static int u32_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c line 177
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)the extra comparisson here is superfluous.
Agreed.
Quoted 82 lines
drivers/spi/spi-intel-mid-ssp.c line 246
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+ || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u32 *)(sspc->tx), reg); + sspc->tx +=4 ; + +return 1 ; +} + +static int u32_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
Quoted 18 lines
drivers/spi/spi-intel-mid-ssp.c new file +18
-0+while ((read_SSSR (reg) &SSSR_RNE ) && (sspc->rx < sspc->rx_end)) { + *(u32 *)(sspc->rx) =read_SSDR (reg); + sspc->rx +=4 ; + } + +return sspc->rx == sspc->rx_end; +} + +static bool chan_filter (struct dma_chan *chan,void *param) +{ +struct ssp_drv_context *sspc = param; + +if (sspc->dmac1 && chan->device->dev == &sspc->dmac1->dev) +return true; + +return false; +} +drivers/spi/spi-intel-mid-ssp.c line 274
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+/** +* unmap_dma_buffers() - Unmap the DMA buffers used during the last transfer. +* @sspc: Pointer to the private driver context +*/ +static void unmap_dma_buffers (struct ssp_drv_context *sspc) +{ +struct device *dev = &sspc->pdev->dev; + +if (!sspc->dma_mapped) +return ;blank line
drivers/spi/spi-intel-mid-ssp.c line 277
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+dma_unmap_single (dev, sspc->rx_dma, sspc->len,PCI_DMA_FROMDEVICE ); +dma_unmap_single (dev, sspc->tx_dma, sspc->len,PCI_DMA_TODEVICE ); + sspc->dma_mapped =0 ;you shouldn't need this
dma_mappedflag here...Quoted 15 lines
drivers/spi/spi-intel-mid-ssp.c new file +15
-0+static void ssp_spi_dma_done (void *arg) +{ +struct callback_param *cb_param = (struct callback_param *)arg; +struct ssp_drv_context *sspc = cb_param->drv_context; +struct device *dev = &sspc->pdev->dev; +void *reg = sspc->ioaddr; + +if (cb_param->direction ==TX_DIRECTION ) + sspc->txdma_done =1 ; +else + sspc->rxdma_done =1 ; + +dev_dbg (dev,"DMA callback for direction %d [RX done:%d] [TX done:%d]\n" , + cb_param->direction, sspc->rxdma_done, + sspc->txdma_done);drivers/spi/spi-intel-mid-ssp.c line 313
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+ +if (sspc->txdma_done && sspc->rxdma_done) { +/* Clear Status Register */ +write_SSSR (sspc->clear_sr, reg); +dev_dbg (dev,"DMA done\n" ); +/* Disable Triggers to DMA or to CPU*/ +disable_triggers (sspc); +unmap_dma_buffers (sspc); + +queue_work (sspc->dma_wq, &sspc->complete_work);I fail to see the need for this workstruct, why can't you call
complete()directly ?
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c line 728
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static irqreturn_t ssp_int (int irq,void *dev_id) +{ +struct ssp_drv_context *sspc = dev_id; +void *reg = sspc->ioaddr; +struct device *dev = &sspc->pdev->dev; +u32 status =read_SSSR (reg); + +/* It should never be our interrupt since SSP will */ +/* only trigs interrupt for under/over run. */ wrong comment style
I'll fix it
Quoted 15 lines
drivers/spi/spi-intel-mid-ssp.c line 739
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +11
-0+if (likely (!(status & sspc->mask_sr))) +return IRQ_NONE ; + +if (status &SSSR_ROR || status &SSSR_TUR ) { +dev_err (dev,"--- SPI ROR or TUR occurred : SSSR=%x\n" , status); +WARN_ON (1 ); +if (status &SSSR_ROR ) +dev_err (dev,"we have Overrun\n" ); +if (status &SSSR_TUR ) +dev_err (dev,"we have Underrun\n" ); + }I would split these two caes here:
Quoted 7 lines
if (status & ROR)
dev_WARN(dev, "Overrun\n");if (status & TUR)
dev_WARN(dev, "Underrun\n");no need for nested ifs.
Agreed.
Quoted 16 lines
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static void poll_transfer (unsigned long data) +{ +struct ssp_drv_context *sspc = (void *)data;drivers/spi/spi-intel-mid-ssp.c line 763
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+ +if (sspc->tx) { +while (sspc->tx != sspc->tx_end) { +if (ssp_timing_wr) { +int timeout =100 ; +/* It is used as debug UART on Tangier. Since +baud rate = 115200, it needs at least 312us +for one word transferring. Becuase of silicon +issue, it MUST check SFIFOL here instead of +TNF. It is the workaround for A0 stepping*/ wrong comment style.
I'll fix it.
Quoted 23 lines
drivers/spi/spi-intel-mid-ssp.c line 771
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +8
-0+while (--timeout && + ((read_SFIFOL (sspc->ioaddr)) &0xFFFF )) +udelay (10 ); + } + sspc->write (sspc); + sspc->read (sspc); + } + }you can make this look sligthly better if you:
if (!sspc->tx)
bail();while (sspc->tx != sspc->tx_end) { if (sspc->timing_wr) { int timeout = 100; .... } }
Quoted 1 line
it'll decrease one indentation level.
I'll consider it in next version.
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c line 786
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+static void start_bitbanging (struct ssp_drv_context *sspc)I would prefix with
ssp_
That makes sense.
Quoted 16 lines
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static int handle_message (struct ssp_drv_context *sspc) +{ +struct chip_data *chip =NULL ;drivers/spi/spi-intel-mid-ssp.c line 889
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+struct spi_transfer *transfer =NULL ; +void *reg = sspc->ioaddr; +u32 cr1; +struct device *dev = &sspc->pdev->dev; +struct spi_message *msg = sspc->cur_msg; + + chip =spi_get_ctldata (msg->spi); + +/* We handle only one transfer message since the protocol module has to +control the out of band signaling. */ wrong comment style.
I'll fix it.
Quoted 42 lines
Quoted 42 lines
drivers/spi/spi-intel-mid-ssp.c new file +41
-0+ transfer = list_entry(msg->transfers.next, struct spi_transfer, + transfer_list); + +/* Check transfer length */ +if (unlikely ((transfer->len >MAX_SPI_TRANSFER_SIZE ) || + (transfer->len ==0 ))) { +dev_warn (dev,"transfer length null or greater than %d\n" , +MAX_SPI_TRANSFER_SIZE ); +dev_warn (dev,"length = %d\n" , transfer->len); + msg->status = -EINVAL ; + +if (msg->complete) + msg->complete (msg->context); +complete (&sspc->msg_done); +return 0 ; + } + +/* Flush any remaining data (in case of failed previous transfer) */ +flush (sspc); + + sspc->tx = (void *)transfer->tx_buf; + sspc->rx = (void *)transfer->rx_buf; + sspc->len = transfer->len; + sspc->write = chip->write; + sspc->read = chip->read; + +if (likely (chip->dma_enabled)) { + sspc->dma_mapped =map_dma_buffers (sspc); +if (unlikely (!sspc->dma_mapped)) +return 0 ; + }else { + sspc->write = sspc->tx ? chip->write : null_writer; + sspc->read = sspc->rx ? chip->read : null_reader; + } + sspc->tx_end = sspc->tx + transfer->len; + sspc->rx_end = sspc->rx + transfer->len; +write_SSSR (sspc->clear_sr, reg); + +/* setup the CR1 control register */ + cr1 = chip->cr1 | sspc->cr1_sig; +
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 936
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+if (likely (sspc->quirks &QUIRKS_DMA_USE_NO_TRAIL )) { +/* in case of len smaller than burst size, adjust the RX */ +/* threshold. All other cases will use the default threshold */ +/* value. The RX fifo threshold must be aligned with the DMA */ +/* RX transfer size, which may be limited to a multiple of 4 */ +/* bytes due to 32bits DDR access. */ wrong comment style
Ditto
Quoted 12 lines
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +11
-0+static int ssp_spi_probe (struct pci_dev *pdev, +const struct pci_device_id *ent) +{ +struct device *dev = &pdev->dev; +struct spi_master *master; +struct ssp_drv_context *sspc =0 ; +int status; +u32 iolen =0 ; +u8 ssp_cfg; +int pos; +void __iomem *syscfg_ioaddr;
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 1196
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+unsigned long syscfg; + +/* Check if the SSP we are probed for has been allocated */ +/* to operate as SPI. This information is retreived from */ +/* the field adid of the Vendor-Specific PCI capability */ +/* which is used as a configuration register. */ wrong comment style
Ditto
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c line 1442
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static int ssp_spi_runtime_suspend (struct device *dev) +{ +return 0 ; +} + +static int ssp_spi_runtime_resume (struct device *dev) +{ +return 0 ; +}why even add these if they're no-ops ?
I'll remove them.
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c line 1495
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+static int __init ssp_spi_init (void ) +{ +return pci_register_driver (&ssp_spi_driver); +} + +late_initcall (ssp_spi_init);does it have to be late ? Can't you just use
module_pci_driver()instead ?
I'll let Ning to answer this.
Quoted 14 lines
drivers/spi/spi-intel-mid-ssp.c line 9
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0@@ -0,0 +1,330 @@ +/* +* Copyright (C) Intel 2013 +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. companies usually don't like this "at your option any later version" statement. Usually it's GPL2 only...
Hm. I've no opinion about. :)
But I'll make sure this follows the same standard of .c file.
Br, David
Quoted 198 lines · On Tue, 29 Oct 2013 13:18:37 -0700 David Cohen <[email protected]>…
Hi Felipe,
Quoted 64 lines · Felipe Balbi
Hi,
Quoted 61 lines · David Cohen
(quoted diff) +0
-0
b/drivers/spi/spi-intel-mid-ssp.cnew file mode 100644 index 0000000..b3b9fe8drivers/spi/spi-intel-mid-ssp.c new file +3
-0@@ -0,0 +1,1506 @@ +/* +* spi-intel-mid-ssp.c +* This driver supports Bulverde SSP core used on Intel MID platforms
+ * It supports SSP of Moorestown & Medfield platforms and handles clock
+ * slave & master modes.
+ *
+ * Copyright (c) 2013, Intel Corporation.
+ * Contacts: Ning Li <[email protected]>
+ * David Cohen <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */drivers/spi/spi-intel-mid-ssp.c new file +22
-0+ +/* +* Note: +* +* Supports DMA and non-interrupt polled transfers. +* +*/ +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/highmem.h> +#include <linux/pci.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/dma-mapping.h> +#include <linux/intel_mid_dma.h> +#include <linux/pm_qos.h> +#include <linux/pm_runtime.h> +#include <linux/completion.h> +#include <asm/intel-mid.h> +Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 52
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+#include <linux/spi/spi.h> +#include <linux/spi/intel_mid_ssp_spi.h> + +#define DRIVER_NAME "intel_mid_ssp_spi_unified" + +static int ssp_timing_wr;this will prevent multiple instances of the same driver.
Yeah. I'll fix it.
Quoted 22 lines
Quoted 22 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+#ifdef DUMP_RX +static void dump_trailer(const struct device *dev, char *buf, intlen, int sz) +{
drivers/spi/spi-intel-mid-ssp.c new file +15
-0+int tlen1 = (len < sz ? len : sz); +int tlen2 = ((len - sz) > sz) ? sz : (len - sz); +unsigned char *p; +static char msg[MAX_SPI_TRANSFER_SIZE ]; + +memset (msg,'\0' ,sizeof (msg)); + p = buf; +while (p < buf + tlen1) +sprintf (msg,"%s%02x" , msg, (unsigned int )*p++); + +if (tlen2 >0 ) { +sprintf (msg,"%s ....." , msg); + p = (buf+len) - tlen2; +while (p < buf + len) + sprintf(msg, "%s%02x", msg, (unsignedint)*p++);
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+ } +Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 77
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ dev_info(dev, "DUMP: %p[0:%d ... %d:%d]:%s", buf, tlen1 -1,
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+ len-tlen2, len - 1, msg); +} +#endif either move this to debugfs or stub the function out ifndef
DUMP_RX, then you don't need the ifdefs when calling it.Agreed.
Quoted 9 lines
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u8 ssp_cfg_get_mode (u8 ssp_cfg) +{ + if (intel_mid_identify_cpu() ==
INTEL_MID_CPU_CHIP_TANGIER)instead, couldn't you use driver data to pass some flags to the driver ? I can't see
intel_mid_identify_cpuand having drivers depend on arch-specific code is usually a bad practice.I'll find a way to get rid of this.
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+return (ssp_cfg) &0x03 ; + elseelse isn't needed here
Agreed.
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c line 105
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u32 is_tx_fifo_empty (struct ssp_drv_context *sspc) +{ +u32 sssr;blank line here would aid readability
Agreed.
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c line 109
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+ sssr =read_SSSR (sspc->ioaddr); +if ((sssr &SSSR_TFL_MASK ) || (sssr &SSSR_TNF ) ==0 ) +return 0 ; +else else isn't necessary
Agreed.
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c line 115
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline u32 is_rx_fifo_empty (struct ssp_drv_context *sspc) +{ +return ((read_SSSR (sspc->ioaddr) &SSSR_RNE ) ==0 );you don't need the outter parenthesis here, GCC should've warned you, even.
Yeah. checkpatch supposed to warn too. I'll fix it.
Quoted 38 lines
drivers/spi/spi-intel-mid-ssp.c line 120
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static inline void disable_interface (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line here
drivers/spi/spi-intel-mid-ssp.c line 126
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+write_SSCR0 (read_SSCR0 (reg) & ~SSCR0_SSE , reg); +} + +static inline void disable_triggers (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;and here...
Quoted 14 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+write_SSCR1 (read_SSCR1 (reg) & ~sspc->cr1_sig, reg); +} + + +static void flush (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr; +u32 i =0 ; + +/* If the transmit fifo is not empty, reset the interface. */
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+if (!is_tx_fifo_empty (sspc)) { + dev_err(&sspc->pdev->dev, "TX FIFO not empty.Reset of SPI IF");
drivers/spi/spi-intel-mid-ssp.c line 141
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+disable_interface (sspc); +return ; + }not so sure, if the transmit fifo isn't empty and you reset it, you could end up corrupting data which is about to be shifted into the wire, couldn't you ?
Quoted 4 lines
Quoted 2 lines
Is this a case which would *really* happen in normal conditions ? If so, why ?
I'll leave this question to Ning.
I did not see it happen before, but maybe the previous author had met the situation. Actually, it should be safe to disable the port here, since when setting SSCR.SSE bit to 0, the SSP will be disabled and at the same time, the FIFOs will be cleared, according to the spec.
Quoted 434 lines
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c line 148
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+dev_dbg (&sspc->pdev->dev," SSSR=%x\r\n" ,read_SSSR (reg)); + while (!is_rx_fifo_empty(sspc) && (i < SPI_FIFO_SIZE +1)) {
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+read_SSDR (reg); + i++; + } +WARN (i >0 ,"%d words flush occured\n" , i);similarly, you could be ignoring data you *should* indeed be handling.
That seems the case, yes.
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+ +return ;return statement is unnecessary.
Agreed.
Quoted 5 lines
Quoted 2 lines
+static int
null_writer(struct ssp_drv_context *sspc)looks like these two functions (null_\(writer\|reader\)) need some documentation. Why do they exist ?
I'll make sure next version has comments for it.
Quoted 38 lines
drivers/spi/spi-intel-mid-ssp.c line 184
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static int u8_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
drivers/spi/spi-intel-mid-ssp.c line 197
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +13
-0+if (((read_SSSR (reg) &SSSR_TFL_MASK ) ==SSSR_TFL_MASK ) + || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u8 *)(sspc->tx), reg); + ++sspc->tx; + +return 1 ; +} + +static int u8_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
drivers/spi/spi-intel-mid-ssp.c line 209
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+while ((read_SSSR (reg) &SSSR_RNE ) + && (sspc->rx < sspc->rx_end)) { + *(u8 *)(sspc->rx) =read_SSDR (reg); + ++sspc->rx; + } + +return sspc->rx == sspc->rx_end; +} + +static int u16_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)the extra comparisson here is superfluous.
Agreed.
Quoted 31 lines
drivers/spi/spi-intel-mid-ssp.c line 222
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+ || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u16 *)(sspc->tx), reg); + sspc->tx +=2 ; + +return 1 ; +} + +static int u16_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
drivers/spi/spi-intel-mid-ssp.c line 233
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ while ((read_SSSR(reg) & SSSR_RNE) && (sspc->rx <
sspc->rx_end)) {drivers/spi/spi-intel-mid-ssp.c new file +10
-0+ *(u16 *)(sspc->rx) =read_SSDR (reg); + sspc->rx +=2 ; + } + +return sspc->rx == sspc->rx_end; +} + +static int u32_writer (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)the extra comparisson here is superfluous.
Agreed.
Quoted 88 lines
drivers/spi/spi-intel-mid-ssp.c line 246
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+ || (sspc->tx == sspc->tx_end)) +return 0 ; + +write_SSDR (*(u32 *)(sspc->tx), reg); + sspc->tx +=4 ; + +return 1 ; +} + +static int u32_reader (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr;blank line
Quoted 24 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ while ((read_SSSR(reg) & SSSR_RNE) && (sspc->rx <
sspc->rx_end)) {drivers/spi/spi-intel-mid-ssp.c new file +19
-0+ *(u32 *)(sspc->rx) =read_SSDR (reg); + sspc->rx +=4 ; + } + +return sspc->rx == sspc->rx_end; +} + +static bool chan_filter (struct dma_chan *chan,void *param) +{ +struct ssp_drv_context *sspc = param; + +if (sspc->dmac1 && chan->device->dev == &sspc->dmac1->dev) +return true; + +return false; +} + +/** +* unmap_dma_buffers() - Unmap the DMA buffers used during the last transfer.
+ * @sspc: Pointer to the private driver context
+ */drivers/spi/spi-intel-mid-ssp.c line 274
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+static void unmap_dma_buffers (struct ssp_drv_context *sspc) +{ +struct device *dev = &sspc->pdev->dev; + +if (!sspc->dma_mapped) +return ;blank line
drivers/spi/spi-intel-mid-ssp.c
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ dma_unmap_single(dev, sspc->rx_dma, sspc->len,
PCI_DMA_FROMDEVICE);drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ dma_unmap_single(dev, sspc->tx_dma, sspc->len,
PCI_DMA_TODEVICE);drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ sspc->dma_mapped =0 ;you shouldn't need this
dma_mappedflag here...Quoted 17 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static void ssp_spi_dma_done (void *arg) +{ + struct callback_param *cb_param = (struct callback_param*)arg;
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+struct ssp_drv_context *sspc = cb_param->drv_context; +struct device *dev = &sspc->pdev->dev; +void *reg = sspc->ioaddr; + +if (cb_param->direction ==TX_DIRECTION ) + sspc->txdma_done =1 ; +else + sspc->rxdma_done =1 ; + + dev_dbg(dev, "DMA callback for direction %d [RX done:%d][TX done:%d]\n",
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+ cb_param->direction, sspc->rxdma_done, + sspc->txdma_done);drivers/spi/spi-intel-mid-ssp.c line 313
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+ +if (sspc->txdma_done && sspc->rxdma_done) { +/* Clear Status Register */ +write_SSSR (sspc->clear_sr, reg); +dev_dbg (dev,"DMA done\n" ); +/* Disable Triggers to DMA or to CPU*/ +disable_triggers (sspc); +unmap_dma_buffers (sspc); + +queue_work (sspc->dma_wq, &sspc->complete_work);I fail to see the need for this workstruct, why can't you call
complete()directly ?Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c line 728
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static irqreturn_t ssp_int (int irq,void *dev_id) +{ +struct ssp_drv_context *sspc = dev_id; +void *reg = sspc->ioaddr; +struct device *dev = &sspc->pdev->dev; +u32 status =read_SSSR (reg); + +/* It should never be our interrupt since SSP will */ +/* only trigs interrupt for under/over run. */ wrong comment style
I'll fix it
Quoted 16 lines
drivers/spi/spi-intel-mid-ssp.c line 739
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+if (likely (!(status & sspc->mask_sr))) +return IRQ_NONE ; + +if (status &SSSR_ROR || status &SSSR_TUR ) { + dev_err(dev, "--- SPI ROR or TUR occurred :SSSR=%x\n", status);
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+WARN_ON (1 ); +if (status &SSSR_ROR ) +dev_err (dev,"we have Overrun\n" ); +if (status &SSSR_TUR ) +dev_err (dev,"we have Underrun\n" ); + }I would split these two caes here:
Quoted 7 lines
if (status & ROR)
dev_WARN(dev, "Overrun\n");if (status & TUR)
dev_WARN(dev, "Underrun\n");no need for nested ifs.
Agreed.
Quoted 13 lines
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static void poll_transfer (unsigned long data) +{ +struct ssp_drv_context *sspc = (void *)data; + +if (sspc->tx) { +while (sspc->tx != sspc->tx_end) { +if (ssp_timing_wr) { +int timeout =100 ; +/* It is used as debug UART on Tangier. Since
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ baud rate = 115200, it needsat least 312us
Quoted 8 lines
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ for one word transferring.Becuase of silicon
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ issue, it MUST check SFIFOLhere instead of
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ TNF. It is the workaround forA0 stepping*/
wrong comment style.
I'll fix it.
Quoted 24 lines
drivers/spi/spi-intel-mid-ssp.c line 771
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+ while (--timeout && +((
read_SFIFOL(sspc->ioaddr)) &0xFFFF))drivers/spi/spi-intel-mid-ssp.c new file +6
-0+udelay (10 ); + } + sspc->write (sspc); + sspc->read (sspc); + } + }you can make this look sligthly better if you:
if (!sspc->tx)
bail();while (sspc->tx != sspc->tx_end) { if (sspc->timing_wr) { int timeout = 100; .... } }Quoted 1 line
it'll decrease one indentation level.
I'll consider it in next version.
Quoted 4 lines
Quoted 2 lines
+static void
start_bitbanging(struct ssp_drv_context *sspc)I would prefix with
ssp_That makes sense.
Quoted 17 lines
Quoted 14 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+static int handle_message (struct ssp_drv_context *sspc) +{ +struct chip_data *chip =NULL ; +struct spi_transfer *transfer =NULL ; +void *reg = sspc->ioaddr; +u32 cr1; +struct device *dev = &sspc->pdev->dev; +struct spi_message *msg = sspc->cur_msg; + + chip =spi_get_ctldata (msg->spi); + +/* We handle only one transfer message since the protocol module has to
drivers/spi/spi-intel-mid-ssp.c line 889
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+control the out of band signaling. */ wrong comment style.
I'll fix it.
Quoted 51 lines
Quoted 51 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+ transfer = list_entry(msg->transfers.next, struct
spi_transfer,drivers/spi/spi-intel-mid-ssp.c new file +6
-0+ transfer_list); + +/* Check transfer length */ +if (unlikely ((transfer->len >MAX_SPI_TRANSFER_SIZE ) || + (transfer->len ==0 ))) { + dev_warn(dev, "transfer length null or greaterthan %d\n",
drivers/spi/spi-intel-mid-ssp.c new file +11
-0+ MAX_SPI_TRANSFER_SIZE); +dev_warn (dev,"length = %d\n" , transfer->len); + msg->status = -EINVAL ; + +if (msg->complete) + msg->complete (msg->context); +complete (&sspc->msg_done); +return 0 ; + } + +/* Flush any remaining data (in case of failed previous transfer) */
drivers/spi/spi-intel-mid-ssp.c new file +14
-0+flush (sspc); + + sspc->tx = (void *)transfer->tx_buf; + sspc->rx = (void *)transfer->rx_buf; + sspc->len = transfer->len; + sspc->write = chip->write; + sspc->read = chip->read; + +if (likely (chip->dma_enabled)) { + sspc->dma_mapped =map_dma_buffers (sspc); +if (unlikely (!sspc->dma_mapped)) +return 0 ; + }else { + sspc->write = sspc->tx ? chip->write :
null_writer;drivers/spi/spi-intel-mid-ssp.c new file +11
-0+ sspc->read = sspc->rx ? chip->read : null_reader; + } + sspc->tx_end = sspc->tx + transfer->len; + sspc->rx_end = sspc->rx + transfer->len; +write_SSSR (sspc->clear_sr, reg); + +/* setup the CR1 control register */ + cr1 = chip->cr1 | sspc->cr1_sig; + +if (likely (sspc->quirks &QUIRKS_DMA_USE_NO_TRAIL )) { +/* in case of len smaller than burst size, adjust the RX */
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* threshold. All other cases will use the default threshold */
Quoted 8 lines
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* value. The RX fifo threshold must be aligned with the DMA */
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* RX transfer size, which may be limited to a multiple of 4 */
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* bytes due to 32bits DDR access. */
wrong comment style
Ditto
Quoted 16 lines
Quoted 16 lines
drivers/spi/spi-intel-mid-ssp.c new file +14
-0+static int ssp_spi_probe (struct pci_dev *pdev, +const struct pci_device_id *ent) +{ +struct device *dev = &pdev->dev; +struct spi_master *master; +struct ssp_drv_context *sspc =0 ; +int status; +u32 iolen =0 ; +u8 ssp_cfg; +int pos; +void __iomem *syscfg_ioaddr; +unsigned long syscfg; + +/* Check if the SSP we are probed for has been allocated */
Quoted 8 lines
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* to operate as SPI. This information is retreived from */
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* the field adid of the Vendor-Specific PCI capability */
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* which is used as a configuration register. */
wrong comment style
Ditto
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c line 1442
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static int ssp_spi_runtime_suspend (struct device *dev) +{ +return 0 ; +} + +static int ssp_spi_runtime_resume (struct device *dev) +{ +return 0 ; +}why even add these if they're no-ops ?
I'll remove them.
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c line 1495
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+static int __init ssp_spi_init (void ) +{ +return pci_register_driver (&ssp_spi_driver); +} + +late_initcall (ssp_spi_init);does it have to be late ? Can't you just use
module_pci_driver()instead ?
Quoted 2 lines
I'll let Ning to answer this.
Agreed. We can use module_pci_driver() here.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0@@ -0,0 +1,330 @@ +/* +* Copyright (C) Intel 2013 +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This program is free software; you can redistribute it and/or modifyQuoted 8 lines
Quoted 5 lines
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.companies usually don't like this "at your option any later version" statement. Usually it's GPL2 only...
Quoted 5 lines
Hm. I've no opinion about. :)
But I'll make sure this follows the same standard of .c file.Br, David
Best Regards,
Ning
Mark Brown
maintainerQuoted 3 lines · David Cohen
From: Fei Yang <[email protected]>
This patch adds driver for ssp spi interface on Intel Mid platform.
Is there not any possibility of code sharing with the PXA SSP IP? It seems odd that Intel would make a second IP of the same name that's totally incompatible... not looked at the register interfaces in detail but the register names certainly look familiar.
drivers/spi/Kconfig config SPI_IMX · line 217
Quoted 3 lines
drivers/spi/Kconfig +3
-0+ tristate "SSP SPI controller driver for Intel MID platforms (EXPERIMENTAL)" + depends on X86_INTEL_MID && SPI_MASTER && INTEL_MID_DMAC + help
Are these all build time dependencies? There's certainly no need to depend on SPI_MASTER, all drivers are inside an if SPI_MASTER block.
Quoted 1 line
+static int
ssp_timing_wr;
Why is this a static global?
drivers/spi/spi-intel-mid-ssp.c line 56
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+#ifdef DUMP_RX +static void dump_trailer (const struct device *dev,char *buf,int len,int sz) +{
Please add this support as a standard feature of the SPI core if it's useful, there's nothing specific to this driver in it. Using trace would probably be better than dumping to the console.
drivers/spi/spi-intel-mid-ssp.c line 60
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+static char msg[MAX_SPI_TRANSFER_SIZE ];
Where did that limit come from?
drivers/spi/spi-intel-mid-ssp.c line 107
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+static inline u32 is_tx_fifo_empty (struct ssp_drv_context *sspc) +{ +u32 sssr; + sssr =read_SSSR (sspc->ioaddr); +if ((sssr &SSSR_TFL_MASK ) || (sssr &SSSR_TNF ) ==0 )
This looks odd, why not sssr & (SSSR_TFL_MASK | SSSR_TNF)?
drivers/spi/spi-intel-mid-ssp.c line 141
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c new file +11
-0+static void flush (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr; +u32 i =0 ; + +/* If the transmit fifo is not empty, reset the interface. */ +if (!is_tx_fifo_empty (sspc)) { +dev_err (&sspc->pdev->dev,"TX FIFO not empty. Reset of SPI IF" ); +disable_interface (sspc); +return ; + }
This isn't a flush then?
drivers/spi/spi-intel-mid-ssp.c line 143
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+dev_dbg (&sspc->pdev->dev," SSSR=%x\r\n" ,read_SSSR (reg));
No extra space at the start of the message and why is there a \r in there? Throughout the driver your log messages have a range of odd formatting quirks that aren't consistent and don't look like normal Linux log messages either.
Please also check the severity of your messages, many of them seem too loud.
drivers/spi/spi-intel-mid-ssp.c line 147
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+while (!is_rx_fifo_empty (sspc) && (i <SPI_FIFO_SIZE +1 )) { +read_SSDR (reg); + i++; + }
What happens if the FIFO doesn't drain?
drivers/spi/spi-intel-mid-ssp.c line 148
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+WARN (i >0 ,"%d words flush occured\n" , i);
This seems *very* loud for a flush operation...
drivers/spi/spi-intel-mid-ssp.c line 394
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+if (sspc->quirks &QUIRKS_SRAM_ADDITIONAL_CPY ) { + sspc->virt_addr_sram_rx =ioremap_nocache (SRAM_BASE_ADDR , +2 *MAX_SPI_TRANSFER_SIZE );
This doesn't look terribly clever, it's remapping a hard coded address rather than getting the address enumerated from a device enumeration interface.
drivers/spi/spi-intel-mid-ssp.c line 475
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+/* get Data Read/Write address */ + ssdr_addr = (dma_addr_t)(sspc->paddr +0x10 );
I'm not entirely sure what this does but it looks dodgy... what's the cast doing for a start?
drivers/spi/spi-intel-mid-ssp.c line 496
Quoted 1 line
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* In Rx direction, TRAIL Bytes are handled by memcpy */
Please don't randomly CAPITALISE words.
drivers/spi/spi-intel-mid-ssp.c line 518
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+ rxdesc = rxchan->device->device_prep_dma_memcpy + (rxchan,/* DMA Channel */ + sspc->rx_dma,/* DAR */ + ssdr_addr,/* SAR */ + sspc->len_dma_rx,/* Data Length */ + flag);/* Flag */
What's going on here? Why is there a DMAed memcpy()? This doesn't reflect normal DMA usage in SPI drivers at all, I'd expect to see dmaengine_prep_ being used.
drivers/spi/spi-intel-mid-ssp.c line 664
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static void int_transfer_complete (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr; +struct spi_message *msg; +struct device *dev = &sspc->pdev->dev; + +if (unlikely (sspc->quirks &QUIRKS_USE_PM_QOS )) +pm_qos_update_request (&sspc->pm_qos_req, +PM_QOS_DEFAULT_VALUE );
Why is this a quirk and not abstracted away by the PM QoS API on platforms that don't need it? I'd also expect these updates to be done in runtime PM callbacks so that if two transfers follow one another we don't bounce the Qos up and down.
drivers/spi/spi-intel-mid-ssp.c line 686
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+dev_dbg (dev,"End of transfer. SSSR:%08X\n" ,read_SSSR (reg)); + msg = sspc->cur_msg; +if (likely (msg->complete)) + msg->complete (msg->context); +complete (&sspc->msg_done);
Remove all these likely()s, they're making the code less clear and seem vanishingly unlikely to have any practical impact on performance.
drivers/spi/spi-intel-mid-ssp.c line 695
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +7
-0+static void int_transfer_complete_work (struct work_struct *work) +{ +struct ssp_drv_context *sspc =container_of (work, + struct ssp_drv_context, complete_work); + +int_transfer_complete (sspc); +}
This wrapper function doesn't seem terribly useful... why not just inline it into the internal function?
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+if (status &SSSR_ROR || status &SSSR_TUR ) { +dev_err (dev,"--- SPI ROR or TUR occurred : SSSR=%x\n" , status); +WARN_ON (1 ); +if (status &SSSR_ROR ) +dev_err (dev,"we have Overrun\n" ); +if (status &SSSR_TUR )
drivers/spi/spi-intel-mid-ssp.c line 747
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+dev_err (dev,"we have Underrun\n" ); + } + +/* We can fall here when not using DMA mode */ +if (!sspc->cur_msg) { +disable_interface (sspc); +disable_triggers (sspc); + } +/* clear status register */ +write_SSSR (sspc->clear_sr, reg);
More comments explaining what's going on here would be good...
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +7
-0+static void poll_transfer (unsigned long data) +{ +struct ssp_drv_context *sspc = (void *)data; + +if (sspc->tx) { +while (sspc->tx != sspc->tx_end) { +if (ssp_timing_wr) {
drivers/spi/spi-intel-mid-ssp.c line 767
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+int timeout =100 ; +/* It is used as debug UART on Tangier. Since +baud rate = 115200, it needs at least 312us +for one word transferring. Becuase of silicon +issue, it MUST check SFIFOL here instead of +TNF. It is the workaround for A0 stepping*/ +while (--timeout && + ((read_SFIFOL (sspc->ioaddr)) &0xFFFF )) +udelay (10 ); + }
This doesn't look like it shouldn't be here at all or should be made more generic but I can't really tell what it's supposed to do...
drivers/spi/spi-intel-mid-ssp.c line 787
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+static void start_bitbanging (struct ssp_drv_context *sspc) +{
The SPI core has bitbanging helpers which you don't seem to be using. However...
drivers/spi/spi-intel-mid-ssp.c line 830
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+/* Bit bang the clock until CSS clears */ +while ((sssr &0x400000 ) && (count <MAX_BITBANGING_LOOP )) { +write_I2CDATA (0x2 , i2c_reg); +udelay (I2C_ACCESS_USDELAY );
...this code is talking about I2C?
Review
Quoted 2 lines
(quoted diff) +2
-0+ udelay(I2C_ACCESS_USDELAY); + write_I2CCTRL(0x01070034, i2c_reg);
This appears to be randomly bashing on an absolute register address.
drivers/spi/spi-intel-mid-ssp.c line 861
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+/** +* transfer() - Start a SPI transfer +* @spi: Pointer to the spi_device struct +* @msg: Pointer to the spi_message struct +*/ +static int transfer (struct spi_device *spi,struct spi_message *msg)
Use of plain transfer() has been deprecated since v3.4, you should at least be using transfer_one_message(). I've stopped reviewing at this point since a lot of the rest of the code is replicating stuff that's in the SPI core and will go away when you update to use the current APIs.
Hi Mark,
Quoted 9 lines · Mark Brown
Quoted 3 lines · David Cohen
From: Fei Yang <[email protected]>
This patch adds driver for ssp spi interface on Intel Mid platform.
Is there not any possibility of code sharing with the PXA SSP IP? It seems odd that Intel would make a second IP of the same name that's totally incompatible... not looked at the register interfaces in detail but the register names certainly look familiar.
I need to bring this question to IO team (who wrote this driver)
Quoted 11 lines
drivers/spi/Kconfig config SPI_IMX · line 217
Quoted 4 lines
drivers/spi/Kconfig +3
-0+ tristate "SSP SPI controller driver for Intel MID platforms (EXPERIMENTAL)" + depends on X86_INTEL_MID && SPI_MASTER && INTEL_MID_DMAC + helpAre these all build time dependencies? There's certainly no need to depend on
SPI_MASTER, all drivers are inside an ifSPI_MASTERblock.Quoted 1 line
+static int
ssp_timing_wr;Why is this a static global?
My only answer would be: because a lazy developer decided so :)
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 56
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+#ifdef DUMP_RX +static void dump_trailer (const struct device *dev,char *buf,int len,int sz) +{Please add this support as a standard feature of the SPI core if it's useful, there's nothing specific to this driver in it. Using trace would probably be better than dumping to the console.
Agreed.
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c line 60
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+static char msg[MAX_SPI_TRANSFER_SIZE ];Where did that limit come from?
Again, I'd need to bring to IO team. I'll make sure a possible new version comes with proper comment.
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 107
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+static inline u32 is_tx_fifo_empty (struct ssp_drv_context *sspc) +{ +u32 sssr; + sssr =read_SSSR (sspc->ioaddr); +if ((sssr &SSSR_TFL_MASK ) || (sssr &SSSR_TNF ) ==0 )This looks odd, why not sssr & (
SSSR_TFL_MASK|SSSR_TNF)?
Agreed.
Quoted 14 lines
drivers/spi/spi-intel-mid-ssp.c line 141
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c new file +11
-0+static void flush (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr; +u32 i =0 ; + +/* If the transmit fifo is not empty, reset the interface. */ +if (!is_tx_fifo_empty (sspc)) { +dev_err (&sspc->pdev->dev,"TX FIFO not empty. Reset of SPI IF" ); +disable_interface (sspc); +return ; + }This isn't a flush then?
Analyzing the code I'd say this flush() function is actually a reset for tx fifo and flush for rx fifo.
Maybe we need a better name for it.
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c line 143
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+dev_dbg (&sspc->pdev->dev," SSSR=%x\r\n" ,read_SSSR (reg));No extra space at the start of the message and why is there a \r in there? Throughout the driver your log messages have a range of odd formatting quirks that aren't consistent and don't look like normal Linux log messages either.
Please also check the severity of your messages, many of them seem too loud.
I'll handle that.
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c line 147
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+while (!is_rx_fifo_empty (sspc) && (i <SPI_FIFO_SIZE +1 )) { +read_SSDR (reg); + i++; + }What happens if the FIFO doesn't drain?
I'll let Ning answer this question.
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c line 148
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+WARN (i >0 ,"%d words flush occured\n" , i);This seems *very* loud for a flush operation...
Agreed.
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 394
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+if (sspc->quirks &QUIRKS_SRAM_ADDITIONAL_CPY ) { + sspc->virt_addr_sram_rx =ioremap_nocache (SRAM_BASE_ADDR , +2 *MAX_SPI_TRANSFER_SIZE );This doesn't look terribly clever, it's remapping a hard coded address rather than getting the address enumerated from a device enumeration interface.
I'll check if I can recover this value from somewhere without changing fw. Otherwise we could mark it as FIXME and change later in a different patch.
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c line 475
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+/* get Data Read/Write address */ + ssdr_addr = (dma_addr_t)(sspc->paddr +0x10 );I'm not entirely sure what this does but it looks dodgy... what's the cast doing for a start?
The answer to your question is: the cast is pointless and can be removed :)0x10 is an offset to paddr. We need to replace it by a macro with proper name to make this clear.
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c line 496
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +1
-0+/* In Rx direction, TRAIL Bytes are handled by memcpy */ Please don't randomly CAPITALISE words.
Sorry ABOUT that :)
I'll fix it.
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c line 518
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+ rxdesc = rxchan->device->device_prep_dma_memcpy + (rxchan,/* DMA Channel */ + sspc->rx_dma,/* DAR */ + ssdr_addr,/* SAR */ + sspc->len_dma_rx,/* Data Length */ + flag);/* Flag */ What's going on here? Why is there a DMAed
memcpy()? This doesn't reflect normal DMA usage in SPI drivers at all, I'd expect to seedmaengine_prep_being used.
I'll let this question again to Ning.
Quoted 15 lines
drivers/spi/spi-intel-mid-ssp.c line 664
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+static void int_transfer_complete (struct ssp_drv_context *sspc) +{ +void *reg = sspc->ioaddr; +struct spi_message *msg; +struct device *dev = &sspc->pdev->dev; + +if (unlikely (sspc->quirks &QUIRKS_USE_PM_QOS )) +pm_qos_update_request (&sspc->pm_qos_req, +PM_QOS_DEFAULT_VALUE );Why is this a quirk and not abstracted away by the PM QoS API on platforms that don't need it? I'd also expect these updates to be done in runtime PM callbacks so that if two transfers follow one another we don't bounce the Qos up and down.
Got it. I'll change this code.
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c line 686
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+dev_dbg (dev,"End of transfer. SSSR:%08X\n" ,read_SSSR (reg)); + msg = sspc->cur_msg; +if (likely (msg->complete)) + msg->complete (msg->context); +complete (&sspc->msg_done);Remove all these likely()s, they're making the code less clear and seem vanishingly unlikely to have any practical impact on performance.
Agreed.
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c line 695
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c new file +7
-0+static void int_transfer_complete_work (struct work_struct *work) +{ +struct ssp_drv_context *sspc =container_of (work, + struct ssp_drv_context, complete_work); + +int_transfer_complete (sspc); +}This wrapper function doesn't seem terribly useful... why not just inline it into the internal function?
That seems reasonable. I'll change it.
Quoted 11 lines
Quoted 11 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+if (status &SSSR_ROR || status &SSSR_TUR ) { +dev_err (dev,"--- SPI ROR or TUR occurred : SSSR=%x\n" , status); +WARN_ON (1 ); +if (status &SSSR_ROR ) +dev_err (dev,"we have Overrun\n" ); +if (status &SSSR_TUR ) +dev_err (dev,"we have Underrun\n" ); + } + +/* We can fall here when not using DMA mode */
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 747
Quoted 6 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+if (!sspc->cur_msg) { +disable_interface (sspc); +disable_triggers (sspc); + } +/* clear status register */ +write_SSSR (sspc->clear_sr, reg);More comments explaining what's going on here would be good...
We'll provide.
Quoted 13 lines
Quoted 13 lines
drivers/spi/spi-intel-mid-ssp.c new file +12
-0+static void poll_transfer (unsigned long data) +{ +struct ssp_drv_context *sspc = (void *)data; + +if (sspc->tx) { +while (sspc->tx != sspc->tx_end) { +if (ssp_timing_wr) { +int timeout =100 ; +/* It is used as debug UART on Tangier. Since +baud rate = 115200, it needs at least 312us +for one word transferring. Becuase of silicon +issue, it MUST check SFIFOL here instead of
Quoted 8 lines
drivers/spi/spi-intel-mid-ssp.c line 767
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +5
-0+TNF. It is the workaround for A0 stepping*/ +while (--timeout && + ((read_SFIFOL (sspc->ioaddr)) &0xFFFF )) +udelay (10 ); + }This doesn't look like it shouldn't be here at all or should be made more generic but I can't really tell what it's supposed to do...
Ning?
Quoted 14 lines
drivers/spi/spi-intel-mid-ssp.c line 787
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+static void start_bitbanging (struct ssp_drv_context *sspc) +{The SPI core has bitbanging helpers which you don't seem to be using. However...
drivers/spi/spi-intel-mid-ssp.c line 830
Quoted 4 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+/* Bit bang the clock until CSS clears */ +while ((sssr &0x400000 ) && (count <MAX_BITBANGING_LOOP )) { +write_I2CDATA (0x2 , i2c_reg); +udelay (I2C_ACCESS_USDELAY );...this code is talking about I2C?
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ udelay(I2C_ACCESS_USDELAY); + write_I2CCTRL(0x01070034, i2c_reg);This appears to be randomly bashing on an absolute register address.
Ouch. I'll fix it.
Quoted 12 lines
drivers/spi/spi-intel-mid-ssp.c line 861
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+/** +* transfer() - Start a SPI transfer +* @spi: Pointer to the spi_device struct +* @msg: Pointer to the spi_message struct +*/ +static int transfer (struct spi_device *spi,struct spi_message *msg)Use of plain
transfer()has been deprecated since v3.4, you should at least be usingtransfer_one_message(). I've stopped reviewing at this point since a lot of the rest of the code is replicating stuff that's in the SPI core and will go away when you update to use the current APIs.
Thanks. This driver needs to be rewritten.
I'll make sure to address your feedback in next version.
Br, David
On 10/29/13 11:05, David Cohen wrote:
a few more comments:
drivers/spi/spi-intel-mid-ssp.c line 853
Quoted 3 lines
drivers/spi/spi-intel-mid-ssp.c new file +3
-0+static unsigned int ssp_get_clk_div (int speed) +{ +return max (100000000 / speed,4 ) -1 ;
Divide uses library call? I dunno...
Bad if so. Would need to use some function from
#include <asm-generic/div64.h>
drivers/spi/spi-intel-mid-ssp.c line 1016
Quoted 5 lines
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+} +/** +* setup() - Driver setup procedure +* @spi: Pointeur to the spi_device struct
Pointer
Quoted 5 lines
+ */
drivers/spi/spi-intel-mid-ssp.c new file +4
-0+static int setup (struct spi_device *spi) +{ +} +/**
drivers/spi/spi-intel-mid-ssp.c line 1236
Quoted 10 lines
drivers/spi/spi-intel-mid-ssp.c new file +10
-0+* ssp_spi_probe() - Driver probe procedure +* @pdev: Pointer to the pci_dev struct +* @ent: Pointer to the pci_device_id struct +*/ +static int ssp_spi_probe (struct pci_dev *pdev, +const struct pci_device_id *ent) +{ +/* Set platform & configuration quirks */ +if (sspc->quirks &QUIRKS_PLATFORM_MRST ) { +/* Apply bit banging workarround on MRST */
workaround
drivers/spi/spi-intel-mid-ssp.c line 1238
Quoted 2 lines
drivers/spi/spi-intel-mid-ssp.c new file +2
-0+ sspc->quirks |=QUIRKS_BIT_BANGING ; +/* MRST slave mode workarrounds */
workarounds
drivers/spi/spi-intel-mid-ssp.c line 1299
Quoted 9 lines
drivers/spi/spi-intel-mid-ssp.c new file +9
-0+if (ssp_cfg_is_spi_slave (ssp_cfg)) + sspc->quirks |=QUIRKS_USE_PM_QOS | +QUIRKS_SRAM_ADDITIONAL_CPY ; + } +if (intel_mid_identify_cpu () ==INTEL_MID_CPU_CHIP_TANGIER ) + ssp_timing_wr =1 ; + +if (status <0 ) { +dev_err (&pdev->dev,"can not get IRQ\n" );
cannot
drivers/spi/spi-intel-mid-ssp.c line 1505
Quoted 7 lines
drivers/spi/spi-intel-mid-ssp.c new file +6
-0+ goto err_free_4; + } + +} +MODULE_AUTHOR ("Ken Mills" ); +MODULE_DESCRIPTION ("Bulverde SSP core SPI contoller" );
controller
Quoted 1 line
+MODULE_LICENSE("GPL");
Signature · 5 lines
~Randy -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html