[patch v26 0/4] JTAG driver introduction

2018-06-15 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/gpio-cdev|1 -
 Documentation/ABI/testing/jtag-dev |   23 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   27 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   31 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  756 
 drivers/jtag/jtag.c|  274 +++
 include/linux/jtag.h   |   41 ++
 include/uapi/linux/jtag.h  |  109 +++
 15 files changed, 1409 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mo

[patch v26 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-06-15 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v21->v22
v20->v21
v19->v20
v18->v19

v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 MAINTAINERS|1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index e7b8b2c..a5e5f75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7617,6 +7617,7 @@ S:Maintained
 F: include/linux/jtag.h
 F: include/uapi/linux/jtag.h
 F: drivers/jtag/
+F: Documentation/devicetree/bindings/jtag/
 
 K10TEMP HARDWARE MONITORING DRIVER
 M: Clemens Ladisch 
-- 
1.7.1



[patch v26 0/4] JTAG driver introduction

2018-06-15 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/gpio-cdev|1 -
 Documentation/ABI/testing/jtag-dev |   23 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   27 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   31 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  756 
 drivers/jtag/jtag.c|  274 +++
 include/linux/jtag.h   |   41 ++
 include/uapi/linux/jtag.h  |  109 +++
 15 files changed, 1409 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mo

[patch v26 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-06-15 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v21->v22
v20->v21
v19->v20
v18->v19

v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 MAINTAINERS|1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index e7b8b2c..a5e5f75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7617,6 +7617,7 @@ S:Maintained
 F: include/linux/jtag.h
 F: include/uapi/linux/jtag.h
 F: drivers/jtag/
+F: Documentation/devicetree/bindings/jtag/
 
 K10TEMP HARDWARE MONITORING DRIVER
 M: Clemens Ladisch 
-- 
1.7.1



[patch v25 0/4] JTAG driver introduction

2018-05-29 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/gpio-cdev|1 -
 Documentation/ABI/testing/jtag-dev |   23 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   27 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   31 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  756 
 drivers/jtag/jtag.c|  274 +++
 include/linux/jtag.h   |   41 ++
 include/uapi/linux/jtag.h  |  109 +++
 15 files changed, 1409 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mo

[patch v25 0/4] JTAG driver introduction

2018-05-29 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/gpio-cdev|1 -
 Documentation/ABI/testing/jtag-dev |   23 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   27 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   31 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  756 
 drivers/jtag/jtag.c|  274 +++
 include/linux/jtag.h   |   41 ++
 include/uapi/linux/jtag.h  |  109 +++
 15 files changed, 1409 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mo

RE: [patch v22 1/4] drivers: jtag: Add JTAG core driver

2018-05-28 Thread Oleksandr Shamray
Hi Greg.

Thanks for your review.
Please see my comments inline.

Best Regards,
Oleksandr Shamray

> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: 28 мая 2018 г. 15:35
> To: Oleksandr Shamray <oleksan...@mellanox.com>
> Cc: a...@arndb.de; linux-kernel@vger.kernel.org; linux-arm-
> ker...@lists.infradead.org; devicet...@vger.kernel.org;
> open...@lists.ozlabs.org; j...@jms.id.au; j...@resnulli.us;
> tklau...@distanz.ch; linux-ser...@vger.kernel.org; Vadim Pasternak
> <vad...@mellanox.com>; system-sw-low-level  le...@mellanox.com>; robh...@kernel.org; openocd-devel-
> ow...@lists.sourceforge.net; linux-...@vger.kernel.org;
> da...@davemloft.net; mche...@kernel.org
> Subject: Re: [patch v22 1/4] drivers: jtag: Add JTAG core driver
> 
> On Mon, May 28, 2018 at 01:34:09PM +0300, Oleksandr Shamray wrote:
> > Initial patch for JTAG driver
> > JTAG class driver provide infrastructure to support hardware/software
> > JTAG platform drivers. It provide user layer API interface for
> > flashing and debugging external devices which equipped with JTAG
> > interface using standard transactions.
> >
> > Driver exposes set of IOCTL to user space for:
> > - XFER:
> > - SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
> > - SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
> > - RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
> >   number of clocks).
> > - SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.
> >
> > Driver core provides set of internal APIs for allocation and
> > registration:
> > - jtag_register;
> > - jtag_unregister;
> > - jtag_alloc;
> > - jtag_free;
> >
> > Platform driver on registration with jtag-core creates the next entry
> > in dev folder:
> > /dev/jtagX
> >
> > Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
> > Signed-off-by: Jiri Pirko <j...@mellanox.com>
> > Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
> > ---
> > v21->v22
> 
> 22 versions, way to stick with this...
> 
> Anyway, time to review it again.  I feel it's really close, but I don't want 
> to
> apply it yet as the api feels odd in places.  If others have asked you to make
> these changes to look like this, I'm sorry, then please push back on me:
> 
> > +/*
> > + * JTAG core driver supports up to 256 devices
> > + * JTAG device name will be in range jtag0-jtag255
> > + * Set maximum len of jtag id to 3
> > + */
> > +
> > +#define MAX_JTAG_DEVS  255
> 
> Why have a max at all?  You should be able to just dynamically allocate them.
> Anyway, if you do want a max, you need to be able to properly keep the max
> number, and right now you have a race when registering (you check the
> number, and then much later do you increment it, a pointless use of an
> atomic value if I've ever seen one...)
> 

You are right. It's not good idea to have restriction of max dev number.
I will remove all regarding It.

> > +#define MAX_JTAG_NAME_LEN (sizeof("jtag") + 3)
> > +
> > +struct jtag {
> > +   struct miscdevice miscdev;
> 
> If you are a miscdev, why even have a max number?  Just let the max
> number of miscdev devices rule things.
> 
> > +   const struct jtag_ops *ops;
> > +   int id;
> > +   bool opened;
> 
> You shouldn't care about this, but ok...

Jtag HW not support to using with multiple requests from different users. So we 
prohibit this.

> 
> > +   struct mutex open_lock;
> > +   unsigned long priv[0];
> > +};
> > +
> > +static DEFINE_IDA(jtag_ida);
> > +
> > +static atomic_t jtag_refcount = ATOMIC_INIT(0);
> 
> Either use it as an atomic properly (test_and_set), or just leave it as an 
> int, or
> better yet, don't use it at all.

It will be removed.

> 
> > +void *jtag_priv(struct jtag *jtag)
> > +{
> > +   return jtag->priv;
> > +}
> > +EXPORT_SYMBOL_GPL(jtag_priv);
> 
> Api naming issue here.  Traditionally this is a "get/set_drvdata" type 
> function,
> as in dev_get_drvdata(), or dev_set_drvdata.  But, you are right in that the
> network stack has a netdev_priv() call, where you probably copied this idea
> from.
> 
> I don't know, I guess it's ok as-is, as it's the way networking does it, it's 
> your
> call though.
> 

Yes,  I did as in networking. 

> > +static long jtag_ioctl(struct file *file, unsigned int cmd, unsigned
> > +long arg) {
> > +   struct jtag *jtag = file->private_data;
> > +   struct jtag_run_test_idle idle;
> 

RE: [patch v22 1/4] drivers: jtag: Add JTAG core driver

2018-05-28 Thread Oleksandr Shamray
Hi Greg.

Thanks for your review.
Please see my comments inline.

Best Regards,
Oleksandr Shamray

> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: 28 мая 2018 г. 15:35
> To: Oleksandr Shamray 
> Cc: a...@arndb.de; linux-kernel@vger.kernel.org; linux-arm-
> ker...@lists.infradead.org; devicet...@vger.kernel.org;
> open...@lists.ozlabs.org; j...@jms.id.au; j...@resnulli.us;
> tklau...@distanz.ch; linux-ser...@vger.kernel.org; Vadim Pasternak
> ; system-sw-low-level  le...@mellanox.com>; robh...@kernel.org; openocd-devel-
> ow...@lists.sourceforge.net; linux-...@vger.kernel.org;
> da...@davemloft.net; mche...@kernel.org
> Subject: Re: [patch v22 1/4] drivers: jtag: Add JTAG core driver
> 
> On Mon, May 28, 2018 at 01:34:09PM +0300, Oleksandr Shamray wrote:
> > Initial patch for JTAG driver
> > JTAG class driver provide infrastructure to support hardware/software
> > JTAG platform drivers. It provide user layer API interface for
> > flashing and debugging external devices which equipped with JTAG
> > interface using standard transactions.
> >
> > Driver exposes set of IOCTL to user space for:
> > - XFER:
> > - SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
> > - SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
> > - RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
> >   number of clocks).
> > - SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.
> >
> > Driver core provides set of internal APIs for allocation and
> > registration:
> > - jtag_register;
> > - jtag_unregister;
> > - jtag_alloc;
> > - jtag_free;
> >
> > Platform driver on registration with jtag-core creates the next entry
> > in dev folder:
> > /dev/jtagX
> >
> > Signed-off-by: Oleksandr Shamray 
> > Signed-off-by: Jiri Pirko 
> > Acked-by: Philippe Ombredanne 
> > ---
> > v21->v22
> 
> 22 versions, way to stick with this...
> 
> Anyway, time to review it again.  I feel it's really close, but I don't want 
> to
> apply it yet as the api feels odd in places.  If others have asked you to make
> these changes to look like this, I'm sorry, then please push back on me:
> 
> > +/*
> > + * JTAG core driver supports up to 256 devices
> > + * JTAG device name will be in range jtag0-jtag255
> > + * Set maximum len of jtag id to 3
> > + */
> > +
> > +#define MAX_JTAG_DEVS  255
> 
> Why have a max at all?  You should be able to just dynamically allocate them.
> Anyway, if you do want a max, you need to be able to properly keep the max
> number, and right now you have a race when registering (you check the
> number, and then much later do you increment it, a pointless use of an
> atomic value if I've ever seen one...)
> 

You are right. It's not good idea to have restriction of max dev number.
I will remove all regarding It.

> > +#define MAX_JTAG_NAME_LEN (sizeof("jtag") + 3)
> > +
> > +struct jtag {
> > +   struct miscdevice miscdev;
> 
> If you are a miscdev, why even have a max number?  Just let the max
> number of miscdev devices rule things.
> 
> > +   const struct jtag_ops *ops;
> > +   int id;
> > +   bool opened;
> 
> You shouldn't care about this, but ok...

Jtag HW not support to using with multiple requests from different users. So we 
prohibit this.

> 
> > +   struct mutex open_lock;
> > +   unsigned long priv[0];
> > +};
> > +
> > +static DEFINE_IDA(jtag_ida);
> > +
> > +static atomic_t jtag_refcount = ATOMIC_INIT(0);
> 
> Either use it as an atomic properly (test_and_set), or just leave it as an 
> int, or
> better yet, don't use it at all.

It will be removed.

> 
> > +void *jtag_priv(struct jtag *jtag)
> > +{
> > +   return jtag->priv;
> > +}
> > +EXPORT_SYMBOL_GPL(jtag_priv);
> 
> Api naming issue here.  Traditionally this is a "get/set_drvdata" type 
> function,
> as in dev_get_drvdata(), or dev_set_drvdata.  But, you are right in that the
> network stack has a netdev_priv() call, where you probably copied this idea
> from.
> 
> I don't know, I guess it's ok as-is, as it's the way networking does it, it's 
> your
> call though.
> 

Yes,  I did as in networking. 

> > +static long jtag_ioctl(struct file *file, unsigned int cmd, unsigned
> > +long arg) {
> > +   struct jtag *jtag = file->private_data;
> > +   struct jtag_run_test_idle idle;
> > +   struct jtag_xfer xfer;
> > +   u8 *xfer_data;
> > +   u32 data_size;
> > +   u32 value;
> > +   int err;
> > +
> >

[patch v22 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-28 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Rob Herring <r...@kernel.org>
---
v21->v22
v20->v21
v19->v20
v18->v19

v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley <joel.s...@gmail.com>
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring <r...@kernel.org>
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring <r...@kernel.org>
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 MAINTAINERS|1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index e7b8b2c..a5e5f75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7617,6 +7617,7 @@ S:Maintained
 F: include/linux/jtag.h
 F: include/uapi/linux/jtag.h
 F: drivers/jtag/
+F: Documentation/devicetree/bindings/jtag/
 
 K10TEMP HARDWARE MONITORING DRIVER
 M: Clemens Ladisch <clem...@ladisch.de>
-- 
1.7.1



[patch v22 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-28 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v21->v22
v20->v21
v19->v20
v18->v19

v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 MAINTAINERS|1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index e7b8b2c..a5e5f75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7617,6 +7617,7 @@ S:Maintained
 F: include/linux/jtag.h
 F: include/uapi/linux/jtag.h
 F: drivers/jtag/
+F: Documentation/devicetree/bindings/jtag/
 
 K10TEMP HARDWARE MONITORING DRIVER
 M: Clemens Ladisch 
-- 
1.7.1



[patch v22 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-28 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
Acked-by: Joel Stanley <j...@jms.id.au>
---
v21->v22
Comments pointed by Andy Shevchenko <andy.shevche...@gmail.com>
- rearrange ASPEED register defines
- simplified JTAG divider calculation formula
- change delay function in bit-bang operation
- add helper functions for TAP states switching
- remove unnecessary comments
- remove redundant debug messages
- make dines for repetative register bit sets
- fixed indentation
- change checks from negative to positive
- add error check for clk_prepare_enable
- rework driver alloc/register to devm_ variant
- Increasing line length up to 85 in order to improve readability

v20->v21
v19->v20
Notifications from kbuild test robot <l...@intel.com>
- add static declaration to 'aspeed_jtag_init' and
  'aspeed_jtag_deinit' functions

v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license- add reset descriptions in bndings file
 in description
Comments pointed by Kun Yi <ku...@google.com>
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann <a...@arndb.de>
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot <l...@intel.com>
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  769 
 3 files changed, 784 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 47771fc..0cc163f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -15,3 +15,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfi

[patch v22 0/4] JTAG driver introduction

2018-05-28 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   31 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  769 
 drivers/jtag/jtag.c|  322 
 include/linux/jtag.h   |   43 ++
 include/uapi/linux/jtag.h  |  102 +++
 14 files changed, 1470 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/u

[patch v22 0/4] JTAG driver introduction

2018-05-28 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   31 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  769 
 drivers/jtag/jtag.c|  322 
 include/linux/jtag.h   |   43 ++
 include/uapi/linux/jtag.h  |  102 +++
 14 files changed, 1470 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/u

[patch v22 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-28 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Arnd Bergmann 
Acked-by: Philippe Ombredanne 
Acked-by: Joel Stanley 
---
v21->v22
Comments pointed by Andy Shevchenko 
- rearrange ASPEED register defines
- simplified JTAG divider calculation formula
- change delay function in bit-bang operation
- add helper functions for TAP states switching
- remove unnecessary comments
- remove redundant debug messages
- make dines for repetative register bit sets
- fixed indentation
- change checks from negative to positive
- add error check for clk_prepare_enable
- rework driver alloc/register to devm_ variant
- Increasing line length up to 85 in order to improve readability

v20->v21
v19->v20
Notifications from kbuild test robot 
- add static declaration to 'aspeed_jtag_init' and
  'aspeed_jtag_deinit' functions

v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley 
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license- add reset descriptions in bndings file
 in description
Comments pointed by Kun Yi 
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey 
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann 
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley 
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot 
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann 
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH 
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong 
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann 
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap 
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot 
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  769 
 3 files changed, 784 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 47771fc..0cc163f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -15,3 +15,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   help
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/dr

[patch v22 1/4] drivers: jtag: Add JTAG core driver

2018-05-28 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v21->v22
Comments pointed by Andy Shevchenko <andy.shevche...@gmail.com>
- Fix 0x0f -> 0x0F in ioctl-number.txt
- Add description to #define MAX_JTAG_NAME_LEN
- Remove unnecessary entry *dev from struct jtag
- Remove redundant parens
- Described mandatory callbacks and removed unnecessary
- Set JTAG_MAX_XFER_DATA_LEN to power of 2
- rework driver alloc/register to devm_ variant
- increasing line length up to 84 in order to improve readability.

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- fix spell in ABI doccumentation

v20->v21
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

Notifications from kbuild test robot <l...@intel.com>
- fix incompatible type casts

v18->v19
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Comments pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add single open per device blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- Add include types.h header to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fi

[patch v22 1/4] drivers: jtag: Add JTAG core driver

2018-05-28 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v21->v22
Comments pointed by Andy Shevchenko 
- Fix 0x0f -> 0x0F in ioctl-number.txt
- Add description to #define MAX_JTAG_NAME_LEN
- Remove unnecessary entry *dev from struct jtag
- Remove redundant parens
- Described mandatory callbacks and removed unnecessary
- Set JTAG_MAX_XFER_DATA_LEN to power of 2
- rework driver alloc/register to devm_ variant
- increasing line length up to 84 in order to improve readability.

Comments pointed by Randy Dunlap 
- fix spell in ABI doccumentation

v20->v21
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

Notifications from kbuild test robot 
- fix incompatible type casts

v18->v19
Comments pointed by Julia Cartwright 
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright 
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright 
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Comments pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Comments pointed by Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add single open per device blocking

v10->v11
Notifications from kbuild test robot 
- Add include types.h header to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 

[patch v22 4/4] Documentation: jtag: Add ABI documentation

2018-05-28 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
---
v21->v22
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- fix spell in ABI doccumentation

v20->v21
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG doccumentation

v18->v19
Pavel Machek <pa...@ucw.cz>
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12 Tobias Klauser <tklau...@distanz.ch>
Comments pointed by
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update KernelVersion and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek <pa...@ucw.cz>
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 
 MAINTAINERS|1 +
 4 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..42b487a
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,28 @@
+Linux kernel JTAG support
+=
+
+The JTAG is an industry standard for verifying hardware.
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional
+
+JTAG interface is designed to have two parts - basic core driver and
+hardware specific driver. The basic driver introduces a general interface
+which is not dependent of specific hardware. It provides communication
+between user space and hardware specific driver.
+Each JTAG device is represented as a char device from (jtag0, jtag1, ...).
+Access to a JTAG device is performed through IOCTL calls.
+
+Call flow example:
+User: open  -> /dev/jatgX
+User: ioctl -> /dev/jtagX -> JTAG core driver -> JTAG hardware specific driver
+User: close -> /dev/jatgX
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..2abf833
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,109 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN.
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Two or more open for one device will return error.
+
+Open/Close  device:
+- jtag_fd = open("/dev/jtag0", O_RDWR);
+- close(jtag_fd);
+
+ioctl()
+---
+All access operations to JTAG devices performed through ioctl interface.
+The IOCTL interface supports these requests:
+   JTAG_IOCRUNTEST - Force J

[patch v22 4/4] Documentation: jtag: Add ABI documentation

2018-05-28 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray 
Acked-by: Arnd Bergmann 
---
v21->v22
Comments pointed by Randy Dunlap 
- fix spell in ABI doccumentation

v20->v21
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap 
- Fix JTAG doccumentation

v18->v19
Pavel Machek 
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12 Tobias Klauser 
Comments pointed by
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update KernelVersion and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek 
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 
 MAINTAINERS|1 +
 4 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..42b487a
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,28 @@
+Linux kernel JTAG support
+=
+
+The JTAG is an industry standard for verifying hardware.
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional
+
+JTAG interface is designed to have two parts - basic core driver and
+hardware specific driver. The basic driver introduces a general interface
+which is not dependent of specific hardware. It provides communication
+between user space and hardware specific driver.
+Each JTAG device is represented as a char device from (jtag0, jtag1, ...).
+Access to a JTAG device is performed through IOCTL calls.
+
+Call flow example:
+User: open  -> /dev/jatgX
+User: ioctl -> /dev/jtagX -> JTAG core driver -> JTAG hardware specific driver
+User: close -> /dev/jatgX
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..2abf833
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,109 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN.
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Two or more open for one device will return error.
+
+Open/Close  device:
+- jtag_fd = open("/dev/jtag0", O_RDWR);
+- close(jtag_fd);
+
+ioctl()
+---
+All access operations to JTAG devices performed through ioctl interface.
+The IOCTL interface supports these requests:
+   JTAG_IOCRUNTEST - Force JTAG state machine to RUN_TEST/IDLE state
+   JTAG_SIOCFREQ - Set JTAG TCK frequency
+   JTAG_GIOCFREQ - Get JTAG TCK frequency
+   JTAG_IOCXFER - send JTAG data Xfer
+   JTAG_GIOCSTAT

[patch v22 1/4] drivers: jtag: Add JTAG core driver

2018-05-28 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v21->v22
Comments pointed by Andy Shevchenko <andy.shevche...@gmail.com>
- Fix 0x0f -> 0x0F in ioctl-number.txt
- Add description to #define MAX_JTAG_NAME_LEN
- Remove unnecessary entry *dev from struct jtag
- Remove redundant parens
- Described mandatory callbacks and removed unnecessary
- Set JTAG_MAX_XFER_DATA_LEN to power of 2
- rework driver alloc/register to devm_ variant
- increasing line length up to 84 in order to improve readability.

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- fix spell in ABI doccumentation

v20->v21
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

Notifications from kbuild test robot <l...@intel.com>
- fix incompatible type casts

v18->v19
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Comments pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add single open per device blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- Add include types.h header to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fi

[patch v22 1/4] drivers: jtag: Add JTAG core driver

2018-05-28 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v21->v22
Comments pointed by Andy Shevchenko 
- Fix 0x0f -> 0x0F in ioctl-number.txt
- Add description to #define MAX_JTAG_NAME_LEN
- Remove unnecessary entry *dev from struct jtag
- Remove redundant parens
- Described mandatory callbacks and removed unnecessary
- Set JTAG_MAX_XFER_DATA_LEN to power of 2
- rework driver alloc/register to devm_ variant
- increasing line length up to 84 in order to improve readability.

Comments pointed by Randy Dunlap 
- fix spell in ABI doccumentation

v20->v21
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

Notifications from kbuild test robot 
- fix incompatible type casts

v18->v19
Comments pointed by Julia Cartwright 
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright 
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright 
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Comments pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Comments pointed by Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add single open per device blocking

v10->v11
Notifications from kbuild test robot 
- Add include types.h header to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 

[patch v22 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-28 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
Acked-by: Joel Stanley <j...@jms.id.au>
---
v21->v22
Comments pointed by Andy Shevchenko <andy.shevche...@gmail.com>
- rearrange ASPEED register defines
- simplified JTAG divider calculation formula
- change delay function in bit-bang operation
- add helper functions for TAP states switching
- remove unnecessary comments
- remove redundant debug messages
- make dines for repetative register bit sets
- fixed indentation
- change checks from negative to positive
- add error check for clk_prepare_enable
- rework driver alloc/register to devm_ variant
- Increasing line length up to 85 in order to improve readability

v20->v21
v19->v20
Notifications from kbuild test robot <l...@intel.com>
- add static declaration to 'aspeed_jtag_init' and
  'aspeed_jtag_deinit' functions

v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license- add reset descriptions in bndings file
 in description
Comments pointed by Kun Yi <ku...@google.com>
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann <a...@arndb.de>
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot <l...@intel.com>
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  769 
 3 files changed, 784 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 47771fc..0cc163f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -15,3 +15,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfi

[patch v22 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-28 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Arnd Bergmann 
Acked-by: Philippe Ombredanne 
Acked-by: Joel Stanley 
---
v21->v22
Comments pointed by Andy Shevchenko 
- rearrange ASPEED register defines
- simplified JTAG divider calculation formula
- change delay function in bit-bang operation
- add helper functions for TAP states switching
- remove unnecessary comments
- remove redundant debug messages
- make dines for repetative register bit sets
- fixed indentation
- change checks from negative to positive
- add error check for clk_prepare_enable
- rework driver alloc/register to devm_ variant
- Increasing line length up to 85 in order to improve readability

v20->v21
v19->v20
Notifications from kbuild test robot 
- add static declaration to 'aspeed_jtag_init' and
  'aspeed_jtag_deinit' functions

v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley 
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license- add reset descriptions in bndings file
 in description
Comments pointed by Kun Yi 
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey 
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann 
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley 
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot 
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann 
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH 
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong 
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann 
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap 
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot 
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  769 
 3 files changed, 784 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 47771fc..0cc163f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -15,3 +15,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   help
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/dr

[patch v22 0/4] JTAG driver introduction

2018-05-28 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   31 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  769 
 drivers/jtag/jtag.c|  322 
 include/linux/jtag.h   |   42 ++
 include/uapi/linux/jtag.h  |  102 +++
 14 files changed, 1469 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/u

[patch v22 0/4] JTAG driver introduction

2018-05-28 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   31 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  769 
 drivers/jtag/jtag.c|  322 
 include/linux/jtag.h   |   42 ++
 include/uapi/linux/jtag.h  |  102 +++
 14 files changed, 1469 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/u

[patch v22 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-28 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Rob Herring <r...@kernel.org>
---
v21->v22
v20->v21
v19->v20
v18->v19

v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley <joel.s...@gmail.com>
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring <r...@kernel.org>
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring <r...@kernel.org>
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 MAINTAINERS|1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index e7b8b2c..a5e5f75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7617,6 +7617,7 @@ S:Maintained
 F: include/linux/jtag.h
 F: include/uapi/linux/jtag.h
 F: drivers/jtag/
+F: Documentation/devicetree/bindings/jtag/
 
 K10TEMP HARDWARE MONITORING DRIVER
 M: Clemens Ladisch <clem...@ladisch.de>
-- 
1.7.1



[patch v22 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-28 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v21->v22
v20->v21
v19->v20
v18->v19

v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 MAINTAINERS|1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index e7b8b2c..a5e5f75 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7617,6 +7617,7 @@ S:Maintained
 F: include/linux/jtag.h
 F: include/uapi/linux/jtag.h
 F: drivers/jtag/
+F: Documentation/devicetree/bindings/jtag/
 
 K10TEMP HARDWARE MONITORING DRIVER
 M: Clemens Ladisch 
-- 
1.7.1



[patch v22 4/4] Documentation: jtag: Add ABI documentation

2018-05-28 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
---
v21->v22
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- fix spell in ABI doccumentation

v20->v21
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG doccumentation

v18->v19
Pavel Machek <pa...@ucw.cz>
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12 Tobias Klauser <tklau...@distanz.ch>
Comments pointed by
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update KernelVersion and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek <pa...@ucw.cz>
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 
 MAINTAINERS|1 +
 4 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..42b487a
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,28 @@
+Linux kernel JTAG support
+=
+
+The JTAG is an industry standard for verifying hardware.
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional
+
+JTAG interface is designed to have two parts - basic core driver and
+hardware specific driver. The basic driver introduces a general interface
+which is not dependent of specific hardware. It provides communication
+between user space and hardware specific driver.
+Each JTAG device is represented as a char device from (jtag0, jtag1, ...).
+Access to a JTAG device is performed through IOCTL calls.
+
+Call flow example:
+User: open  -> /dev/jatgX
+User: ioctl -> /dev/jtagX -> JTAG core driver -> JTAG hardware specific driver
+User: close -> /dev/jatgX
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..2abf833
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,109 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN.
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Two or more open for one device will return error.
+
+Open/Close  device:
+- jtag_fd = open("/dev/jtag0", O_RDWR);
+- close(jtag_fd);
+
+ioctl()
+---
+All access operations to JTAG devices performed through ioctl interface.
+The IOCTL interface supports these requests:
+   JTAG_IOCRUNTEST - Force J

[patch v22 4/4] Documentation: jtag: Add ABI documentation

2018-05-28 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray 
Acked-by: Arnd Bergmann 
---
v21->v22
Comments pointed by Randy Dunlap 
- fix spell in ABI doccumentation

v20->v21
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap 
- Fix JTAG doccumentation

v18->v19
Pavel Machek 
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12 Tobias Klauser 
Comments pointed by
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update KernelVersion and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek 
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 
 MAINTAINERS|1 +
 4 files changed, 165 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..42b487a
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,28 @@
+Linux kernel JTAG support
+=
+
+The JTAG is an industry standard for verifying hardware.
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional
+
+JTAG interface is designed to have two parts - basic core driver and
+hardware specific driver. The basic driver introduces a general interface
+which is not dependent of specific hardware. It provides communication
+between user space and hardware specific driver.
+Each JTAG device is represented as a char device from (jtag0, jtag1, ...).
+Access to a JTAG device is performed through IOCTL calls.
+
+Call flow example:
+User: open  -> /dev/jatgX
+User: ioctl -> /dev/jtagX -> JTAG core driver -> JTAG hardware specific driver
+User: close -> /dev/jatgX
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..2abf833
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,109 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN.
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Two or more open for one device will return error.
+
+Open/Close  device:
+- jtag_fd = open("/dev/jtag0", O_RDWR);
+- close(jtag_fd);
+
+ioctl()
+---
+All access operations to JTAG devices performed through ioctl interface.
+The IOCTL interface supports these requests:
+   JTAG_IOCRUNTEST - Force JTAG state machine to RUN_TEST/IDLE state
+   JTAG_SIOCFREQ - Set JTAG TCK frequency
+   JTAG_GIOCFREQ - Get JTAG TCK frequency
+   JTAG_IOCXFER - send JTAG data Xfer
+   JTAG_GIOCSTAT

RE: [patch v21 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-22 Thread Oleksandr Shamray
Hi Andy. 
Thanks for review.

Please read my answers inline.

> -Original Message-
> From: Andy Shevchenko [mailto:andy.shevche...@gmail.com]
> Sent: 16 мая 2018 г. 0:00
> To: Oleksandr Shamray <oleksan...@mellanox.com>
> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>; Arnd Bergmann 
> <a...@arndb.de>; Linux Kernel Mailing List 
> <linux-kernel@vger.kernel.org>; linux-arm Mailing List 
> <linux-arm-ker...@lists.infradead.org>; devicetree 
> <devicet...@vger.kernel.org>; open...@lists.ozlabs.org; Joel Stanley 
> <j...@jms.id.au>; Jiří Pírko <j...@resnulli.us>; Tobias Klauser 
> <tklau...@distanz.ch>; open list:SERIAL DRIVERS  ser...@vger.kernel.org>; Vadim Pasternak <vad...@mellanox.com>; 
> system-sw-low-level <system-sw-low-le...@mellanox.com>; Rob Herring 
> <robh...@kernel.org>; openocd-devel-ow...@lists.sourceforge.net; 
> linux- a...@vger.kernel.org; David S. Miller <da...@davemloft.net>; 
> Mauro Carvalho Chehab <mche...@kernel.org>; Jiri Pirko 
> <j...@mellanox.com>
> Subject: Re: [patch v21 2/4] drivers: jtag: Add Aspeed SoC 24xx and 
> 25xx families JTAG master driver
> 
> On Tue, May 15, 2018 at 5:21 PM, Oleksandr Shamray 
> <oleksan...@mellanox.com> wrote:
> > Driver adds support of Aspeed 2500/2400 series SOC JTAG master
> controller.
> >
> > Driver implements the following jtag ops:
> > - freq_get;
> > - freq_set;
> > - status_get;
> > - idle;
> > - xfer;
> >
> > It has been tested on Mellanox system with BMC equipped with Aspeed
> > 2520 SoC for programming CPLD devices.
> 
> > +#define ASPEED_JTAG_DATA   0x00
> > +#define ASPEED_JTAG_INST   0x04
> > +#define ASPEED_JTAG_CTRL   0x08
> > +#define ASPEED_JTAG_ISR0x0C
> > +#define ASPEED_JTAG_SW 0x10
> > +#define ASPEED_JTAG_TCK0x14
> > +#define ASPEED_JTAG_EC 0x18
> > +
> > +#define ASPEED_JTAG_DATA_MSB   0x01
> > +#define ASPEED_JTAG_DATA_CHUNK_SIZE0x20
> 
> 
> > +#define ASPEED_JTAG_IOUT_LEN(len)  (ASPEED_JTAG_CTL_ENG_EN |\
> > +ASPEED_JTAG_CTL_ENG_OUT_EN 
> > +|\
> > +
> > +ASPEED_JTAG_CTL_INST_LEN(len))
> 
> Better to read
> 
> #define MY_COOL_CONST_OR_MACRO(xxx) \
>  ...
> 
> > +#define ASPEED_JTAG_DOUT_LEN(len)  (ASPEED_JTAG_CTL_ENG_EN
> |\
> > +ASPEED_JTAG_CTL_ENG_OUT_EN 
> > + |\
> > +
> > +ASPEED_JTAG_CTL_DATA_LEN(len))
> 
> Ditto.

Ok. Changed to:
#define ASPEED_JTAG_IOUT_LEN(len) \
   (ASPEED_JTAG_CTL_ENG_EN | \
   ASPEED_JTAG_CTL_ENG_OUT_EN | \
   ASPEED_JTAG_CTL_INST_LEN(len))

#define ASPEED_JTAG_DOUT_LEN(len) \
   (ASPEED_JTAG_CTL_ENG_EN | \
   ASPEED_JTAG_CTL_ENG_OUT_EN | \
   ASPEED_JTAG_CTL_DATA_LEN(len))


> 
> > +static char *end_status_str[] = {"idle", "ir pause", "drpause"};
> 
> > +static int aspeed_jtag_freq_set(struct jtag *jtag, u32 freq) {
> > +   struct aspeed_jtag *aspeed_jtag = jtag_priv(jtag);
> > +   unsigned long apb_frq;
> > +   u32 tck_val;
> > +   u16 div;
> > +
> > +   apb_frq = clk_get_rate(aspeed_jtag->pclk);
> 
> > +   div = (apb_frq % freq == 0) ? (apb_frq / freq) - 1 : 
> > + (apb_frq / freq);
> 
> Isn't it the same as
> 
> div = (apb_frq - 1) / freq;
> 
> ?
> 

Seems it is same. Thanks.

> > +   tck_val = aspeed_jtag_read(aspeed_jtag, ASPEED_JTAG_TCK);
> > +   aspeed_jtag_write(aspeed_jtag,
> > + (tck_val & ASPEED_JTAG_TCK_DIVISOR_MASK) | div,
> > + ASPEED_JTAG_TCK);
> > +   return 0;
> > +}
> 
> > +static void aspeed_jtag_sw_delay(struct aspeed_jtag *aspeed_jtag, 
> > +int
> > +cnt) {
> > +   int i;
> > +
> > +   for (i = 0; i < cnt; i++)
> > +   aspeed_jtag_read(aspeed_jtag, ASPEED_JTAG_SW);
> 
> Isn't it readsl() (or how it's called, I don't remember).
> 

No, readsl reads data into buffer. But in this place read used for make 
software delay. 
Aspeed jtag driver supports 2 modes:
1 - hw mode with the hardware controlled JTAG states
and pins
2 - with software controlled pins. 
This part of code used in sw-mode and generates delay for JTAG bit-bang .
I will change it to ndelay().

>

RE: [patch v21 1/4] drivers: jtag: Add JTAG core driver

2018-05-22 Thread Oleksandr Shamray
Hi Andy. 
Thanks for review.

Please read my answers inline.

> -Original Message-
> From: Andy Shevchenko [mailto:andy.shevche...@gmail.com]
> Sent: 16 мая 2018 г. 0:22
> To: Oleksandr Shamray <oleksan...@mellanox.com>
> Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>; Arnd Bergmann 
> <a...@arndb.de>; Linux Kernel Mailing List 
> <linux-kernel@vger.kernel.org>; linux-arm Mailing List 
> <linux-arm-ker...@lists.infradead.org>; devicetree 
> <devicet...@vger.kernel.org>; open...@lists.ozlabs.org; Joel Stanley 
> <j...@jms.id.au>; Jiří Pírko <j...@resnulli.us>; Tobias Klauser 
> <tklau...@distanz.ch>; open list:SERIAL DRIVERS  ser...@vger.kernel.org>; Vadim Pasternak <vad...@mellanox.com>; 
> system-sw-low-level <system-sw-low-le...@mellanox.com>; Rob Herring 
> <robh...@kernel.org>; openocd-devel-ow...@lists.sourceforge.net; 
> linux- a...@vger.kernel.org; David S. Miller <da...@davemloft.net>; 
> Mauro Carvalho Chehab <mche...@kernel.org>; Jiri Pirko 
> <j...@mellanox.com>
> Subject: Re: [patch v21 1/4] drivers: jtag: Add JTAG core driver
> 
> On Tue, May 15, 2018 at 5:21 PM, Oleksandr Shamray 
> <oleksan...@mellanox.com> wrote:
> > Initial patch for JTAG driver
> > JTAG class driver provide infrastructure to support 
> > hardware/software JTAG platform drivers. It provide user layer API 
> > interface for flashing and debugging external devices which equipped 
> > with JTAG interface using standard transactions.
> >
> > Driver exposes set of IOCTL to user space for:
> > - XFER:
> > - SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
> > - SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
> > - RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
> >   number of clocks).
> > - SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.
> >
> > Driver core provides set of internal APIs for allocation and
> > registration:
> > - jtag_register;
> > - jtag_unregister;
> > - jtag_alloc;
> > - jtag_free;
> >
> > Platform driver on registration with jtag-core creates the next 
> > entry in dev folder:
> > /dev/jtagX
> 
> >  0xB0   all RATIO devices   in development:
> > <mailto:v...@ratio.de>
> >  0xB1   00-1F   PPPoX   <mailto:mostr...@styx.uwaterloo.ca>
> > +0xB2   00-0f   linux/jtag.hJTAG driver
> > +
> > +<mailto:oleksan...@mellanox.com>
> 
> Consider to preserve style (upper vs. lower).

JTAG in code is lower (jtag) cane but in descriptions and notes it  is upper 
(JTAG).
In all places which do not correspond to this I will fix. 

> 
> > + This provides basic core functionality support for JTAG class 
> > devices.
> > + Hardware that is equipped with a JTAG microcontroller can be
> > + supported by using this driver's interfaces.
> > + This driver exposes a set of IOCTLs to the user space for
> > + the following commands:
> > + SDR: (Scan Data Register) Performs an IEEE 1149.1 Data Register 
> > scan
> > + SIR: (Scan Instruction Register) Performs an IEEE 1149.1 
> > Instruction
> > + Register scan.
> > + RUNTEST: Forces the IEEE 1149.1 bus to a run state for a specified
> > + number of clocks or a specified time period.
> 
> Something feels wrong with formatting here.
> 

Will fix

> > +#define MAX_JTAG_NAME_LEN (sizeof("jtag") + 5)
> 
> Interesting definition. Why not to set to 10 explicitly? And why 10?
> (16 sounds better)
> 
5 - is a max len of JTAG device id in device name. I will add define to it.

In general I don't see the case for the system with hundreds JTAG interfaces.
I will limit maximum jtag master to 255 devices and change  id len to 3

#define MAX_JTAG_ID_STR_LEN 5
#define MAX_JTAG_NAME_LEN (sizeof("jtag") + MAX_JTAG_ID_STR_LEN)

> > +struct jtag {
> > +   struct miscdevice miscdev;
> 
> > +   struct device *dev;
> 
> Doesn't miscdev parent contain exactly this one?

Yes. 
Will fix.

> 
> > +   const struct jtag_ops *ops;
> > +   int id;
> > +   bool opened;
> > +   struct mutex open_lock;
> > +   unsigned long priv[0];
> > +};
> 
> > +   err = copy_to_user(u64_to_user_ptr(xfer.tdio),
> > +  (void *)(xfer_data), data_size);
> 
> Redundant parens in one case. Check the rest similar places.
> 

Yes.

> > +static int jtag_open(

RE: [patch v21 1/4] drivers: jtag: Add JTAG core driver

2018-05-22 Thread Oleksandr Shamray
Hi Andy. 
Thanks for review.

Please read my answers inline.

> -Original Message-
> From: Andy Shevchenko [mailto:andy.shevche...@gmail.com]
> Sent: 16 мая 2018 г. 0:22
> To: Oleksandr Shamray 
> Cc: Greg Kroah-Hartman ; Arnd Bergmann 
> ; Linux Kernel Mailing List 
> ; linux-arm Mailing List 
> ; devicetree 
> ; open...@lists.ozlabs.org; Joel Stanley 
> ; Jiří Pírko ; Tobias Klauser 
> ; open list:SERIAL DRIVERS  ser...@vger.kernel.org>; Vadim Pasternak ; 
> system-sw-low-level ; Rob Herring 
> ; openocd-devel-ow...@lists.sourceforge.net; 
> linux- a...@vger.kernel.org; David S. Miller ; 
> Mauro Carvalho Chehab ; Jiri Pirko 
> 
> Subject: Re: [patch v21 1/4] drivers: jtag: Add JTAG core driver
> 
> On Tue, May 15, 2018 at 5:21 PM, Oleksandr Shamray 
>  wrote:
> > Initial patch for JTAG driver
> > JTAG class driver provide infrastructure to support 
> > hardware/software JTAG platform drivers. It provide user layer API 
> > interface for flashing and debugging external devices which equipped 
> > with JTAG interface using standard transactions.
> >
> > Driver exposes set of IOCTL to user space for:
> > - XFER:
> > - SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
> > - SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
> > - RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
> >   number of clocks).
> > - SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.
> >
> > Driver core provides set of internal APIs for allocation and
> > registration:
> > - jtag_register;
> > - jtag_unregister;
> > - jtag_alloc;
> > - jtag_free;
> >
> > Platform driver on registration with jtag-core creates the next 
> > entry in dev folder:
> > /dev/jtagX
> 
> >  0xB0   all RATIO devices   in development:
> > <mailto:v...@ratio.de>
> >  0xB1   00-1F   PPPoX   <mailto:mostr...@styx.uwaterloo.ca>
> > +0xB2   00-0f   linux/jtag.hJTAG driver
> > +
> > +<mailto:oleksan...@mellanox.com>
> 
> Consider to preserve style (upper vs. lower).

JTAG in code is lower (jtag) cane but in descriptions and notes it  is upper 
(JTAG).
In all places which do not correspond to this I will fix. 

> 
> > + This provides basic core functionality support for JTAG class 
> > devices.
> > + Hardware that is equipped with a JTAG microcontroller can be
> > + supported by using this driver's interfaces.
> > + This driver exposes a set of IOCTLs to the user space for
> > + the following commands:
> > + SDR: (Scan Data Register) Performs an IEEE 1149.1 Data Register 
> > scan
> > + SIR: (Scan Instruction Register) Performs an IEEE 1149.1 
> > Instruction
> > + Register scan.
> > + RUNTEST: Forces the IEEE 1149.1 bus to a run state for a specified
> > + number of clocks or a specified time period.
> 
> Something feels wrong with formatting here.
> 

Will fix

> > +#define MAX_JTAG_NAME_LEN (sizeof("jtag") + 5)
> 
> Interesting definition. Why not to set to 10 explicitly? And why 10?
> (16 sounds better)
> 
5 - is a max len of JTAG device id in device name. I will add define to it.

In general I don't see the case for the system with hundreds JTAG interfaces.
I will limit maximum jtag master to 255 devices and change  id len to 3

#define MAX_JTAG_ID_STR_LEN 5
#define MAX_JTAG_NAME_LEN (sizeof("jtag") + MAX_JTAG_ID_STR_LEN)

> > +struct jtag {
> > +   struct miscdevice miscdev;
> 
> > +   struct device *dev;
> 
> Doesn't miscdev parent contain exactly this one?

Yes. 
Will fix.

> 
> > +   const struct jtag_ops *ops;
> > +   int id;
> > +   bool opened;
> > +   struct mutex open_lock;
> > +   unsigned long priv[0];
> > +};
> 
> > +   err = copy_to_user(u64_to_user_ptr(xfer.tdio),
> > +  (void *)(xfer_data), data_size);
> 
> Redundant parens in one case. Check the rest similar places.
> 

Yes.

> > +static int jtag_open(struct inode *inode, struct file *file) {
> 
> > +   struct jtag *jtag = container_of(file->private_data, struct jtag,
> > +miscdev);
> 
> I would don't care about length and put it on one line.
> 

But following to LINUX kernel style, it should be no longer than 80 symbols. 
It will not pass by  ./scripts/checkpatch.pl

Will it be OK to send a patch which failed 80 symbols limitation check?

> &

RE: [patch v21 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-22 Thread Oleksandr Shamray
Hi Andy. 
Thanks for review.

Please read my answers inline.

> -Original Message-
> From: Andy Shevchenko [mailto:andy.shevche...@gmail.com]
> Sent: 16 мая 2018 г. 0:00
> To: Oleksandr Shamray 
> Cc: Greg Kroah-Hartman ; Arnd Bergmann 
> ; Linux Kernel Mailing List 
> ; linux-arm Mailing List 
> ; devicetree 
> ; open...@lists.ozlabs.org; Joel Stanley 
> ; Jiří Pírko ; Tobias Klauser 
> ; open list:SERIAL DRIVERS  ser...@vger.kernel.org>; Vadim Pasternak ; 
> system-sw-low-level ; Rob Herring 
> ; openocd-devel-ow...@lists.sourceforge.net; 
> linux- a...@vger.kernel.org; David S. Miller ; 
> Mauro Carvalho Chehab ; Jiri Pirko 
> 
> Subject: Re: [patch v21 2/4] drivers: jtag: Add Aspeed SoC 24xx and 
> 25xx families JTAG master driver
> 
> On Tue, May 15, 2018 at 5:21 PM, Oleksandr Shamray 
>  wrote:
> > Driver adds support of Aspeed 2500/2400 series SOC JTAG master
> controller.
> >
> > Driver implements the following jtag ops:
> > - freq_get;
> > - freq_set;
> > - status_get;
> > - idle;
> > - xfer;
> >
> > It has been tested on Mellanox system with BMC equipped with Aspeed
> > 2520 SoC for programming CPLD devices.
> 
> > +#define ASPEED_JTAG_DATA   0x00
> > +#define ASPEED_JTAG_INST   0x04
> > +#define ASPEED_JTAG_CTRL   0x08
> > +#define ASPEED_JTAG_ISR0x0C
> > +#define ASPEED_JTAG_SW 0x10
> > +#define ASPEED_JTAG_TCK0x14
> > +#define ASPEED_JTAG_EC 0x18
> > +
> > +#define ASPEED_JTAG_DATA_MSB   0x01
> > +#define ASPEED_JTAG_DATA_CHUNK_SIZE0x20
> 
> 
> > +#define ASPEED_JTAG_IOUT_LEN(len)  (ASPEED_JTAG_CTL_ENG_EN |\
> > +ASPEED_JTAG_CTL_ENG_OUT_EN 
> > +|\
> > +
> > +ASPEED_JTAG_CTL_INST_LEN(len))
> 
> Better to read
> 
> #define MY_COOL_CONST_OR_MACRO(xxx) \
>  ...
> 
> > +#define ASPEED_JTAG_DOUT_LEN(len)  (ASPEED_JTAG_CTL_ENG_EN
> |\
> > +ASPEED_JTAG_CTL_ENG_OUT_EN 
> > + |\
> > +
> > +ASPEED_JTAG_CTL_DATA_LEN(len))
> 
> Ditto.

Ok. Changed to:
#define ASPEED_JTAG_IOUT_LEN(len) \
   (ASPEED_JTAG_CTL_ENG_EN | \
   ASPEED_JTAG_CTL_ENG_OUT_EN | \
   ASPEED_JTAG_CTL_INST_LEN(len))

#define ASPEED_JTAG_DOUT_LEN(len) \
   (ASPEED_JTAG_CTL_ENG_EN | \
   ASPEED_JTAG_CTL_ENG_OUT_EN | \
   ASPEED_JTAG_CTL_DATA_LEN(len))


> 
> > +static char *end_status_str[] = {"idle", "ir pause", "drpause"};
> 
> > +static int aspeed_jtag_freq_set(struct jtag *jtag, u32 freq) {
> > +   struct aspeed_jtag *aspeed_jtag = jtag_priv(jtag);
> > +   unsigned long apb_frq;
> > +   u32 tck_val;
> > +   u16 div;
> > +
> > +   apb_frq = clk_get_rate(aspeed_jtag->pclk);
> 
> > +   div = (apb_frq % freq == 0) ? (apb_frq / freq) - 1 : 
> > + (apb_frq / freq);
> 
> Isn't it the same as
> 
> div = (apb_frq - 1) / freq;
> 
> ?
> 

Seems it is same. Thanks.

> > +   tck_val = aspeed_jtag_read(aspeed_jtag, ASPEED_JTAG_TCK);
> > +   aspeed_jtag_write(aspeed_jtag,
> > + (tck_val & ASPEED_JTAG_TCK_DIVISOR_MASK) | div,
> > + ASPEED_JTAG_TCK);
> > +   return 0;
> > +}
> 
> > +static void aspeed_jtag_sw_delay(struct aspeed_jtag *aspeed_jtag, 
> > +int
> > +cnt) {
> > +   int i;
> > +
> > +   for (i = 0; i < cnt; i++)
> > +   aspeed_jtag_read(aspeed_jtag, ASPEED_JTAG_SW);
> 
> Isn't it readsl() (or how it's called, I don't remember).
> 

No, readsl reads data into buffer. But in this place read used for make 
software delay. 
Aspeed jtag driver supports 2 modes:
1 - hw mode with the hardware controlled JTAG states
and pins
2 - with software controlled pins. 
This part of code used in sw-mode and generates delay for JTAG bit-bang .
I will change it to ndelay().

> > +}
> 
> > +static void aspeed_jtag_wait_instruction_pause(struct aspeed_jtag
> > +*aspeed_jtag) {
> > +   wait_event_interruptible(aspeed_jtag->jtag_wq, aspeed_jtag->flag &
> > +ASPEED_JTAG_ISR_INST_PAUSE);
> 
> In such cases I prefer to see a new line with a parameter in full.
> Check all places.
> 
> > +   aspeed_jtag->flag &= ~ASPEED_JTAG_ISR_INST_PAUSE; }
> 
> > +static void asp

[patch v21 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-15 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
Acked-by: Joel Stanley <j...@jms.id.au>
---
v19->v20
Notifications from kbuild test robot <l...@intel.com>
- add static declaration to 'aspeed_jtag_init' and
  'aspeed_jtag_deinit' functions

v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi <ku...@google.com>
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann <a...@arndb.de>
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot <l...@intel.com>
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  786 
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 43eb9a4..6b43ac8 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -16,3 +16,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   help
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index

[patch v21 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-15 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Arnd Bergmann 
Acked-by: Philippe Ombredanne 
Acked-by: Joel Stanley 
---
v19->v20
Notifications from kbuild test robot 
- add static declaration to 'aspeed_jtag_init' and
  'aspeed_jtag_deinit' functions

v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley 
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi 
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey 
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann 
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley 
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot 
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann 
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH 
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong 
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann 
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap 
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot 
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  786 
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 43eb9a4..6b43ac8 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -16,3 +16,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   help
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_ASPEED)  += jtag-aspeed.o
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
new file mode 100644
index 000..2d22de0
--- /dev/null
+++ b/drivers/jtag/jtag-aspeed.c
@@ -0,0 +1,786 @@
+// SPDX-License-Identifier: GPL-2.0
+// drivers/jtag/aspeed-jtag.c
+//
+// Copyright (c) 2018 Mellanox Technologies. All rights reserved.
+// Copyright (c) 2018 Oleksandr Shamray 
+
+#

[patch v21 1/4] drivers: jtag: Add JTAG core driver

2018-05-15 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v20->v21
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

Notifications from kbuild test robot <l...@intel.com>
- fix incompatible type casts

v18->v19
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot <l...@intel.com>
- Change include path t

[patch v21 1/4] drivers: jtag: Add JTAG core driver

2018-05-15 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v20->v21
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

v19->v20
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

Notifications from kbuild test robot 
- fix incompatible type casts

v18->v19
Comments pointed by Julia Cartwright 
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright 
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright 
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot 
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn 
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong 
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann 
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit sy

[patch v21 4/4] Documentation: jtag: Add ABI documentation

2018-05-15 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
---
v19->v20
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG doccumentation

v18->v19
Pavel Machek <pa...@ucw.cz>
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser <tklau...@distanz.ch>
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek <pa...@ucw.cz>
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 
 3 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..a86f188
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,28 @@
+Linux kernel JTAG support
+=
+
+The JTAG is an industry standard for verifying hardware
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional.
+
+JTAG interface is designed to have two parts - basic core driver and
+hardware specific driver. The basic driver introduces a general interface
+which is not dependent of specific hardware. It provides communication
+between user space and hardware specific driver.
+Each JTAG device is represented as a char device from (jtag0, jtag1, ...).
+Access to a JTAG device is performed through IOCTL calls.
+
+Call flow example:
+User: open  -> /dev/jatgX
+User: ioctl -> /dev/jtagX -> JTAG core driver -> JTAG hw specific driver
+User: close -> /dev/jatgX
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..6a857c8
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,109 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Two or more open for one device will return error
+
+Open/Close  device:
+- open("/dev/jtag0", O_RDWR);
+- close(jtag_fd');
+
+ioctl()
+---
+All access operations to JTAG devices performed through ioctl interface.
+The IOCTL interface supports this requests:
+   JTAG_IOCRUNTEST - Force JTAG state machine to RUN_TEST/IDLE state
+   JTAG_SIOCFREQ - Set JTAG TCK frequency
+   JTAG_GIOCFREQ - Get JTAG TCK frequency
+   JTAG_IOCXFER - send JTAG data Xfer
+   JTAG_GIOCSTATUS - get current JTAG TAP status
+   JTAG_SIOCMODE - set JTAG mode flags.
+
+JTAG_SIOCFREQ, JTAG_GIOCFR

[patch v21 4/4] Documentation: jtag: Add ABI documentation

2018-05-15 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray 
Acked-by: Arnd Bergmann 
---
v19->v20
Comments pointed by Randy Dunlap 
- Fix JTAG doccumentation

v18->v19
Pavel Machek 
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser 
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek 
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 
 3 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..a86f188
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,28 @@
+Linux kernel JTAG support
+=
+
+The JTAG is an industry standard for verifying hardware
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional.
+
+JTAG interface is designed to have two parts - basic core driver and
+hardware specific driver. The basic driver introduces a general interface
+which is not dependent of specific hardware. It provides communication
+between user space and hardware specific driver.
+Each JTAG device is represented as a char device from (jtag0, jtag1, ...).
+Access to a JTAG device is performed through IOCTL calls.
+
+Call flow example:
+User: open  -> /dev/jatgX
+User: ioctl -> /dev/jtagX -> JTAG core driver -> JTAG hw specific driver
+User: close -> /dev/jatgX
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..6a857c8
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,109 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Two or more open for one device will return error
+
+Open/Close  device:
+- open("/dev/jtag0", O_RDWR);
+- close(jtag_fd');
+
+ioctl()
+---
+All access operations to JTAG devices performed through ioctl interface.
+The IOCTL interface supports this requests:
+   JTAG_IOCRUNTEST - Force JTAG state machine to RUN_TEST/IDLE state
+   JTAG_SIOCFREQ - Set JTAG TCK frequency
+   JTAG_GIOCFREQ - Get JTAG TCK frequency
+   JTAG_IOCXFER - send JTAG data Xfer
+   JTAG_GIOCSTATUS - get current JTAG TAP status
+   JTAG_SIOCMODE - set JTAG mode flags.
+
+JTAG_SIOCFREQ, JTAG_GIOCFREQ
+--
+Set/Get JTAG clock speed:
+
+   unsigned int jtag_fd;
+   ioctl(jtag_fd, JTAG_SIOCFREQ, );
+   ioctl(jtag_fd, JTAG_GIOCFRE

[patch v21 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-15 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Rob Herring <r...@kernel.org>
---
v19->v20
v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley <joel.s...@gmail.com>
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring <r...@kernel.org>
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring <r...@kernel.org>
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
-- 
1.7.1



[patch v21 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-15 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v19->v20
v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
-- 
1.7.1



[patch v21 0/4] JTAG driver introduction

2018-05-15 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   32 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  274 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  105 +++
 14 files changed, 1441 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v21 0/4] JTAG driver introduction

2018-05-15 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   32 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  274 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  105 +++
 14 files changed, 1441 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v20 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-14 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
Acked-by: Joel Stanley <j...@jms.id.au>
---
v19->v20
Notifications from kbuild test robot <l...@intel.com>
- add static declaration to 'aspeed_jtag_init' and
  'aspeed_jtag_deinit' functions

v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi <ku...@google.com>
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann <a...@arndb.de>
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot <l...@intel.com>
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  786 
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index ba72a2b..07950a6 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -16,3 +16,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   help
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index

[patch v20 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-14 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Arnd Bergmann 
Acked-by: Philippe Ombredanne 
Acked-by: Joel Stanley 
---
v19->v20
Notifications from kbuild test robot 
- add static declaration to 'aspeed_jtag_init' and
  'aspeed_jtag_deinit' functions

v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley 
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi 
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey 
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann 
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley 
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot 
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann 
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH 
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong 
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann 
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap 
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot 
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  786 
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index ba72a2b..07950a6 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -16,3 +16,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   help
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_ASPEED)  += jtag-aspeed.o
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
new file mode 100644
index 000..2d22de0
--- /dev/null
+++ b/drivers/jtag/jtag-aspeed.c
@@ -0,0 +1,786 @@
+// SPDX-License-Identifier: GPL-2.0
+// drivers/jtag/aspeed-jtag.c
+//
+// Copyright (c) 2018 Mellanox Technologies. All rights reserved.
+// Copyright (c) 2018 Oleksandr Shamray 
+
+#

[patch v20 1/4] drivers: jtag: Add JTAG core driver

2018-05-14 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v19->v20
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG dirver help in Kconfig

Notifications from kbuild test robot <l...@intel.com>
- fix incompatible type casts

v18->v19
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot <l...@intel.com>
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change license typ

[patch v20 1/4] drivers: jtag: Add JTAG core driver

2018-05-14 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v19->v20
Comments pointed by Randy Dunlap 
- Fix JTAG dirver help in Kconfig

Notifications from kbuild test robot 
- fix incompatible type casts

v18->v19
Comments pointed by Julia Cartwright 
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright 
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright 
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot 
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn 
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong 
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann 
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism 

[patch v20 0/4] JTAG driver introduction

2018-05-14 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   32 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  274 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  105 +++
 14 files changed, 1441 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v20 0/4] JTAG driver introduction

2018-05-14 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   32 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  274 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  105 +++
 14 files changed, 1441 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v20 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-14 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Rob Herring <r...@kernel.org>
---
v19->v20
v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley <joel.s...@gmail.com>
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring <r...@kernel.org>
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring <r...@kernel.org>
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
-- 
1.7.1



[patch v20 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-14 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v19->v20
v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
-- 
1.7.1



[patch v20 4/4] Documentation: jtag: Add ABI documentation

2018-05-14 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
---
v19->v20
Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Fix JTAG doccumentation

v18->v19
Pavel Machek <pa...@ucw.cz>
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser <tklau...@distanz.ch>
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek <pa...@ucw.cz>
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 
 3 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..a86f188
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,28 @@
+Linux kernel JTAG support
+=
+
+The JTAG is an industry standard for verifying hardware
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional.
+
+JTAG interface is designed to have two parts - basic core driver and
+hardware specific driver. The basic driver introduces a general interface
+which is not dependent of specific hardware. It provides communication
+between user space and hardware specific driver.
+Each JTAG device is represented as a char device from (jtag0, jtag1, ...).
+Access to a JTAG device is performed through IOCTL calls.
+
+Call flow example:
+User: open  -> /dev/jatgX
+User: ioctl -> /dev/jtagX -> JTAG core driver -> JTAG hw specific driver
+User: close -> /dev/jatgX
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..6a857c8
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,109 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Two or more open for one device will return error
+
+Open/Close  device:
+- open("/dev/jtag0", O_RDWR);
+- close(jtag_fd');
+
+ioctl()
+---
+All access operations to JTAG devices performed through ioctl interface.
+The IOCTL interface supports this requests:
+   JTAG_IOCRUNTEST - Force JTAG state machine to RUN_TEST/IDLE state
+   JTAG_SIOCFREQ - Set JTAG TCK frequency
+   JTAG_GIOCFREQ - Get JTAG TCK frequency
+   JTAG_IOCXFER - send JTAG data Xfer
+   JTAG_GIOCSTATUS - get current JTAG TAP status
+   JTAG_SIOCMODE - set JTAG mode flags.
+
+JTAG_SIOCFREQ, JTAG_GIOCFR

[patch v20 4/4] Documentation: jtag: Add ABI documentation

2018-05-14 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray 
Acked-by: Arnd Bergmann 
---
v19->v20
Comments pointed by Randy Dunlap 
- Fix JTAG doccumentation

v18->v19
Pavel Machek 
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser 
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek 
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   28 +
 Documentation/jtag/transactions|  109 
 3 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..a86f188
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,28 @@
+Linux kernel JTAG support
+=
+
+The JTAG is an industry standard for verifying hardware
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional.
+
+JTAG interface is designed to have two parts - basic core driver and
+hardware specific driver. The basic driver introduces a general interface
+which is not dependent of specific hardware. It provides communication
+between user space and hardware specific driver.
+Each JTAG device is represented as a char device from (jtag0, jtag1, ...).
+Access to a JTAG device is performed through IOCTL calls.
+
+Call flow example:
+User: open  -> /dev/jatgX
+User: ioctl -> /dev/jtagX -> JTAG core driver -> JTAG hw specific driver
+User: close -> /dev/jatgX
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..6a857c8
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,109 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Instruction Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Data Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Two or more open for one device will return error
+
+Open/Close  device:
+- open("/dev/jtag0", O_RDWR);
+- close(jtag_fd');
+
+ioctl()
+---
+All access operations to JTAG devices performed through ioctl interface.
+The IOCTL interface supports this requests:
+   JTAG_IOCRUNTEST - Force JTAG state machine to RUN_TEST/IDLE state
+   JTAG_SIOCFREQ - Set JTAG TCK frequency
+   JTAG_GIOCFREQ - Get JTAG TCK frequency
+   JTAG_IOCXFER - send JTAG data Xfer
+   JTAG_GIOCSTATUS - get current JTAG TAP status
+   JTAG_SIOCMODE - set JTAG mode flags.
+
+JTAG_SIOCFREQ, JTAG_GIOCFREQ
+--
+Set/Get JTAG clock speed:
+
+   unsigned int jtag_fd;
+   ioctl(jtag_fd, JTAG_SIOCFREQ, );
+   ioctl(jtag_fd, JTAG_GIOCFRE

[patch v19 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-10 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Rob Herring <r...@kernel.org>
---
v17->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley <joel.s...@gmail.com>
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring <r...@kernel.org>
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring <r...@kernel.org>
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
-- 
1.7.1



[patch v19 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-10 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v17->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
-- 
1.7.1



[patch v19 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-10 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
Acked-by: Joel Stanley <j...@jms.id.au>
---
v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi <ku...@google.com>
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann <a...@arndb.de>
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot <l...@intel.com>
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  786 
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 5e2c75b..10c9a62 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -14,3 +14,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   help
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTA

[patch v19 1/4] drivers: jtag: Add JTAG core driver

2018-05-10 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v18->v19
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot <l...@intel.com>
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn <and...@lunn.ch>
- Change

[patch v19 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-05-10 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Arnd Bergmann 
Acked-by: Philippe Ombredanne 
Acked-by: Joel Stanley 
---
v18->v19
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley 
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi 
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey 
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann 
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley 
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot 
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann 
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH 
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong 
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann 
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap 
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot 
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  786 
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 5e2c75b..10c9a62 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -14,3 +14,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   help
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_ASPEED)  += jtag-aspeed.o
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
new file mode 100644
index 000..259af67
--- /dev/null
+++ b/drivers/jtag/jtag-aspeed.c
@@ -0,0 +1,786 @@
+// SPDX-License-Identifier: GPL-2.0
+// drivers/jtag/aspeed-jtag.c
+//
+// Copyright (c) 2018 Mellanox Technologies. All rights reserved.
+// Copyright (c) 2018 Oleksandr Shamray 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#defi

[patch v19 1/4] drivers: jtag: Add JTAG core driver

2018-05-10 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v18->v19
Comments pointed by Julia Cartwright 
- Fix memory leak on jtag_alloc exit

v17->v18
Comments pointed by Julia Cartwright 
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright 
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot 
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn 
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong 
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann 
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism to get jtag data from inode
- Add .compat_ioctl to file ops
- Add mem alignment for jtag priv data

Comments pointed by Tobias Klauser 

[patch v19 0/4] JTAG driver introduction

2018-05-10 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   31 +
 Documentation/jtag/transactions|  108 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   30 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  273 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  105 +++
 14 files changed, 1440 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v19 0/4] JTAG driver introduction

2018-05-10 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 Documentation/jtag/overview|   31 +
 Documentation/jtag/transactions|  108 +++
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   30 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  273 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  105 +++
 14 files changed, 1440 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v19 4/4] Documentation: jtag: Add ABI documentation

2018-05-10 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
---
v18-v19
Pavel Machek <pa...@ucw.cz>
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser <tklau...@distanz.ch>
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek <pa...@ucw.cz>
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   31 ++
 Documentation/jtag/transactions|  108 
 3 files changed, 166 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..e35afc0
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,31 @@
+Linux kernel JTAG support
+=
+
+The JTAG (Joint Test Action Group) is an industry standard for hardware
+verifying designs and testing printed circuit boards after manufacture.
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins
+
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional.
+
+JTAG interface is supposed to have two parts - basic core driver and
+hardware specific driver.
+The basic driver introduces general interface which is not dependent of 
specific
+hardware. It  provides communication between user space and hardware specific
+driver.
+Each JTAG device is represented as char device from (jtag0, jtag1, ...).
+Access to JTAG device is performed through IOCTL call.
+
+Call flow example:
+User (IOCTL) -> /dev/jtagX -> JTAG core driver -> JTAG hw specific driver
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..91f7f92
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,108 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Twice and more open for one device will return error
+
+Open/Close  device:
+- open('/dev/jtag0', O_RDWR);
+- close(jtag_fd');
+
+ioctl()
+---
+All access operations to JTAG device performed trougth ioctl interface.
+It support another requests:
+   JTAG_IOCRUNTEST - Force JTAG state machine to RUN_TEST/IDLE state
+   JTAG_SIOCFREQ - Set JTAG TCK frequency
+   JTAG_GIOCFREQ - GET JTAG TCK frequency
+   JTAG_IOCXFER - send JTAG data Xfer
+   JTAG_GIOCSTATUS - get current JTAG TAP status
+   JTAG_SIOCMODE - set JTAG mode flags.
+
+JTAG_SIOC

[patch v19 4/4] Documentation: jtag: Add ABI documentation

2018-05-10 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray 
Acked-by: Arnd Bergmann 
---
v18-v19
Pavel Machek 
- Added JTAG doccumentation to Documentation/jtag

v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser 
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek 
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +
 Documentation/jtag/overview|   31 ++
 Documentation/jtag/transactions|  108 
 3 files changed, 166 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/jtag/overview
 create mode 100644 Documentation/jtag/transactions

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..4325316
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  May 2018
+KernelVersion: 4.18
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
diff --git a/Documentation/jtag/overview b/Documentation/jtag/overview
new file mode 100644
index 000..e35afc0
--- /dev/null
+++ b/Documentation/jtag/overview
@@ -0,0 +1,31 @@
+Linux kernel JTAG support
+=
+
+The JTAG (Joint Test Action Group) is an industry standard for hardware
+verifying designs and testing printed circuit boards after manufacture.
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins
+
+JTAG provides access to many logic signals of a complex integrated circuit,
+including the device pins.
+
+A JTAG interface is a special interface added to a chip.
+Depending on the version of JTAG, two, four, or five pins are added.
+
+The connector pins are:
+   TDI (Test Data In)
+   TDO (Test Data Out)
+   TCK (Test Clock)
+   TMS (Test Mode Select)
+   TRST (Test Reset) optional.
+
+JTAG interface is supposed to have two parts - basic core driver and
+hardware specific driver.
+The basic driver introduces general interface which is not dependent of 
specific
+hardware. It  provides communication between user space and hardware specific
+driver.
+Each JTAG device is represented as char device from (jtag0, jtag1, ...).
+Access to JTAG device is performed through IOCTL call.
+
+Call flow example:
+User (IOCTL) -> /dev/jtagX -> JTAG core driver -> JTAG hw specific driver
diff --git a/Documentation/jtag/transactions b/Documentation/jtag/transactions
new file mode 100644
index 000..91f7f92
--- /dev/null
+++ b/Documentation/jtag/transactions
@@ -0,0 +1,108 @@
+The JTAG API
+=
+
+JTAG master devices can be accessed through a character misc-device.
+Each JTAG master interface can be accessed by using /dev/jtagN
+
+JTAG system calls set:
+- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
+- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
+- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
+number of clocks.
+
+open(), close()
+---
+open() opens JTAG device. Only one open operation per JTAG device
+can be performed. Twice and more open for one device will return error
+
+Open/Close  device:
+- open('/dev/jtag0', O_RDWR);
+- close(jtag_fd');
+
+ioctl()
+---
+All access operations to JTAG device performed trougth ioctl interface.
+It support another requests:
+   JTAG_IOCRUNTEST - Force JTAG state machine to RUN_TEST/IDLE state
+   JTAG_SIOCFREQ - Set JTAG TCK frequency
+   JTAG_GIOCFREQ - GET JTAG TCK frequency
+   JTAG_IOCXFER - send JTAG data Xfer
+   JTAG_GIOCSTATUS - get current JTAG TAP status
+   JTAG_SIOCMODE - set JTAG mode flags.
+
+JTAG_SIOCFREQ, JTAG_GIOCFREQ
+--
+Set/Get JTAG clock speed:
+
+   ioctl(jtag_fd, JTAG_SIOCFREQ, );
+   ioctl(jtag_fd, JTAG_GIO

RE: [patch v18 0/4] JTAG driver introduction

2018-05-10 Thread Oleksandr Shamray
Hi Florian.

>> We propose to implement general JTAG interface and infrastructure 
>> to communicate with user layer application. In such way, we can 
>> have the standard JTAG interface core part and separation from 
>> specific HW implementation.
>
>Well, the framework in its current shape is still extremely 
>simplistic, therefore leaving a lot of room (read: bugs, 
>inconsistencies) within the hands of the driver, so while the 
>user-space interface is standard through the proposed character 
>device, the user experience, likely might not.

Well, the framework is intentionally simply and provide the very basic
interface. It supposed that interface can be extended in the future, if 
necessary. Current kernel does not provide a framework for JTAG interface,
and we believe this is good starting point to allow such framework. This
provide minimal, but sufficient interface and any future extension will be
of course welcomed.

At the moment we have one controller driver, which works well with this
infrastructure. And we have very reasonable use case - this driver allows
flashing for all the programmable devices, connected to JTAG interface,
where the image for these device is provided with the standard SVF format.


>> This allow new capability to debug the CPU or program system's 
>> device via BMC without additional devices nor cost.

>If that is the case, should not we leverage the kernel's device 
>driver model and expect the JTAG framework to create specific devices 
>for the different pieces of HW discovered on the scan chain? That 
>would also
>presumably allow the core JTAG framework to retain the necessary 
>state
>changes in order to address one particular device within the scan chain.

For the device programming use case, the flashing image will contain
jtag chain topology. If for example, jtag domain contains x devices, but
image contains less, the only relevant devices will be flashed and there is
no need to distinct between them.
In case there are several domains, jtag interface is  configured to be
connected to the relevant one.

For the CPU debug use case, jtag interface is configured to be connected
to CPU only.

System should be able to provide jtag selection according to the needs
and this kind of operations should be out of the JTAG driver scope.


>> This patch purpose is to add JTAG master core infrastructure by 
>> defining new JTAG class and provide generic JTAG interface to allow 
>> hardware specific drivers to connect this interface.
>> This will enable all JTAG drivers to use the common interface part 
>> and will have separate for hardware implementation.

>Let's consider I want to get rid of OpenOCD, or rather, move its 
>driver interface within the kernel and replace it on the OpenOCD side 
>with a generic character device interface. I could presumably 
>amortize the costly operations which are currently I/O and/or system 
>call limiting when running in user-space, what would it look like 
>with your proposed framework, have you given some thoughts about that?


The JTAG driver using SDR/SIR transactions to send/receive data.
It can send/receive multiple data bits by a single transaction.

For the bit-banging style drivers it gives you an advantage of sending
Bits stream by one system call vs per-bit system call.
So, instead of updating GPIO pins a few time through user space interface
(sysfs) for sending single bit, an application can send multiple bits in a
stream by one call. And all GPIO operations will be performed than in a
kernel space.
It'll be necessary to have bit-banging driver, using the JTAG infrastructure,
which should be configured according to the particular system during
initialization. And we are planning to develop such kind of driver.
It definitely reduces system calls and saves time for JTAG operations.

For the system equipped with the JTAG master there the same advantages
plus hardware acceleration for pin access (all pins can be accessed by
one shot).

Driver supports universal transactions (include/uapi/linux/jtag.h),
which are sent through  IOCTL interface JTAG_IOCRUNTEST, JTAG_IOCXFER
struct struct jtag_xfer {
  __u8  type;
  __u8  direction;
  __u8  endstate;
  __u8  padding;
  __u32length;
   __u64tdio;
};

jtag_run_test_idle {
  __u8  reset;
  __u8  endstate;
  __u8  tck;
};

You can see usage example on 
https://github.com/mellanoxbmc/mellanox-bmc-tools/tree/master/mlnx_cpldprog

Best Regards,
Oleksandr Shamray

> -----Original Message-
> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> Sent: 31 января 2018 г. 5:03
> To: Oleksandr Shamray <oleksan...@mellanox.com>;
> gre...@linuxfoundation.org; a...@arndb.de
> Cc: linux-kernel@vger.kernel.org; li

RE: [patch v18 0/4] JTAG driver introduction

2018-05-10 Thread Oleksandr Shamray
Hi Florian.

>> We propose to implement general JTAG interface and infrastructure 
>> to communicate with user layer application. In such way, we can 
>> have the standard JTAG interface core part and separation from 
>> specific HW implementation.
>
>Well, the framework in its current shape is still extremely 
>simplistic, therefore leaving a lot of room (read: bugs, 
>inconsistencies) within the hands of the driver, so while the 
>user-space interface is standard through the proposed character 
>device, the user experience, likely might not.

Well, the framework is intentionally simply and provide the very basic
interface. It supposed that interface can be extended in the future, if 
necessary. Current kernel does not provide a framework for JTAG interface,
and we believe this is good starting point to allow such framework. This
provide minimal, but sufficient interface and any future extension will be
of course welcomed.

At the moment we have one controller driver, which works well with this
infrastructure. And we have very reasonable use case - this driver allows
flashing for all the programmable devices, connected to JTAG interface,
where the image for these device is provided with the standard SVF format.


>> This allow new capability to debug the CPU or program system's 
>> device via BMC without additional devices nor cost.

>If that is the case, should not we leverage the kernel's device 
>driver model and expect the JTAG framework to create specific devices 
>for the different pieces of HW discovered on the scan chain? That 
>would also
>presumably allow the core JTAG framework to retain the necessary 
>state
>changes in order to address one particular device within the scan chain.

For the device programming use case, the flashing image will contain
jtag chain topology. If for example, jtag domain contains x devices, but
image contains less, the only relevant devices will be flashed and there is
no need to distinct between them.
In case there are several domains, jtag interface is  configured to be
connected to the relevant one.

For the CPU debug use case, jtag interface is configured to be connected
to CPU only.

System should be able to provide jtag selection according to the needs
and this kind of operations should be out of the JTAG driver scope.


>> This patch purpose is to add JTAG master core infrastructure by 
>> defining new JTAG class and provide generic JTAG interface to allow 
>> hardware specific drivers to connect this interface.
>> This will enable all JTAG drivers to use the common interface part 
>> and will have separate for hardware implementation.

>Let's consider I want to get rid of OpenOCD, or rather, move its 
>driver interface within the kernel and replace it on the OpenOCD side 
>with a generic character device interface. I could presumably 
>amortize the costly operations which are currently I/O and/or system 
>call limiting when running in user-space, what would it look like 
>with your proposed framework, have you given some thoughts about that?


The JTAG driver using SDR/SIR transactions to send/receive data.
It can send/receive multiple data bits by a single transaction.

For the bit-banging style drivers it gives you an advantage of sending
Bits stream by one system call vs per-bit system call.
So, instead of updating GPIO pins a few time through user space interface
(sysfs) for sending single bit, an application can send multiple bits in a
stream by one call. And all GPIO operations will be performed than in a
kernel space.
It'll be necessary to have bit-banging driver, using the JTAG infrastructure,
which should be configured according to the particular system during
initialization. And we are planning to develop such kind of driver.
It definitely reduces system calls and saves time for JTAG operations.

For the system equipped with the JTAG master there the same advantages
plus hardware acceleration for pin access (all pins can be accessed by
one shot).

Driver supports universal transactions (include/uapi/linux/jtag.h),
which are sent through  IOCTL interface JTAG_IOCRUNTEST, JTAG_IOCXFER
struct struct jtag_xfer {
  __u8  type;
  __u8  direction;
  __u8  endstate;
  __u8  padding;
  __u32length;
   __u64tdio;
};

jtag_run_test_idle {
  __u8  reset;
  __u8  endstate;
  __u8  tck;
};

You can see usage example on 
https://github.com/mellanoxbmc/mellanox-bmc-tools/tree/master/mlnx_cpldprog

Best Regards,
Oleksandr Shamray

> -----Original Message-
> From: Florian Fainelli [mailto:f.faine...@gmail.com]
> Sent: 31 января 2018 г. 5:03
> To: Oleksandr Shamray ;
> gre...@linuxfoundation.org; a...@arndb.de
> Cc: linux-kernel@vger.kernel.org; linux-arm-ker...@lists.infradead.org;

[patch v18 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-29 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
Acked-by: Joel Stanley <j...@jms.id.au>
---
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi <ku...@google.com>
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann <a...@arndb.de>
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot <l...@intel.com>
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  786 
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 0fad1a3..63ddf1f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -14,3 +14,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   ---help---
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_A

[patch v18 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-29 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Arnd Bergmann 
Acked-by: Philippe Ombredanne 
Acked-by: Joel Stanley 
---
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley 
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi 
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey 
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann 
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley 
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot 
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann 
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH 
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong 
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann 
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap 
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot 
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  786 
 3 files changed, 801 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 0fad1a3..63ddf1f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -14,3 +14,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   ---help---
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_ASPEED)  += jtag-aspeed.o
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
new file mode 100644
index 000..f679041
--- /dev/null
+++ b/drivers/jtag/jtag-aspeed.c
@@ -0,0 +1,786 @@
+// SPDX-License-Identifier: GPL-2.0
+// drivers/jtag/aspeed-jtag.c
+//
+// Copyright (c) 2017 Mellanox Technologies. All rights reserved.
+// Copyright (c) 2017 Oleksandr Shamray 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define 

[patch v18 1/4] drivers: jtag: Add JTAG core driver

2018-01-29 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v17->v18
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot <l...@intel.com>
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn <and...@lunn.ch>
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add SPD

[patch v18 1/4] drivers: jtag: Add JTAG core driver

2018-01-29 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v17->v18
Comments pointed by Julia Cartwright 
- Change to return -EOPNOTSUPP in case of error in JTAG_GIOCFREQ
- Add ops callbacks check to jtag_alloc
- Add err check for copy_to_user
- Move the kfree() above the if (err) in JTAG_IOCXFER
- remove unnecessary check for error after put_user
- add padding to struct jtag_xfer

v16->v17
Comments pointed by Julia Cartwright 
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot 
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn 
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong 
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann 
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism to get jtag data from inode
- Add .compat_ioctl to file ops
- Add mem alignment for jtag priv data

Comments pointed by Tobias Klauser 
- Change function names to avoid match with variable types
- Fix description for jtag_ru_test_idle in uapi 

[patch v18 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-29 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Rob Herring <r...@kernel.org>
---
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley <joel.s...@gmail.com>
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring <r...@kernel.org>
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring <r...@kernel.org>
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
-- 
1.7.1



[patch v18 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-29 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v17->v18
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 1 files changed, 22 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
-- 
1.7.1



[patch v18 4/4] Documentation: jtag: Add ABI documentation

2018-01-29 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
---
v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser <tklau...@distanz.ch>
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek <pa...@ucw.cz>
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..9db83ea
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  October 2017
+KernelVersion: 4.17
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
-- 
1.7.1



[patch v18 4/4] Documentation: jtag: Add ABI documentation

2018-01-29 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray 
Acked-by: Arnd Bergmann 
---
v17->v18
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser 
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek 
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..9db83ea
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  October 2017
+KernelVersion: 4.17
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
-- 
1.7.1



[patch v18 0/4] JTAG driver introduction

2018-01-29 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   30 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  273 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  105 +++
 12 files changed, 1301 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v18 0/4] JTAG driver introduction

2018-01-29 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   30 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  273 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  105 +++
 12 files changed, 1301 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v17 1/4] drivers: jtag: Add JTAG core driver

2018-01-15 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v16->v17
Comments pointed by Julia Cartwright <jul...@eso.teric.us>
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot <l...@intel.com>
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn <and...@lunn.ch>
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism to get jtag data from inode
- A

[patch v17 1/4] drivers: jtag: Add JTAG core driver

2018-01-15 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v16->v17
Comments pointed by Julia Cartwright 
- Fix memory allocation on jtag alloc
- Move out unnecessary form lock on jtag open
- Rework jtag register behavior

v15->v16
Commen ts pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot 
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn 
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong 
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann 
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism to get jtag data from inode
- Add .compat_ioctl to file ops
- Add mem alignment for jtag priv data

Comments pointed by Tobias Klauser 
- Change function names to avoid match with variable types
- Fix description for jtag_ru_test_idle in uapi jtag.h
- Fix misprints IDEL/IDLE, trough/through
---
 Documentation/ioctl/ioctl-number.txt |2 +
 MAINTAINERS  |   10 ++
 drivers/Kconfig  |2 +
 drivers/Makefile |1 +
 drivers/jtag/Kconfig |   16 ++
 drivers/jtag/Makefil

[patch v17 4/4] Documentation: jtag: Add ABI documentation

2018-01-15 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
---
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser <tklau...@distanz.ch>
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek <pa...@ucw.cz>
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..cea9552
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  October 2017
+KernelVersion: 4.17
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
\ No newline at end of file
-- 
1.7.1



[patch v17 4/4] Documentation: jtag: Add ABI documentation

2018-01-15 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray 
Acked-by: Arnd Bergmann 
---
v16->v17
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser 
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek 
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..cea9552
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  October 2017
+KernelVersion: 4.17
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
\ No newline at end of file
-- 
1.7.1



[patch v17 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-15 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
Acked-by: Joel Stanley <j...@jms.id.au>
---
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi <ku...@google.com>
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann <a...@arndb.de>
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot <l...@intel.com>
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  785 
 3 files changed, 800 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 0fad1a3..63ddf1f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -14,3 +14,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   ---help---
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_ASPEED) 

[patch v17 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-15 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Rob Herring <r...@kernel.org>
---
v16->v17
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley <joel.s...@gmail.com>
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring <r...@kernel.org>
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring <r...@kernel.org>
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 drivers/jtag/jtag-aspeed.c |1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
index 9cbd6da..f679041 100644
--- a/drivers/jtag/jtag-aspeed.c
+++ b/drivers/jtag/jtag-aspeed.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
1.7.1



[patch v17 0/4] JTAG driver introduction

2018-01-15 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   30 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  284 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  104 +++
 12 files changed, 1311 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v17 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-15 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Arnd Bergmann 
Acked-by: Philippe Ombredanne 
Acked-by: Joel Stanley 
---
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley 
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi 
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey 
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann 
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley 
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot 
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann 
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH 
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong 
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann 
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap 
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot 
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  785 
 3 files changed, 800 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 0fad1a3..63ddf1f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -14,3 +14,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   ---help---
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_ASPEED)  += jtag-aspeed.o
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
new file mode 100644
index 000..9cbd6da
--- /dev/null
+++ b/drivers/jtag/jtag-aspeed.c
@@ -0,0 +1,785 @@
+// SPDX-License-Identifier: GPL-2.0
+// drivers/jtag/aspeed-jtag.c
+//
+// Copyright (c) 2017 Mellanox Technologies. All rights reserved.
+// Copyright (c) 2017 Oleksandr Shamray 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ASPEED_JTAG_DATA

[patch v17 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-15 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v16->v17
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 drivers/jtag/jtag-aspeed.c |1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
index 9cbd6da..f679041 100644
--- a/drivers/jtag/jtag-aspeed.c
+++ b/drivers/jtag/jtag-aspeed.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
1.7.1



[patch v17 0/4] JTAG driver introduction

2018-01-15 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   30 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  284 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  104 +++
 12 files changed, 1311 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



RE: [patch v16 1/4] drivers: jtag: Add JTAG core driver

2018-01-15 Thread Oleksandr Shamray
Hi Julia

> -Original Message-
> From: Julia Cartwright [mailto:jul...@eso.teric.us]
> Sent: 15 января 2018 г. 22:52
> To: Oleksandr Shamray <oleksan...@mellanox.com>
> Cc: gre...@linuxfoundation.org; a...@arndb.de; linux-
> ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> devicet...@vger.kernel.org; open...@lists.ozlabs.org; j...@jms.id.au;
> j...@resnulli.us; tklau...@distanz.ch; linux-ser...@vger.kernel.org; Vadim
> Pasternak <vad...@mellanox.com>; system-sw-low-level  le...@mellanox.com>; robh...@kernel.org; openocd-devel-
> ow...@lists.sourceforge.net; linux-...@vger.kernel.org;
> da...@davemloft.net; mche...@kernel.org; Jiri Pirko
> <j...@mellanox.com>
> Subject: Re: [patch v16 1/4] drivers: jtag: Add JTAG core driver
> 
> Hello Oleksandr-
> 
> I have a few comments below.
> 
> On Fri, Jan 12, 2018 at 07:08:26PM +0200, Oleksandr Shamray wrote:
> > Initial patch for JTAG driver
> > JTAG class driver provide infrastructure to support hardware/software
> > JTAG platform drivers. It provide user layer API interface for
> > flashing and debugging external devices which equipped with JTAG
> > interface using standard transactions.
> >

[..]
> > +   break;
> > +
> > +   case JTAG_IOCXFER:
> > +   if (!jtag->ops->xfer)
> 
> Are all ops optional?  That seems bizarre.  I would have expected at least one
> callback to be required.

You right. But I'm preferred to check pointers before use it.

> 
> [..]
> > +static int jtag_open(struct inode *inode, struct file *file) {
> > +   struct jtag *jtag = container_of(file->private_data, struct jtag,
> > +miscdev);
> > +
> > +   if (mutex_lock_interruptible(>open_lock))
> > +   return -ERESTARTSYS;
> > +
> > +   if (jtag->opened) {
> > +   mutex_unlock(>open_lock);
> > +   return -EBUSY;
> > +   }
> > +
> > +   nonseekable_open(inode, file);
> > +   file->private_data = jtag;
> 
> These two can be moved out of the lock.

Agree.

> 
> > +   jtag->opened = true;
> > +   mutex_unlock(>open_lock);
> > +   return 0;
> > +}
> > +
> > +static int jtag_release(struct inode *inode, struct file *file) {
> > +   struct jtag *jtag = file->private_data;
> > +
> > +   mutex_lock(>open_lock);
> > +   jtag->opened = false;
> > +   mutex_unlock(>open_lock);
> > +   return 0;
> > +}
> > +
> > +static const struct file_operations jtag_fops = {
> > +   .owner  = THIS_MODULE,
> > +   .open   = jtag_open,
> > +   .release= jtag_release,
> > +   .llseek = noop_llseek,
> > +   .unlocked_ioctl = jtag_ioctl,
> > +};
> > +
> > +struct jtag *jtag_alloc(size_t priv_size, const struct jtag_ops *ops)
> > +{
> > +   struct jtag *jtag;
> > +
> > +   jtag = kzalloc(sizeof(*jtag), GFP_KERNEL);
> 
> Did you mean to allocate: sizeof(*jtag) + priv_size?

Thank, it's a mistake.

> 
> > +   if (!jtag)
> > +   return NULL;
> > +
> > +   jtag->ops = ops;
> > +   return jtag;
> > +}
> > +EXPORT_SYMBOL_GPL(jtag_alloc);
> > +
> > +void jtag_free(struct jtag *jtag)
> > +{
> > +   kfree(jtag);
> > +}
> > +EXPORT_SYMBOL_GPL(jtag_free);
> > +
> > +int jtag_register(struct jtag *jtag)
> > +{
> > +   char *name;
> > +   int err;
> > +   int id;
> > +
> > +   id = ida_simple_get(_ida, 0, 0, GFP_KERNEL);
> > +   if (id < 0)
> > +   return id;
> > +
> > +   jtag->id = id;
> > +
> > +   name = kzalloc(MAX_JTAG_NAME_LEN, GFP_KERNEL);
> > +   if (!name) {
> > +   err = -ENOMEM;
> > +   goto err_jtag_alloc;
> > +   }
> > +
> > +   err = snprintf(name, MAX_JTAG_NAME_LEN, "jtag%d", id);
> > +   if (err < 0)
> > +   goto err_jtag_name;
> > +
> > +   mutex_init(>open_lock);
> > +   jtag->miscdev.fops =  _fops;
> > +   jtag->miscdev.minor = MISC_DYNAMIC_MINOR;
> > +   jtag->miscdev.name = name;
> > +
> > +   err = misc_register(>miscdev);
> > +   if (err)
> > +   dev_err(jtag->dev, "Unable to register device\n");
> > +   else
> > +   return 0;
> > +   jtag->opened = false;
> 
> Well, this code flow is just confusing.
> 
> I suggest a redo with:
> 
>   err = misc_register(>miscdev);
>   if (err) {
>   dev_err(jtag->dev, "Unable to register device\n");
>   goto err_jtag_name;
>   }
> 
> If you need to initialize 'opened', do it prior to misc_register.
> 

Thanks

> Thanks,
>Julia

Thanks for Review.

Br,
Oleksandr



RE: [patch v16 1/4] drivers: jtag: Add JTAG core driver

2018-01-15 Thread Oleksandr Shamray
Hi Julia

> -Original Message-
> From: Julia Cartwright [mailto:jul...@eso.teric.us]
> Sent: 15 января 2018 г. 22:52
> To: Oleksandr Shamray 
> Cc: gre...@linuxfoundation.org; a...@arndb.de; linux-
> ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> devicet...@vger.kernel.org; open...@lists.ozlabs.org; j...@jms.id.au;
> j...@resnulli.us; tklau...@distanz.ch; linux-ser...@vger.kernel.org; Vadim
> Pasternak ; system-sw-low-level  le...@mellanox.com>; robh...@kernel.org; openocd-devel-
> ow...@lists.sourceforge.net; linux-...@vger.kernel.org;
> da...@davemloft.net; mche...@kernel.org; Jiri Pirko
> 
> Subject: Re: [patch v16 1/4] drivers: jtag: Add JTAG core driver
> 
> Hello Oleksandr-
> 
> I have a few comments below.
> 
> On Fri, Jan 12, 2018 at 07:08:26PM +0200, Oleksandr Shamray wrote:
> > Initial patch for JTAG driver
> > JTAG class driver provide infrastructure to support hardware/software
> > JTAG platform drivers. It provide user layer API interface for
> > flashing and debugging external devices which equipped with JTAG
> > interface using standard transactions.
> >

[..]
> > +   break;
> > +
> > +   case JTAG_IOCXFER:
> > +   if (!jtag->ops->xfer)
> 
> Are all ops optional?  That seems bizarre.  I would have expected at least one
> callback to be required.

You right. But I'm preferred to check pointers before use it.

> 
> [..]
> > +static int jtag_open(struct inode *inode, struct file *file) {
> > +   struct jtag *jtag = container_of(file->private_data, struct jtag,
> > +miscdev);
> > +
> > +   if (mutex_lock_interruptible(>open_lock))
> > +   return -ERESTARTSYS;
> > +
> > +   if (jtag->opened) {
> > +   mutex_unlock(>open_lock);
> > +   return -EBUSY;
> > +   }
> > +
> > +   nonseekable_open(inode, file);
> > +   file->private_data = jtag;
> 
> These two can be moved out of the lock.

Agree.

> 
> > +   jtag->opened = true;
> > +   mutex_unlock(>open_lock);
> > +   return 0;
> > +}
> > +
> > +static int jtag_release(struct inode *inode, struct file *file) {
> > +   struct jtag *jtag = file->private_data;
> > +
> > +   mutex_lock(>open_lock);
> > +   jtag->opened = false;
> > +   mutex_unlock(>open_lock);
> > +   return 0;
> > +}
> > +
> > +static const struct file_operations jtag_fops = {
> > +   .owner  = THIS_MODULE,
> > +   .open   = jtag_open,
> > +   .release= jtag_release,
> > +   .llseek = noop_llseek,
> > +   .unlocked_ioctl = jtag_ioctl,
> > +};
> > +
> > +struct jtag *jtag_alloc(size_t priv_size, const struct jtag_ops *ops)
> > +{
> > +   struct jtag *jtag;
> > +
> > +   jtag = kzalloc(sizeof(*jtag), GFP_KERNEL);
> 
> Did you mean to allocate: sizeof(*jtag) + priv_size?

Thank, it's a mistake.

> 
> > +   if (!jtag)
> > +   return NULL;
> > +
> > +   jtag->ops = ops;
> > +   return jtag;
> > +}
> > +EXPORT_SYMBOL_GPL(jtag_alloc);
> > +
> > +void jtag_free(struct jtag *jtag)
> > +{
> > +   kfree(jtag);
> > +}
> > +EXPORT_SYMBOL_GPL(jtag_free);
> > +
> > +int jtag_register(struct jtag *jtag)
> > +{
> > +   char *name;
> > +   int err;
> > +   int id;
> > +
> > +   id = ida_simple_get(_ida, 0, 0, GFP_KERNEL);
> > +   if (id < 0)
> > +   return id;
> > +
> > +   jtag->id = id;
> > +
> > +   name = kzalloc(MAX_JTAG_NAME_LEN, GFP_KERNEL);
> > +   if (!name) {
> > +   err = -ENOMEM;
> > +   goto err_jtag_alloc;
> > +   }
> > +
> > +   err = snprintf(name, MAX_JTAG_NAME_LEN, "jtag%d", id);
> > +   if (err < 0)
> > +   goto err_jtag_name;
> > +
> > +   mutex_init(>open_lock);
> > +   jtag->miscdev.fops =  _fops;
> > +   jtag->miscdev.minor = MISC_DYNAMIC_MINOR;
> > +   jtag->miscdev.name = name;
> > +
> > +   err = misc_register(>miscdev);
> > +   if (err)
> > +   dev_err(jtag->dev, "Unable to register device\n");
> > +   else
> > +   return 0;
> > +   jtag->opened = false;
> 
> Well, this code flow is just confusing.
> 
> I suggest a redo with:
> 
>   err = misc_register(>miscdev);
>   if (err) {
>   dev_err(jtag->dev, "Unable to register device\n");
>   goto err_jtag_name;
>   }
> 
> If you need to initialize 'opened', do it prior to misc_register.
> 

Thanks

> Thanks,
>Julia

Thanks for Review.

Br,
Oleksandr



[patch v16 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-12 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
Acked-by: Joel Stanley <j...@jms.id.au>
---
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi <ku...@google.com>
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey <c...@bilbrey.org>
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann <a...@arndb.de>
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap <rdun...@infradead.org>
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot <l...@intel.com>
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  785 
 3 files changed, 800 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 0fad1a3..63ddf1f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -14,3 +14,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   ---help---
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_ASPEED)  += jtag-aspeed.o
d

[patch v16 2/4] drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-12 Thread Oleksandr Shamray
Driver adds support of Aspeed 2500/2400 series SOC JTAG master controller.

Driver implements the following jtag ops:
- freq_get;
- freq_set;
- status_get;
- idle;
- xfer;

It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Arnd Bergmann 
Acked-by: Philippe Ombredanne 
Acked-by: Joel Stanley 
---
v15->v16
Comments pointed by Joel Stanley 
- Add reset_control on Jtag init/deinit

v14->v15
Comments pointed by Joel Stanley 
- Add ARCH_ASPEED || COMPILE_TEST to Kconfig
- remove unused offset variable
- remove "aspeed_jtag" from dev_err and dev_dbg messages
- change clk_prepare_enable initialisation order

v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag-aspeed.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
Comments pointed by Kun Yi 
- Changed capability check for aspeed,ast2400-jtag/ast200-jtag

v11->v12
Comments pointed by Chip Bilbrey 
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode

v10->v11
v9->v10
V8->v9
Comments pointed by Arnd Bergmann 
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Joel Stanley 
- aspeed_jtag_init replace goto to return;
- change input variables type from __u32 to u32
  in functios freq_get, freq_set, status_get
- change sm_ variables type from char to u8
- in jatg_init add disable clocks on error case
- remove release_mem_region on error case
- remove devm_free_irq on jtag_deinit
- Fix misspelling Disabe/Disable
- Change compatible string to ast2400 and ast2000

v6->v7
Notifications from kbuild test robot 
- Add include  to jtag-asapeed.c

v5->v6
v4->v5
Comments pointed by Arnd Bergmann 
- Added HAS_IOMEM dependence in Kconfig to avoid
  "undefined reference to `devm_ioremap_resource'" error,
  because in some arch this not supported

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32

v2->v3

v1->v2
Comments pointed by Greg KH 
- change license type from GPLv2/BSD to GPLv2

Comments pointed by Neil Armstrong 
- Add clk_prepare_enable/clk_disable_unprepare in clock init/deinit
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Added dt-bindings

Comments pointed by Arnd Bergmann 
- Reorder functions and removed the forward declarations
- Add static const qualifier to state machine states transitions
- Change .compatible to soc-specific compatible names
  aspeed,aspeed4000-jtag/aspeed5000-jtag
- Add dt-bindings

Comments pointed by Randy Dunlap 
- Change module name jtag-aspeed in description in Kconfig

Comments pointed by kbuild test robot 
- Remove invalid include 
- add resource_size instead of calculation
---
 drivers/jtag/Kconfig   |   14 +
 drivers/jtag/Makefile  |1 +
 drivers/jtag/jtag-aspeed.c |  785 
 3 files changed, 800 insertions(+), 0 deletions(-)
 create mode 100644 drivers/jtag/jtag-aspeed.c

diff --git a/drivers/jtag/Kconfig b/drivers/jtag/Kconfig
index 0fad1a3..63ddf1f 100644
--- a/drivers/jtag/Kconfig
+++ b/drivers/jtag/Kconfig
@@ -14,3 +14,17 @@ menuconfig JTAG
 
  To compile this driver as a module, choose M here: the module will
  be called jtag.
+
+menuconfig JTAG_ASPEED
+   tristate "Aspeed SoC JTAG controller support"
+   depends on JTAG && HAS_IOMEM
+   depends on ARCH_ASPEED || COMPILE_TEST
+   ---help---
+ This provides a support for Aspeed JTAG device, equipped on
+ Aspeed SoC 24xx and 25xx families. Drivers allows programming
+ of hardware devices, connected to SoC through the JTAG interface.
+
+ If you want this support, you should say Y here.
+
+ To compile this driver as a module, choose M here: the module will
+ be called jtag-aspeed.
diff --git a/drivers/jtag/Makefile b/drivers/jtag/Makefile
index af37493..04a855e 100644
--- a/drivers/jtag/Makefile
+++ b/drivers/jtag/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_JTAG) += jtag.o
+obj-$(CONFIG_JTAG_ASPEED)  += jtag-aspeed.o
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
new file mode 100644
index 000..9cbd6da
--- /dev/null
+++ b/drivers/jtag/jtag-aspeed.c
@@ -0,0 +1,785 @@
+// SPDX-License-Identifier: GPL-2.0
+// drivers/jtag/aspeed-jtag.c
+//
+// Copyright (c) 2017 Mellanox Technologies. All rights reserved.
+// Copyright (c) 2017 Oleksandr Shamray 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define ASPEED_JTAG_DATA   0x00
+#defi

[patch v16 0/4] JTAG driver introduction

2018-01-12 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   30 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  283 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  104 +++
 12 files changed, 1310 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v16 0/4] JTAG driver introduction

2018-01-12 Thread Oleksandr Shamray
When a need raise up to use JTAG interface for system's devices
programming or CPU debugging, usually the user layer
application implements jtag protocol by bit-bang or using a 
proprietary connection to vendor hardware.
This method can be slow and not generic.
 
We propose to implement general JTAG interface and infrastructure
to communicate with user layer application. In such way, we can
have the standard JTAG interface core part and separation from
specific HW implementation.
This allow new capability to debug the CPU or program system's 
device via BMC without additional devices nor cost. 

This patch purpose is to add JTAG master core infrastructure by 
defining new JTAG class and provide generic JTAG interface
to allow hardware specific drivers to connect this interface.
This will enable all JTAG drivers to use the common interface
part and will have separate for hardware implementation.

The JTAG (Joint Test Action Group) core driver provides minimal generic
JTAG interface, which can be used by hardware specific JTAG master
controllers. By providing common interface for the JTAG controllers,
user space device programing is hardware independent.
 
Modern SoC which in use for embedded system' equipped with
internal JTAG master interface.
This interface is used for programming and debugging system's
hardware components, like CPLD, FPGA, CPU, voltage and
industrial controllers.
Firmware for such devices can be upgraded through JTAG interface during
Runtime. The JTAG standard support for multiple devices programming,
is in case their lines are daisy-chained together.

For example, systems which equipped with host CPU, BMC SoC or/and 
number of programmable devices are capable to connect a pin and
select system components dynamically for programming and debugging,
This is using by the BMC which is equipped with internal SoC master
controller.
For example:

BMC JTAG master --> pin selected to CPLDs chain for programming (filed
upgrade, production) 
BMC JTAG master --> pin selected to voltage monitors for programming 
(field upgrade, production) 
BMC JTAG master --> pin selected to host CPU (on-site debugging 
and developers debugging)

For example, we can have application in user space which using calls
to JTAG driver executes CPLD programming directly from SVF file
 
The JTAG standard (IEEE 1149.1) defines the next connector pins:
- TDI (Test Data In);
- TDO (Test Data Out);
- TCK (Test Clock);
- TMS (Test Mode Select);
- TRST (Test Reset) (Optional);

The SoC equipped with JTAG master controller, performs
device programming on command or vector level. For example
a file in a standard SVF (Serial Vector Format) that contains
boundary scan vectors, can be used by sending each vector
to the JTAG interface and the JTAG controller will execute
the programming.

Initial version provides the system calls set for:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks.

SoC which are not equipped with JTAG master interface, can be built
on top of JTAG core driver infrastructure, by applying bit-banging of
TDI, TDO, TCK and TMS pins within the hardware specific driver.

Oleksandr Shamray (4):
  drivers: jtag: Add JTAG core driver
  drivers: jtag: Add Aspeed SoC 24xx and 25xx families JTAG master
driver
  Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx
families JTAG master driver
  Documentation: jtag: Add ABI documentation

 Documentation/ABI/testing/jtag-dev |   27 +
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 +
 Documentation/ioctl/ioctl-number.txt   |2 +
 MAINTAINERS|   10 +
 drivers/Kconfig|2 +
 drivers/Makefile   |1 +
 drivers/jtag/Kconfig   |   30 +
 drivers/jtag/Makefile  |2 +
 drivers/jtag/jtag-aspeed.c |  786 
 drivers/jtag/jtag.c|  283 +++
 include/linux/jtag.h   |   41 +
 include/uapi/linux/jtag.h  |  104 +++
 12 files changed, 1310 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
 create mode 100644 drivers/jtag/Kconfig
 create mode 100644 drivers/jtag/Makefile
 create mode 100644 drivers/jtag/jtag-aspeed.c
 create mode 100644 drivers/jtag/jtag.c
 create mode 100644 include/linux/jtag.h
 create mode 100644 include/uapi/linux/jtag.h



[patch v16 1/4] drivers: jtag: Add JTAG core driver

2018-01-12 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v15->v16
Commen ts pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot <l...@intel.com>
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn <and...@lunn.ch>
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism to get jtag data from inode
- Add .compat_ioctl to file ops
- Add mem alignment for jtag priv data

Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Change function names to avoid match with variable types
- Fix

[patch v16 1/4] drivers: jtag: Add JTAG core driver

2018-01-12 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v15->v16
Commen ts pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot 
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn 
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong 
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann 
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism to get jtag data from inode
- Add .compat_ioctl to file ops
- Add mem alignment for jtag priv data

Comments pointed by Tobias Klauser 
- Change function names to avoid match with variable types
- Fix description for jtag_ru_test_idle in uapi jtag.h
- Fix misprints IDEL/IDLE, trough/through
---
 Documentation/ioctl/ioctl-number.txt |2 +
 MAINTAINERS  |   10 ++
 drivers/Kconfig  |2 +
 drivers/Makefile |1 +
 drivers/jtag/Kconfig |   16 ++
 drivers/jtag/Makefile|1 +
 drivers/jtag/jtag.c  |  283 ++
 include/linux/jtag.h |   41 +
 include/uapi/linux/jtag.h

[patch v16 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-12 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Rob Herring <r...@kernel.org>
---
v15->v16
Comments pointed by Joel Stanley <joel.s...@gmail.com>
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley <joel.s...@gmail.com>
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring <r...@kernel.org>
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring <r...@kernel.org>
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 drivers/jtag/jtag-aspeed.c |1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
index 9cbd6da..f679041 100644
--- a/drivers/jtag/jtag-aspeed.c
+++ b/drivers/jtag/jtag-aspeed.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
1.7.1



[patch v16 3/4] Documentation: jtag: Add bindings for Aspeed SoC 24xx and 25xx families JTAG master driver

2018-01-12 Thread Oleksandr Shamray
It has been tested on Mellanox system with BMC equipped with
Aspeed 2520 SoC for programming CPLD devices.

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Rob Herring 
---
v15->v16
Comments pointed by Joel Stanley 
- change clocks = <_apb> to proper clocks = < ASPEED_CLK_APB>
- add reset descriptions in bndings file

v14->v15
v13->v14
v12->v13
v11->v12
v10->v11
v9->v10
v8->v9
v7->v8
Comments pointed by pointed by Joel Stanley 
- Change compatible string to ast2400 and ast2000

V6->v7
Comments pointed by Tobias Klauser 
 - Fix spell "Doccumentation" -> "Documentation"

v5->v6
Comments pointed by Tobias Klauser 
- Small nit: s/documentation/Documentation/

v4->v5

V3->v4
Comments pointed by Rob Herring 
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file

v2->v3
Comments pointed by Rob Herring 
- split Aspeed jtag driver and binding to sepatrate patches
- delete unnecessary "status" and "reg-shift" descriptions in
  bndings file
---
 .../devicetree/bindings/jtag/aspeed-jtag.txt   |   22 
 drivers/jtag/jtag-aspeed.c |1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/jtag/aspeed-jtag.txt

diff --git a/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt 
b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
new file mode 100644
index 000..7c36eb6
--- /dev/null
+++ b/Documentation/devicetree/bindings/jtag/aspeed-jtag.txt
@@ -0,0 +1,22 @@
+Aspeed JTAG driver for ast2400 and ast2500 SoC
+
+Required properties:
+- compatible:  Should be one of
+  - "aspeed,ast2400-jtag"
+  - "aspeed,ast2500-jtag"
+- reg  contains the offset and length of the JTAG memory
+   region
+- clocks   root clock of bus, should reference the APB
+   clock in the second cell
+- resets   phandle to reset controller with the reset number in
+   the second cell
+- interrupts   should contain JTAG controller interrupt
+
+Example:
+jtag: jtag@1e6e4000 {
+   compatible = "aspeed,ast2500-jtag";
+   reg = <0x1e6e4000 0x1c>;
+   clocks = < ASPEED_CLK_APB>;
+   resets = < ASPEED_RESET_JTAG_MASTER>;
+   interrupts = <43>;
+};
diff --git a/drivers/jtag/jtag-aspeed.c b/drivers/jtag/jtag-aspeed.c
index 9cbd6da..f679041 100644
--- a/drivers/jtag/jtag-aspeed.c
+++ b/drivers/jtag/jtag-aspeed.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-- 
1.7.1



[patch v16 4/4] Documentation: jtag: Add ABI documentation

2018-01-12 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Acked-by: Arnd Bergmann <a...@arndb.de>
---
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser <tklau...@distanz.ch>
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek <pa...@ucw.cz>
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..cea9552
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  October 2017
+KernelVersion: 4.17
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
\ No newline at end of file
-- 
1.7.1



[patch v16 4/4] Documentation: jtag: Add ABI documentation

2018-01-12 Thread Oleksandr Shamray
Added document that describe the ABI for JTAG class drivrer

Signed-off-by: Oleksandr Shamray 
Acked-by: Arnd Bergmann 
---
v15->v16
v14->v15
v13->v14
v12->v13
v11->v12
Tobias Klauser 
- rename /Documentation/ABI/testing/jatg-dev -> jtag-dev
- Typo: s/interfase/interface
v10->v11
v9->v10
Fixes added by Oleksandr:
- change jtag-cdev to jtag-dev in documentation
- update Kernel Version and Date in jtag-dev documentation;
v8->v9
v7->v8
v6->v7
Comments pointed by Pavel Machek 
- Added jtag-cdev documentation to Documentation/ABI/testing folder
---
 Documentation/ABI/testing/jtag-dev |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/jtag-dev

diff --git a/Documentation/ABI/testing/jtag-dev 
b/Documentation/ABI/testing/jtag-dev
new file mode 100644
index 000..cea9552
--- /dev/null
+++ b/Documentation/ABI/testing/jtag-dev
@@ -0,0 +1,27 @@
+What:  /dev/jtag[0-9]+
+Date:  October 2017
+KernelVersion: 4.17
+Contact:   oleksan...@mellanox.com
+Description:
+   The misc device files /dev/jtag* are the interface
+   between JTAG master interface and userspace.
+
+   The ioctl(2)-based ABI is defined and documented in
+   [include/uapi].
+
+   The following file operations are supported:
+
+   open(2)
+   The argument flag currently support only one access
+   mode O_RDWR.
+
+   ioctl(2)
+   Initiate various actions.
+   See the inline documentation in [include/uapi]
+   for descriptions of all ioctls.
+
+   close(2)
+   Stops and free up the I/O contexts that was associated
+   with the file descriptor.
+
+Users: TBD
\ No newline at end of file
-- 
1.7.1



RE: [patch v16 1/4] Linux 4.15-rc6

2018-01-12 Thread Oleksandr Shamray
do not pay attention about this.

Best Regards,
Oleksandr Shamray

> -Original Message-
> From: Oleksandr Shamray [mailto:oleksan...@mellanox.com]
> Sent: 12 января 2018 г. 18:55
> To: gre...@linuxfoundation.org; a...@arndb.de
> Cc: linux-kernel@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> devicet...@vger.kernel.org; open...@lists.ozlabs.org; j...@jms.id.au;
> j...@resnulli.us; tklau...@distanz.ch; linux-ser...@vger.kernel.org; Vadim
> Pasternak <vad...@mellanox.com>; system-sw-low-level  le...@mellanox.com>; robh...@kernel.org; openocd-devel-
> ow...@lists.sourceforge.net; linux-...@vger.kernel.org;
> da...@davemloft.net; mche...@kernel.org; Linus Torvalds
> <torva...@linux-foundation.org>
> Subject: [patch v16 1/4] Linux 4.15-rc6
> 
> From: Linus Torvalds <torva...@linux-foundation.org>
> 
> ---
>  Makefile |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 92b74bc..eb1f597 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2,7 +2,7 @@
>  VERSION = 4
>  PATCHLEVEL = 15
>  SUBLEVEL = 0
> -EXTRAVERSION = -rc5
> +EXTRAVERSION = -rc6
>  NAME = Fearless Coyote
> 
>  # *DOCUMENTATION*
> --
> 1.7.1



RE: [patch v16 1/4] Linux 4.15-rc6

2018-01-12 Thread Oleksandr Shamray
do not pay attention about this.

Best Regards,
Oleksandr Shamray

> -Original Message-
> From: Oleksandr Shamray [mailto:oleksan...@mellanox.com]
> Sent: 12 января 2018 г. 18:55
> To: gre...@linuxfoundation.org; a...@arndb.de
> Cc: linux-kernel@vger.kernel.org; linux-arm-ker...@lists.infradead.org;
> devicet...@vger.kernel.org; open...@lists.ozlabs.org; j...@jms.id.au;
> j...@resnulli.us; tklau...@distanz.ch; linux-ser...@vger.kernel.org; Vadim
> Pasternak ; system-sw-low-level  le...@mellanox.com>; robh...@kernel.org; openocd-devel-
> ow...@lists.sourceforge.net; linux-...@vger.kernel.org;
> da...@davemloft.net; mche...@kernel.org; Linus Torvalds
> 
> Subject: [patch v16 1/4] Linux 4.15-rc6
> 
> From: Linus Torvalds 
> 
> ---
>  Makefile |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 92b74bc..eb1f597 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -2,7 +2,7 @@
>  VERSION = 4
>  PATCHLEVEL = 15
>  SUBLEVEL = 0
> -EXTRAVERSION = -rc5
> +EXTRAVERSION = -rc6
>  NAME = Fearless Coyote
> 
>  # *DOCUMENTATION*
> --
> 1.7.1



[patch v16 2/4] drivers: jtag: Add JTAG core driver

2018-01-12 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray <oleksan...@mellanox.com>
Signed-off-by: Jiri Pirko <j...@mellanox.com>
Acked-by: Philippe Ombredanne <pombreda...@nexb.com>
---
v15->v16
Commen ts pointed by Florian Fainelli <f.faine...@gmail.com>
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne <pombreda...@nexb.com>
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey <c...@bilbrey.org>
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot <l...@intel.com>
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann <a...@arndb.de>
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer <moritz.fisc...@ettus.com>
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot <l...@intel.com>
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann <a...@arndb.de>
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot <l...@intel.com>
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH <gre...@linuxfoundation.org>
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn <and...@lunn.ch>
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong <narmstr...@baylibre.com>
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann <a...@arndb.de>
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism to get jtag data from inode
- Add .compat_ioctl to file ops
- Add mem alignment for jtag priv data

Comments pointed by Tobias Klauser <tklau...@distanz.ch>
- Change function names to avoid match with variable types
- Fix

[patch v16 2/4] drivers: jtag: Add JTAG core driver

2018-01-12 Thread Oleksandr Shamray
Initial patch for JTAG driver
JTAG class driver provide infrastructure to support hardware/software
JTAG platform drivers. It provide user layer API interface for flashing
and debugging external devices which equipped with JTAG interface
using standard transactions.

Driver exposes set of IOCTL to user space for:
- XFER:
- SIR (Scan Instruction Register, IEEE 1149.1 Data Register scan);
- SDR (Scan Data Register, IEEE 1149.1 Instruction Register scan);
- RUNTEST (Forces the IEEE 1149.1 bus to a run state for a specified
  number of clocks).
- SIOCFREQ/GIOCFREQ for setting and reading JTAG frequency.

Driver core provides set of internal APIs for allocation and
registration:
- jtag_register;
- jtag_unregister;
- jtag_alloc;
- jtag_free;

Platform driver on registration with jtag-core creates the next
entry in dev folder:
/dev/jtagX

Signed-off-by: Oleksandr Shamray 
Signed-off-by: Jiri Pirko 
Acked-by: Philippe Ombredanne 
---
v15->v16
Commen ts pointed by Florian Fainelli 
- move check jtag->ops->* in ioctl before get_user()
- change error type -EINVAL --> -EBUSY on open already opened jtag
- remove unnecessary ARCH_DMA_MINALIGN flag from kzalloc
- remove define ARCH_DMA_MINALIGN

v14->v15
v13->v14
Comments pointed by Philippe Ombredanne 
- Change style of head block comment from /**/ to //

v12->v13
Comments pointed by Philippe Ombredanne 
- Change jtag.c licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description
v11->v12
Comments pointed by Greg KH 
- Change jtag.h licence type to
  SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
  and reorder line with license in description

Chip Bilbrey 
- Remove Apeed reference from uapi jtag.h header
- Remove access mode from xfer and idle transactions
- Add new ioctl JTAG_SIOCMODE for set hw mode
- Add only one open per JTAG port blocking with mutex blocking

v10->v11
Notifications from kbuild test robot 
- include types.h headeri to jtag.h
- fix incompatible type of xfer callback
- remove rdundant class defination
- Fix return order in case of xfer error

V9->v10
Comments pointed by Greg KH 
- remove unnecessary alignment for pirv data
- move jtag_copy_to_user and jtag_copy_from_user code just to ioctl
- move int jtag_run_test_idle_op and jtag_xfer_op code
  just to ioctl
- change return error codes to more applicable
- add missing error checks
- fix error check order in ioctl
- remove unnecessary blank lines
- add param validation to ioctl
- remove compat_ioctl
- remove only one open per JTAG port blocking.
  User will care about this.
- Fix idr memory leak on jtag_exit
- change cdev device type to misc

V8->v9
Comments pointed by Arnd Bergmann 
- use get_user() instead of __get_user().
- change jtag->open type from int to atomic_t
- remove spinlock on jtg_open
- remove mutex on jtag_register
- add unregister_chrdev_region on jtag_init err
- add unregister_chrdev_region on jtag_exit
- remove unnecessary pointer casts
- add *data parameter to xfer function prototype

v7->v8
Comments pointed by Moritz Fischer 
- Fix misspelling s/friver/driver

v6->v7
Notifications from kbuild test robot 
- Remove include asm/types.h from jtag.h
- Add include  to jtag.c

v5->v6
v4->v5

v3->v4
Comments pointed by Arnd Bergmann 
- change transaction pointer tdio type  to __u64
- change internal status type from enum to __u32
- reorder jtag_xfer members to avoid the implied padding
- add __packed attribute to jtag_xfer and jtag_run_test_idle

v2->v3
Notifications from kbuild test robot 
- Change include path to  in jtag.h

v1->v2
Comments pointed by Greg KH 
- Change license type from GPLv2/BSD to GPLv2
- Change type of variables which crossed user/kernel to __type
- Remove "default n" from Kconfig

Comments pointed by Andrew Lunn 
- Change list_add_tail in jtag_unregister to list_del

Comments pointed by Neil Armstrong 
- Add SPDX-License-Identifier instead of license text

Comments pointed by Arnd Bergmann 
- Change __copy_to_user to memdup_user
- Change __put_user to put_user
- Change type of variables to __type for compatible 32 and 64-bit systems
- Add check for maximum xfer data size
- Change lookup data mechanism to get jtag data from inode
- Add .compat_ioctl to file ops
- Add mem alignment for jtag priv data

Comments pointed by Tobias Klauser 
- Change function names to avoid match with variable types
- Fix description for jtag_ru_test_idle in uapi jtag.h
- Fix misprints IDEL/IDLE, trough/through
---
 Documentation/ioctl/ioctl-number.txt |2 +
 MAINTAINERS  |   10 ++
 drivers/Kconfig  |2 +
 drivers/Makefile |1 +
 drivers/jtag/Kconfig |   16 ++
 drivers/jtag/Makefile|1 +
 drivers/jtag/jtag.c  |  283 ++
 include/linux/jtag.h |   41 +
 include/uapi/linux/jtag.h

  1   2   3   >