Skip to contentSkip to conversation

MIPS/spi: New driver for SPI master controller for OCTEON SOCs.

PATCH Superseded David Daney 7 participants 19 messages May 11, 2012 – Aug 21, 2012

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover MIPS/spi: New driver for SPI master controller for OCTEON SOCs.

From: David Daney <[email protected]>

Several members of the OCTEON family have on-chips SPI master controller hardware, so here is a driver for it.

I split the register definitions out to a separate patch so that they live with all the other similar files for other OCTEON hardware blocks in arch/mips/include/asm/octeon. This does leave the question of who should merge these. I don't have a preference, could be Ralf's Linux/MIPS tree or via the SPI maintainers.

Tested by driving an at25 eeprom.

David Daney (2):
MIPS: OCTEON: Add register definitions for SPI host hardware.
spi: Add SPI master controller for OCTEON SOCs.

 .../devicetree/bindings/spi/spi-octeon.txt         |   33 ++
 arch/mips/include/asm/octeon/cvmx-mpi-defs.h       |  328 +++++++++++++++++
 drivers/spi/Kconfig                                |    7 +
 drivers/spi/Makefile                               |    1 +
 drivers/spi/spi-octeon.c                           |  369 ++++++++++++++++++++
 5 files changed, 738 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-octeon.txt
 create mode 100644 arch/mips/include/asm/octeon/cvmx-mpi-defs.h
 create mode 100644 drivers/spi/spi-octeon.c
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/2 MIPS: OCTEON: Add register definitions for SPI host hardware.

From: David Daney <david.daney-YGCgFSpz5w/[email protected]>

Needed by SPI driver.

---
 arch/mips/include/asm/octeon/cvmx-mpi-defs.h |  328 ++++++++++++++++++++++++++
 1 files changed, 328 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/include/asm/octeon/cvmx-mpi-defs.h
arch/mips/include/asm/octeon/cvmx-mpi-defs.h new file +328 -0
new file mode 100644
index 0000000..4615b10
@@ -0,0 +1,328 @@
+/***********************license start***************
+ * Author: Cavium Networks
+ *
+ * Contact: [email protected]
+ * This file is part of the OCTEON SDK
+ *
+ * Copyright (c) 2003-2012 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
+ * NONINFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this file; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * or visit http://www.gnu.org/licenses/.
+ *
+ * This file may also be available under a different license from Cavium.
+ * Contact Cavium Networks for more information
+ ***********************license end**************************************/
+
+#ifndef __CVMX_MPI_DEFS_H__
+#define __CVMX_MPI_DEFS_H__
+
+#define CVMX_MPI_CFG (CVMX_ADD_IO_SEG(0x0001070000001000ull))
+#define CVMX_MPI_DATX(offset) (CVMX_ADD_IO_SEG(0x0001070000001080ull) + ((offset) & 15) * 8)
+#define CVMX_MPI_STS (CVMX_ADD_IO_SEG(0x0001070000001008ull))
+#define CVMX_MPI_TX (CVMX_ADD_IO_SEG(0x0001070000001010ull))
+
+union cvmx_mpi_cfg {
+	uint64_t u64;
+	struct cvmx_mpi_cfg_s {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_29_63:35;
+		uint64_t clkdiv:13;
+		uint64_t csena3:1;
+		uint64_t csena2:1;
+		uint64_t csena1:1;
+		uint64_t csena0:1;
+		uint64_t cslate:1;
+		uint64_t tritx:1;
+		uint64_t idleclks:2;
+		uint64_t cshi:1;
+		uint64_t csena:1;
+		uint64_t int_ena:1;
+		uint64_t lsbfirst:1;
+		uint64_t wireor:1;
+		uint64_t clk_cont:1;
+		uint64_t idlelo:1;
+		uint64_t enable:1;
+#else
+		uint64_t enable:1;
+		uint64_t idlelo:1;
+		uint64_t clk_cont:1;
+		uint64_t wireor:1;
+		uint64_t lsbfirst:1;
+		uint64_t int_ena:1;
+		uint64_t csena:1;
+		uint64_t cshi:1;
+		uint64_t idleclks:2;
+		uint64_t tritx:1;
+		uint64_t cslate:1;
+		uint64_t csena0:1;
+		uint64_t csena1:1;
+		uint64_t csena2:1;
+		uint64_t csena3:1;
+		uint64_t clkdiv:13;
+		uint64_t reserved_29_63:35;
+#endif
+	} s;
+	struct cvmx_mpi_cfg_cn30xx {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_29_63:35;
+		uint64_t clkdiv:13;
+		uint64_t reserved_12_15:4;
+		uint64_t cslate:1;
+		uint64_t tritx:1;
+		uint64_t idleclks:2;
+		uint64_t cshi:1;
+		uint64_t csena:1;
+		uint64_t int_ena:1;
+		uint64_t lsbfirst:1;
+		uint64_t wireor:1;
+		uint64_t clk_cont:1;
+		uint64_t idlelo:1;
+		uint64_t enable:1;
+#else
+		uint64_t enable:1;
+		uint64_t idlelo:1;
+		uint64_t clk_cont:1;
+		uint64_t wireor:1;
+		uint64_t lsbfirst:1;
+		uint64_t int_ena:1;
+		uint64_t csena:1;
+		uint64_t cshi:1;
+		uint64_t idleclks:2;
+		uint64_t tritx:1;
+		uint64_t cslate:1;
+		uint64_t reserved_12_15:4;
+		uint64_t clkdiv:13;
+		uint64_t reserved_29_63:35;
+#endif
+	} cn30xx;
+	struct cvmx_mpi_cfg_cn31xx {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_29_63:35;
+		uint64_t clkdiv:13;
+		uint64_t reserved_11_15:5;
+		uint64_t tritx:1;
+		uint64_t idleclks:2;
+		uint64_t cshi:1;
+		uint64_t csena:1;
+		uint64_t int_ena:1;
+		uint64_t lsbfirst:1;
+		uint64_t wireor:1;
+		uint64_t clk_cont:1;
+		uint64_t idlelo:1;
+		uint64_t enable:1;
+#else
+		uint64_t enable:1;
+		uint64_t idlelo:1;
+		uint64_t clk_cont:1;
+		uint64_t wireor:1;
+		uint64_t lsbfirst:1;
+		uint64_t int_ena:1;
+		uint64_t csena:1;
+		uint64_t cshi:1;
+		uint64_t idleclks:2;
+		uint64_t tritx:1;
+		uint64_t reserved_11_15:5;
+		uint64_t clkdiv:13;
+		uint64_t reserved_29_63:35;
+#endif
+	} cn31xx;
+	struct cvmx_mpi_cfg_cn30xx cn50xx;
+	struct cvmx_mpi_cfg_cn61xx {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_29_63:35;
+		uint64_t clkdiv:13;
+		uint64_t reserved_14_15:2;
+		uint64_t csena1:1;
+		uint64_t csena0:1;
+		uint64_t cslate:1;
+		uint64_t tritx:1;
+		uint64_t idleclks:2;
+		uint64_t cshi:1;
+		uint64_t reserved_6_6:1;
+		uint64_t int_ena:1;
+		uint64_t lsbfirst:1;
+		uint64_t wireor:1;
+		uint64_t clk_cont:1;
+		uint64_t idlelo:1;
+		uint64_t enable:1;
+#else
+		uint64_t enable:1;
+		uint64_t idlelo:1;
+		uint64_t clk_cont:1;
+		uint64_t wireor:1;
+		uint64_t lsbfirst:1;
+		uint64_t int_ena:1;
+		uint64_t reserved_6_6:1;
+		uint64_t cshi:1;
+		uint64_t idleclks:2;
+		uint64_t tritx:1;
+		uint64_t cslate:1;
+		uint64_t csena0:1;
+		uint64_t csena1:1;
+		uint64_t reserved_14_15:2;
+		uint64_t clkdiv:13;
+		uint64_t reserved_29_63:35;
+#endif
+	} cn61xx;
+	struct cvmx_mpi_cfg_cn66xx {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_29_63:35;
+		uint64_t clkdiv:13;
+		uint64_t csena3:1;
+		uint64_t csena2:1;
+		uint64_t reserved_12_13:2;
+		uint64_t cslate:1;
+		uint64_t tritx:1;
+		uint64_t idleclks:2;
+		uint64_t cshi:1;
+		uint64_t reserved_6_6:1;
+		uint64_t int_ena:1;
+		uint64_t lsbfirst:1;
+		uint64_t wireor:1;
+		uint64_t clk_cont:1;
+		uint64_t idlelo:1;
+		uint64_t enable:1;
+#else
+		uint64_t enable:1;
+		uint64_t idlelo:1;
+		uint64_t clk_cont:1;
+		uint64_t wireor:1;
+		uint64_t lsbfirst:1;
+		uint64_t int_ena:1;
+		uint64_t reserved_6_6:1;
+		uint64_t cshi:1;
+		uint64_t idleclks:2;
+		uint64_t tritx:1;
+		uint64_t cslate:1;
+		uint64_t reserved_12_13:2;
+		uint64_t csena2:1;
+		uint64_t csena3:1;
+		uint64_t clkdiv:13;
+		uint64_t reserved_29_63:35;
+#endif
+	} cn66xx;
+	struct cvmx_mpi_cfg_cn61xx cnf71xx;
+};
+
+union cvmx_mpi_datx {
+	uint64_t u64;
+	struct cvmx_mpi_datx_s {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_8_63:56;
+		uint64_t data:8;
+#else
+		uint64_t data:8;
+		uint64_t reserved_8_63:56;
+#endif
+	} s;
+	struct cvmx_mpi_datx_s cn30xx;
+	struct cvmx_mpi_datx_s cn31xx;
+	struct cvmx_mpi_datx_s cn50xx;
+	struct cvmx_mpi_datx_s cn61xx;
+	struct cvmx_mpi_datx_s cn66xx;
+	struct cvmx_mpi_datx_s cnf71xx;
+};
+
+union cvmx_mpi_sts {
+	uint64_t u64;
+	struct cvmx_mpi_sts_s {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_13_63:51;
+		uint64_t rxnum:5;
+		uint64_t reserved_1_7:7;
+		uint64_t busy:1;
+#else
+		uint64_t busy:1;
+		uint64_t reserved_1_7:7;
+		uint64_t rxnum:5;
+		uint64_t reserved_13_63:51;
+#endif
+	} s;
+	struct cvmx_mpi_sts_s cn30xx;
+	struct cvmx_mpi_sts_s cn31xx;
+	struct cvmx_mpi_sts_s cn50xx;
+	struct cvmx_mpi_sts_s cn61xx;
+	struct cvmx_mpi_sts_s cn66xx;
+	struct cvmx_mpi_sts_s cnf71xx;
+};
+
+union cvmx_mpi_tx {
+	uint64_t u64;
+	struct cvmx_mpi_tx_s {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_22_63:42;
+		uint64_t csid:2;
+		uint64_t reserved_17_19:3;
+		uint64_t leavecs:1;
+		uint64_t reserved_13_15:3;
+		uint64_t txnum:5;
+		uint64_t reserved_5_7:3;
+		uint64_t totnum:5;
+#else
+		uint64_t totnum:5;
+		uint64_t reserved_5_7:3;
+		uint64_t txnum:5;
+		uint64_t reserved_13_15:3;
+		uint64_t leavecs:1;
+		uint64_t reserved_17_19:3;
+		uint64_t csid:2;
+		uint64_t reserved_22_63:42;
+#endif
+	} s;
+	struct cvmx_mpi_tx_cn30xx {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_17_63:47;
+		uint64_t leavecs:1;
+		uint64_t reserved_13_15:3;
+		uint64_t txnum:5;
+		uint64_t reserved_5_7:3;
+		uint64_t totnum:5;
+#else
+		uint64_t totnum:5;
+		uint64_t reserved_5_7:3;
+		uint64_t txnum:5;
+		uint64_t reserved_13_15:3;
+		uint64_t leavecs:1;
+		uint64_t reserved_17_63:47;
+#endif
+	} cn30xx;
+	struct cvmx_mpi_tx_cn30xx cn31xx;
+	struct cvmx_mpi_tx_cn30xx cn50xx;
+	struct cvmx_mpi_tx_cn61xx {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_21_63:43;
+		uint64_t csid:1;
+		uint64_t reserved_17_19:3;
+		uint64_t leavecs:1;
+		uint64_t reserved_13_15:3;
+		uint64_t txnum:5;
+		uint64_t reserved_5_7:3;
+		uint64_t totnum:5;
+#else
+		uint64_t totnum:5;
+		uint64_t reserved_5_7:3;
+		uint64_t txnum:5;
+		uint64_t reserved_13_15:3;
+		uint64_t leavecs:1;
+		uint64_t reserved_17_19:3;
+		uint64_t csid:1;
+		uint64_t reserved_21_63:43;
+#endif
+	} cn61xx;
+	struct cvmx_mpi_tx_s cn66xx;
+	struct cvmx_mpi_tx_cn61xx cnf71xx;
+};
+
+#endif
Signature · 9 lines
1.7.2.3


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
#5 lore raw

PATCH 2/2 spi: Add SPI master controller for OCTEON SOCs.

In reply to David Daney

From: David Daney <david.daney-YGCgFSpz5w/[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

---
 .../devicetree/bindings/spi/spi-octeon.txt         |   33 ++
 drivers/spi/Kconfig                                |    7 +
 drivers/spi/Makefile                               |    1 +
 drivers/spi/spi-octeon.c                           |  369 ++++++++++++++++++++
 4 files changed, 410 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-octeon.txt
 create mode 100644 drivers/spi/spi-octeon.c
Documentation/devicetree/bindings/spi/spi-octeon.txt new file +33 -0
new file mode 100644
index 0000000..431add1
@@ -0,0 +1,33 @@
+Cavium, Inc. OCTEON SOC SPI master controller.
+
+Required properties:
+- compatible : "cavium,octeon-3010-spi"
+- reg : The register base for the controller.
+- interrupts : One interrupt, used by the controller.
+- #address-cells : <1>, as required by generic SPI binding.
+- #size-cells : <0>, also as required by generic SPI binding.
+
+Child nodes as per the generic SPI binding.
+
+Example:
+
+	spi@1070000001000 {
+		compatible = "cavium,octeon-3010-spi";
+		reg = <0x10700 0x00001000 0x0 0x100>;
+		interrupts = <0 58>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		eeprom@0 {
+			compatible = "st,m95256", "atmel,at25";
+			reg = <0>;
+			spi-max-frequency = <5000000>;
+			spi-cpha;
+			spi-cpol;
+
+			pagesize = <64>;
+			size = <32768>;
+			address-width = <16>;
+		};
+	};
+
drivers/spi/Kconfig +7 -0
index 00c0240..e1dd0d0 100644
@@ -228,6 +228,13 @@ config SPI_OC_TINY
 	help
 	  This is the driver for OpenCores tiny SPI master controller.
 
+config SPI_OCTEON
+	tristate "Cavium OCTEON SPI controller"
+	depends on CPU_CAVIUM_OCTEON
+	help
+	  SPI host driver for the hardware found on some Cavium OCTEON
+	  SOCs.
+
 config SPI_OMAP_UWIRE
 	tristate "OMAP1 MicroWire"
 	depends on ARCH_OMAP1
drivers/spi/Makefile +1 -0
index 9d75d21..c7f8b71 100644
@@ -37,6 +37,7 @@ obj-$(CONFIG_SPI_MPC52xx_PSC)		+= spi-mpc52xx-psc.o
 obj-$(CONFIG_SPI_MPC52xx)		+= spi-mpc52xx.o
 obj-$(CONFIG_SPI_NUC900)		+= spi-nuc900.o
 obj-$(CONFIG_SPI_OC_TINY)		+= spi-oc-tiny.o
+obj-$(CONFIG_SPI_OCTEON)		+= spi-octeon.o
 obj-$(CONFIG_SPI_OMAP_UWIRE)		+= spi-omap-uwire.o
 obj-$(CONFIG_SPI_OMAP_100K)		+= spi-omap-100k.o
 obj-$(CONFIG_SPI_OMAP24XX)		+= spi-omap2-mcspi.o
drivers/spi/spi-octeon.c new file +369 -0

369 lines not on this page · raw message

Signature · 9 lines
1.7.2.3


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
#6 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

Hi David,
A few comments.

Quoted 101 lines · David Daney

From: David Daney <[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

---
 .../devicetree/bindings/spi/spi-octeon.txt         |   33 ++ drivers/spi/Kconfig                                |    7 + drivers/spi/Makefile                               |    1 + drivers/spi/spi-octeon.c                           |  369 ++++++++++++++++++++

 4 files changed, 410 insertions(+), 0 deletions(-)

 create mode 100644 Documentation/devicetree/bindings/spi/spi-octeon.txt create mode 100644 drivers/spi/spi-octeon.c

Documentation/devicetree/bindings/spi/spi-octeon.txt new file +33 -0
new file mode 100644
index 0000000..431add1
@@ -0,0 +1,33 @@
+Cavium, Inc. OCTEON SOC SPI master controller.
+
+Required properties:
+- compatible : "cavium,octeon-3010-spi"
+- reg : The register base for the controller.
+- interrupts : One interrupt, used by the controller.
+- #address-cells : <1>, as required by generic SPI binding.
+- #size-cells : <0>, also as required by generic SPI binding.
+
+Child nodes as per the generic SPI binding.
+
+Example:
+
+       spi@1070000001000 {
+               compatible = "cavium,octeon-3010-spi";
+               reg = <0x10700 0x00001000 0x0 0x100>;
+               interrupts = <0 58>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               eeprom@0 {
+                       compatible = "st,m95256", "atmel,at25";
+                       reg = <0>;
+                       spi-max-frequency = <5000000>;
+                       spi-cpha;
+                       spi-cpol;
+
+                       pagesize = <64>;
+                       size = <32768>;
+                       address-width = <16>;
+               };
+       };
+
drivers/spi/Kconfig +0 -0
index 00c0240..e1dd0d0 100644
@@ -228,6 +228,13 @@ config SPI_OC_TINY

       help
         This is the driver for OpenCores tiny SPI master controller.

drivers/spi/Kconfig +7 -0
+config SPI_OCTEON
+       tristate "Cavium OCTEON SPI controller"
+       depends on CPU_CAVIUM_OCTEON
+       help
+         SPI host driver for the hardware found on some Cavium OCTEON
+         SOCs.
+

 config SPI_OMAP_UWIRE
       tristate "OMAP1 MicroWire"
       depends on ARCH_OMAP1

drivers/spi/Makefile +0 -0
index 9d75d21..c7f8b71 100644
@@ -37,6 +37,7 @@ obj-$(CONFIG_SPI_MPC52xx_PSC)         += spi-mpc52xx-psc.o

 obj-$(CONFIG_SPI_MPC52xx)              += spi-mpc52xx.o obj-$(CONFIG_SPI_NUC900)               += spi-nuc900.o obj-$(CONFIG_SPI_OC_TINY)              += spi-oc-tiny.o +obj-$(CONFIG_SPI_OCTEON)               += spi-octeon.o obj-$(CONFIG_SPI_OMAP_UWIRE)           += spi-omap-uwire.o obj-$(CONFIG_SPI_OMAP_100K)            += spi-omap-100k.o obj-$(CONFIG_SPI_OMAP24XX)             += spi-omap2-mcspi.o

drivers/spi/spi-octeon.c new file +11 -0
new file mode 100644
index 0000000..7207aaf
@@ -0,0 +1,369 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2011, 2012 Cavium, Inc.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/spi/spi.h>

drivers/spi/spi-octeon.c line 21

Quoted 10 lines
drivers/spi/spi-octeon.c new file +10 -0
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/of_spi.h>
+#include <linux/io.h>
+#include <linux/of.h>
+
+#include <asm/octeon/octeon.h>
+#include <asm/octeon/cvmx-mpi-defs.h>
+
+#define DRV_VERSION "2.0" /* Version 1 was the out-of-tree driver */

This could be given a miss. As it is less meaningful once accepted.

Quoted 24 lines
drivers/spi/spi-octeon.c new file +24 -0
+#define DRV_DESCRIPTION "Cavium, Inc. OCTEON SPI bus driver"
+
+
+#define OCTEON_SPI_CFG 0
+#define OCTEON_SPI_STS 0x08
+#define OCTEON_SPI_TX 0x10
+#define OCTEON_SPI_DAT0 0x80
+
+#define OCTEON_SPI_MAX_BYTES 9
+
+#define OCTEON_SPI_MAX_CLOCK_HZ 16000000
+
+struct octeon_spi {
+       struct spi_master *my_master;
+       u64 register_base;
+       u64 last_cfg;
+       u64 cs_enax;
+};
+
+struct octeon_spi_setup {
+       u32 max_speed_hz;
+       u8 chip_select;
+       u8 mode;
+       u8 bits_per_word;

drivers/spi/spi-octeon.c line 55

Quoted 10 lines
drivers/spi/spi-octeon.c new file +10 -0
+};
+
+static void octeon_spi_wait_ready(struct octeon_spi *p)
+{
+       union cvmx_mpi_sts mpi_sts;
+       unsigned int loops = 0;
+
+       do {
+               if (loops++)
+                       __delay(500);

Could we allow have a non-busy loop here?

#7 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

Quoted 4 lines · Shubhrajyoti Datta

Hi David,
A few comments.

On Sat, May 12, 2012 at 3:04 AM, David Daney<[email protected]> wrote:

[...]

Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+#define DRV_VERSION "2.0" /* Version 1 was the out-of-tree driver */

This could be given a miss. As it is less meaningful once accepted.

Well, this leads to the question, what is the purpose of the 'MODULE_VERSION()' macro? If I use that, I need to populate it with a value.

Quoted 1 line

[...]

Quoted 10 lines

drivers/spi/spi-octeon.c line 55

Quoted 8 lines
drivers/spi/spi-octeon.c new file +8 -0
+static void octeon_spi_wait_ready(struct octeon_spi *p)
+{
+       union cvmx_mpi_sts mpi_sts;
+       unsigned int loops = 0;
+
+       do {
+               if (loops++)
+                       __delay(500);

Could we allow have a non-busy loop here?

We could, but I thought about it and chose not to.

The SPI hardware can queue a maximum of 9 bytes (72 bits) before software has to take action. That works out to 3.6 uS at a 20MHz clock rate. Sleeping, scheduling to a different task, taking an interrupt and then switching back to this task will likely not be faster than that.

At lower clock rates, it would make more sense, but it adds complexity to the driver. We can always revisit this decision if it proves to be a problem.

David Daney

#2 lore raw

Re: [PATCH 1/2] MIPS: OCTEON: Add register definitions for SPI host hardware.

In reply to David Daney
Quoted 3 lines · David Daney

From: David Daney <[email protected]>

Needed by SPI driver.

That's not very verbose, plese tell atleast tell which SPI driver it's for.

Quoted 2 lines

+union cvmx_mpi_cfg {
+       uint64_t u64;

The kernel already has a type (in <linux/kernel.h>) used in many places in the kernel, called "u64" so this gets very confusing.

Can you call it something else?

BTW: you could then s/uint64_t/u64 and use that u64. (Some don't like the three-letter types so no big deal.)

Quoted 28 lines

+       struct cvmx_mpi_cfg_s {

arch/mips/include/asm/octeon/cvmx-mpi-defs.h new file +27 -0
+#ifdef __BIG_ENDIAN_BITFIELD
+               uint64_t reserved_29_63:35;
+               uint64_t clkdiv:13;
+               uint64_t csena3:1;
+               uint64_t csena2:1;
+               uint64_t csena1:1;
+               uint64_t csena0:1;
+               uint64_t cslate:1;
+               uint64_t tritx:1;
+               uint64_t idleclks:2;
+               uint64_t cshi:1;
+               uint64_t csena:1;
+               uint64_t int_ena:1;
+               uint64_t lsbfirst:1;
+               uint64_t wireor:1;
+               uint64_t clk_cont:1;
+               uint64_t idlelo:1;
+               uint64_t enable:1;
+#else
+               uint64_t enable:1;
+               uint64_t idlelo:1;
+               uint64_t clk_cont:1;
+               uint64_t wireor:1;
+               uint64_t lsbfirst:1;
+               uint64_t int_ena:1;
+               uint64_t csena:1;
+               uint64_t cshi:1;

arch/mips/include/asm/octeon/cvmx-mpi-defs.h line 75

Quoted 10 lines
arch/mips/include/asm/octeon/cvmx-mpi-defs.h new file +10 -0
+               uint64_t idleclks:2;
+               uint64_t tritx:1;
+               uint64_t cslate:1;
+               uint64_t csena0:1;
+               uint64_t csena1:1;
+               uint64_t csena2:1;
+               uint64_t csena3:1;
+               uint64_t clkdiv:13;
+               uint64_t reserved_29_63:35;
+#endif

This boggles my mind, but I see there are many drivers doing this, but using uint64_t looks overly scary.

Can't you break it apart using a set of u32's like in drivers/net/ethernet/micrel/ksz884x.c?

Yours,
Linus Walleij

#9 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

In reply to David Daney
Quoted 3 lines · David Daney

+       mpi_cfg.u64 = 0;
+       mpi_cfg.u64 |= p->cs_enax;
+       if (mpi_cfg.u64 != p->last_cfg) {

But now I see why this 64bit is so clever. Forget the comment on 1/2! This has a certain elegance to it that I just learned to appreciate.

Yours,
Linus Walleij

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#3 lore raw

Re: [PATCH 1/2] MIPS: OCTEON: Add register definitions for SPI host hardware.

In reply to David Daney
Quoted 82 lines · David Daney

From: David Daney <david.daney-YGCgFSpz5w/[email protected]>

Needed by SPI driver.

---
 arch/mips/include/asm/octeon/cvmx-mpi-defs.h |  328 ++++++++++++++++++++++++++
 1 files changed, 328 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/include/asm/octeon/cvmx-mpi-defs.h
arch/mips/include/asm/octeon/cvmx-mpi-defs.h new file +66 -0
new file mode 100644
index 0000000..4615b10
@@ -0,0 +1,328 @@
+/***********************license start***************
+ * Author: Cavium Networks
+ *
+ * Contact: [email protected]
+ * This file is part of the OCTEON SDK
+ *
+ * Copyright (c) 2003-2012 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
+ * NONINFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this file; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * or visit http://www.gnu.org/licenses/.
+ *
+ * This file may also be available under a different license from Cavium.
+ * Contact Cavium Networks for more information
+ ***********************license end**************************************/
+
+#ifndef __CVMX_MPI_DEFS_H__
+#define __CVMX_MPI_DEFS_H__
+
+#define CVMX_MPI_CFG (CVMX_ADD_IO_SEG(0x0001070000001000ull))
+#define CVMX_MPI_DATX(offset) (CVMX_ADD_IO_SEG(0x0001070000001080ull) + ((offset) & 15) * 8)
+#define CVMX_MPI_STS (CVMX_ADD_IO_SEG(0x0001070000001008ull))
+#define CVMX_MPI_TX (CVMX_ADD_IO_SEG(0x0001070000001010ull))
+
+union cvmx_mpi_cfg {
+	uint64_t u64;
+	struct cvmx_mpi_cfg_s {
+#ifdef __BIG_ENDIAN_BITFIELD
+		uint64_t reserved_29_63:35;
+		uint64_t clkdiv:13;
+		uint64_t csena3:1;
+		uint64_t csena2:1;
+		uint64_t csena1:1;
+		uint64_t csena0:1;
+		uint64_t cslate:1;
+		uint64_t tritx:1;
+		uint64_t idleclks:2;
+		uint64_t cshi:1;
+		uint64_t csena:1;
+		uint64_t int_ena:1;
+		uint64_t lsbfirst:1;
+		uint64_t wireor:1;
+		uint64_t clk_cont:1;
+		uint64_t idlelo:1;
+		uint64_t enable:1;
+#else
+		uint64_t enable:1;
+		uint64_t idlelo:1;
+		uint64_t clk_cont:1;
+		uint64_t wireor:1;
+		uint64_t lsbfirst:1;
+		uint64_t int_ena:1;
+		uint64_t csena:1;
+		uint64_t cshi:1;
+		uint64_t idleclks:2;

arch/mips/include/asm/octeon/cvmx-mpi-defs.h line 76

Quoted 10 lines
arch/mips/include/asm/octeon/cvmx-mpi-defs.h new file +10 -0
+		uint64_t tritx:1;
+		uint64_t cslate:1;
+		uint64_t csena0:1;
+		uint64_t csena1:1;
+		uint64_t csena2:1;
+		uint64_t csena3:1;
+		uint64_t clkdiv:13;
+		uint64_t reserved_29_63:35;
+#endif
+	} s;

:-/ I'm not a fan of bitfields for register access. I'd much rather have macros the various bit positions; but given that this live under arch/mips I can't really say much and you can add my acked-by if you need to.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#8 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

In reply to David Daney
Quoted 7 lines · David Daney
Quoted 4 lines · Shubhrajyoti Datta

Hi David,
A few comments.

On Sat, May 12, 2012 at 3:04 AM, David Daney<[email protected]> wrote:

[...]

Quoted 8 lines
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+#define DRV_VERSION "2.0" /* Version 1 was the out-of-tree driver */

This could be given a miss. As it is less meaningful once accepted.

Well, this leads to the question, what is the purpose of the 'MODULE_VERSION()' macro? If I use that, I need to populate it with a value.

Don't use MODULE_VERSION. Just because it is there doesn't mean you need to use it. :-) You'll notice that none of the other spi drivers have it.

g.

Acked-by on v1 2/2
#10 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

In reply to David Daney
Quoted 6 lines · David Daney

From: David Daney <[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

Some comments below, but you can add my a-b:

drivers/spi/spi-octeon.c line 21

Quoted 4 lines
drivers/spi/spi-octeon.c new file +4 -0
+#include <asm/octeon/octeon.h>
+#include <asm/octeon/cvmx-mpi-defs.h>
+
+#define DRV_VERSION "2.0" /* Version 1 was the out-of-tree driver */

As already discussed, drop this line.

Quoted 1 line

+#define DRV_DESCRIPTION "Cavium, Inc. OCTEON SPI bus driver"

Used exactly once. Drop this line and move string to the MODULE_DESCRIPTION().

Quoted 19 lines
drivers/spi/spi-octeon.c new file +19 -0
+static int __devinit octeon_spi_probe(struct platform_device *pdev)
+{
+
+	struct resource *res_mem;
+	struct spi_master *master;
+	struct octeon_spi *p;
+	int err = -ENOENT;
+
+	master = spi_alloc_master(&pdev->dev, sizeof(struct octeon_spi));
+	if (!master)
+		return -ENOMEM;
+	p = spi_master_get_devdata(master);
+	platform_set_drvdata(pdev, p);
+	p->my_master = master;
+
+	res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+	if (res_mem == NULL) {
+		dev_err(&pdev->dev, "found no memory resource\n");

drivers/spi/spi-octeon.c line 301

Quoted 10 lines
drivers/spi/spi-octeon.c new file +10 -0
+		err = -ENXIO;
+		goto fail;
+	}
+	if (!devm_request_mem_region(&pdev->dev, res_mem->start,
+				     resource_size(res_mem), res_mem->name)) {
+		dev_err(&pdev->dev, "request_mem_region failed\n");
+		goto fail;
+	}
+	p->register_base = (u64)devm_ioremap(&pdev->dev, res_mem->start,
+					     resource_size(res_mem));

Nasty cast. p->register_base needs to be an __iomem pointer variable. The fact taht cvmx_read_csr accepts a uint64_t instead of an __iomem pointer looks really wrong. Why is it written that way?

Quoted 39 lines
drivers/spi/spi-octeon.c new file +39 -0
+
+	/* Dynamic bus numbering */
+	master->bus_num = -1;
+	master->num_chipselect = 4;
+	master->mode_bits = SPI_CPHA |
+			    SPI_CPOL |
+			    SPI_CS_HIGH |
+			    SPI_LSB_FIRST |
+			    SPI_3WIRE;
+
+	master->setup = octeon_spi_setup;
+	master->cleanup = octeon_spi_cleanup;
+	master->prepare_transfer_hardware = octeon_spi_nop_transfer_hardware;
+	master->transfer_one_message = octeon_spi_transfer_one_message;
+	master->unprepare_transfer_hardware = octeon_spi_nop_transfer_hardware;
+
+	master->dev.of_node = pdev->dev.of_node;
+	err = spi_register_master(master);
+	if (err) {
+		dev_err(&pdev->dev, "register master failed: %d\n", err);
+		goto fail;
+	}
+
+	dev_info(&pdev->dev, "Version " DRV_VERSION "\n");
+
+	return 0;
+fail:
+	spi_master_put(master);
+	return err;
+}
+
+static int __devexit octeon_spi_remove(struct platform_device *pdev)
+{
+	struct octeon_spi *p = platform_get_drvdata(pdev);
+	struct spi_master *master = p->my_master;
+
+	spi_unregister_master(master);
+
+	/* Clear the CSENA* and put everything in a known state. */

drivers/spi/spi-octeon.c line 350

Quoted 10 lines
drivers/spi/spi-octeon.c new file +10 -0
+	cvmx_write_csr(p->register_base + OCTEON_SPI_CFG, 0);
+	spi_master_put(master);
+	return 0;
+}
+
+static struct of_device_id octeon_spi_match[] = {
+	{
+		.compatible = "cavium,octeon-3010-spi",
+	},
+	{},

Nitpick:

	{ .compatible = "cavium,octeon-3010-spi", },
	{},

No need for the extra lines when it is so short.

drivers/spi/spi-octeon.c line 361

Quoted 11 lines
drivers/spi/spi-octeon.c new file +11 -0
+};
+MODULE_DEVICE_TABLE(of, octeon_spi_match);
+
+static struct platform_driver octeon_spi_driver = {
+	.driver = {
+		.name		= "spi-octeon",
+		.owner		= THIS_MODULE,
+		.of_match_table = octeon_spi_match,
+	},
+	.probe		= octeon_spi_probe,
+	.remove		= __exit_p(octeon_spi_remove),

__devexit_p

Quoted 11 lines
drivers/spi/spi-octeon.c new file +8 -0
+};
+
+module_platform_driver(octeon_spi_driver);
+
+MODULE_DESCRIPTION(DRV_DESCRIPTION);
+MODULE_VERSION(DRV_VERSION);
+MODULE_AUTHOR("David Daney");
+MODULE_LICENSE("GPL");
Signature · 1 line
1.7.2.3
Signature · 2 lines
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.
#13 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

Quoted 10 lines · John Crispin
Quoted 6 lines · David Daney

From: David Daney <[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

Thanks, queued for 3.7.

This cannot go in like this.

There were a bunch of requests by other maintainers that were never done. Also since it is in a foreign subsystem, it at a minimum needs some additional Acked-bys

David Daney

#14 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

Quoted 9 lines · David Daney
Quoted 8 lines · John Crispin
Quoted 6 lines · David Daney

From: David Daney <[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

Quoted 8 lines
Quoted 2 lines

Thanks, queued for 3.7.

This cannot go in like this.

There were a bunch of requests by other maintainers that were never done. Also since it is in a foreign subsystem, it at a minimum needs some additional Acked-bys

hmmm ... you are right about the Acked-by ... i forgot to merge add it ...

i did ask you about this on IRC and you said the driver was ok to be merged like this. inside the thread linus wllej at some point says that his comment was bogus if i am not mistaken ?

John

#15 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

Quoted 19 lines · John Crispin
Quoted 9 lines · David Daney
Quoted 8 lines · John Crispin
Quoted 6 lines · David Daney

From: David Daney <[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

Quoted 8 lines
Quoted 2 lines

Thanks, queued for 3.7.

This cannot go in like this.

There were a bunch of requests by other maintainers that were never done. Also since it is in a foreign subsystem, it at a minimum needs some additional Acked-bys

Quoted 5 lines

hmmm ... you are right about the Acked-by ... i forgot to merge add it ...

i did ask you about this on IRC and you said the driver was ok to be merged like this. inside the thread linus wllej at some point says that his comment was bogus if i am not mistaken ?

OK, I think I won't answer this type of question on IRC in the future. I really should have looked at it in more detail. But at the end of the day, I need to fix it up before it can go in.

David Daney

#16 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

Quoted 27 lines · David Daney
Quoted 19 lines · John Crispin
Quoted 9 lines · David Daney
Quoted 8 lines · John Crispin
Quoted 6 lines · David Daney

From: David Daney <[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

Quoted 8 lines
Quoted 2 lines

Thanks, queued for 3.7.

This cannot go in like this.

There were a bunch of requests by other maintainers that were never done. Also since it is in a foreign subsystem, it at a minimum needs some additional Acked-bys

Quoted 6 lines

hmmm ... you are right about the Acked-by ... i forgot to merge add it
...

i did ask you about this on IRC and you said the driver was ok to be merged like this. inside the thread linus wllej at some point says that his comment was bogus if i am not mistaken ?

Quoted 5 lines

OK, I think I won't answer this type of question on IRC in the future. I really should have looked at it in more detail. But at the end of the day, I need to fix it up before it can go in.

David Daney

i agree, i just removed it from the queue ...

#11 lore raw

Re: [PATCH 2/2] spi: Add SPI master controller for OCTEON SOCs.

In reply to Grant Likely
Quoted 12 lines · Grant Likely
Quoted 6 lines · David Daney

From: David Daney <david.daney-YGCgFSpz5w/[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

Some comments below, but you can add my a-b:

[...]

Quoted 5 lines

drivers/spi/spi-octeon.c line 301

Quoted 2 lines
drivers/spi/spi-octeon.c new file +2 -0
+	p->register_base = (u64)devm_ioremap(&pdev->dev, res_mem->start,
+					     resource_size(res_mem));

Nasty cast. p->register_base needs to be an __iomem pointer variable.

No, it is only ever used as an argument to cvmx_{read,write}_csr(), which want the u64 type.

Quoted 2 lines

The fact taht cvmx_read_csr accepts a uint64_t instead of
an __iomem pointer looks really wrong. Why is it written that way?

Register addresses on OCTEON are 64-bits wide. In a 32-bit kernel, pointers are only 32-bits wide. Thus was born the cvmx_read_csr() function that takes a u64 address.

We no longer support 32-bit kernels, but the legacy of the interface lives on.

David Daney

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#17 lore raw

Re: [2/2] spi: Add SPI master controller for OCTEON SOCs.

In reply to David Daney
Quoted 8 lines · David Daney

From: David Daney <[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

[ ... ]

drivers/spi/spi-octeon.c line 339

Quoted 8 lines
drivers/spi/spi-octeon.c new file +8 -0
+
+static int __devexit octeon_spi_remove(struct platform_device *pdev)
+{
+	struct octeon_spi *p = platform_get_drvdata(pdev);
+	struct spi_master *master = p->my_master;
+
+	spi_unregister_master(master);
+

I know it is a bit late, but ...

The call to spi_unregister_master() frees the memory associated with master, ie 'p', and the spi_master_put() below without matching spi_master_get() is unnecessary/wrong. One possible fix would be to use

	struct spi_master *master = spi_master_get(p->my_master);

above. That protects master and p while it is still being used, and makes use of the call to spi_master_put() below. Another option might be to move cvmx_write_csr() ahead of the call to spi_unregister_master() and drop the call to spi_master_put().

Guenter

Quoted 6 lines
drivers/spi/spi-octeon.c new file +6 -0
+	/* Clear the CSENA* and put everything in a known state. */
+	cvmx_write_csr(p->register_base + OCTEON_SPI_CFG, 0);
+	spi_master_put(master);
+	return 0;
+}
+
#18 lore raw

Re: [2/2] spi: Add SPI master controller for OCTEON SOCs.

Quoted 11 lines · Guenter Roeck
Quoted 8 lines · David Daney

From: David Daney <[email protected]>

Add the driver, link it into the kbuild system and provide device tree binding documentation.

[ ... ]

Quoted 10 lines

drivers/spi/spi-octeon.c line 339

Quoted 8 lines
drivers/spi/spi-octeon.c new file +8 -0
+
+static int __devexit octeon_spi_remove(struct platform_device *pdev)
+{
+	struct octeon_spi *p = platform_get_drvdata(pdev);
+	struct spi_master *master = p->my_master;
+
+	spi_unregister_master(master);
+

I know it is a bit late, but ...

In this case, just in time. I am now finally getting back to fixing the issues with this driver, and looking to merging it in the near future.

David Daney

Quoted 21 lines

The call to spi_unregister_master() frees the memory associated with master, ie 'p', and the spi_master_put() below without matching spi_master_get() is unnecessary/wrong. One possible fix would be to use

	struct spi_master *master = spi_master_get(p->my_master);

above. That protects master and p while it is still being used, and makes use of the call to spi_master_put() below. Another option might be to move cvmx_write_csr() ahead of the call to spi_unregister_master() and drop the call to spi_master_put().

Guenter

Quoted 6 lines
drivers/spi/spi-octeon.c new file +6 -0
+	/* Clear the CSENA* and put everything in a known state. */
+	cvmx_write_csr(p->register_base + OCTEON_SPI_CFG, 0);
+	spi_master_put(master);
+	return 0;
+}
+