[U-Boot] [PATCH 1/9 v2] Exynos: Change get_timer() to work correctly

Alexei Fedorov Alexei.Fedorov at arm.com
Thu Mar 28 17:41:56 CET 2013


Dear Akshay,
You wrote
"(PCLK = 66 MHz)"
To be precise it's 66.(6)MHz.
Regards.
Alexei.


-----Original Message-----
From: u-boot-bounces at lists.denx.de [mailto:u-boot-bounces at lists.denx.de] On Behalf Of u-boot-request at lists.denx.de
Sent: 28 March 2013 15:22
To: u-boot at lists.denx.de
Subject: U-Boot Digest, Vol 58, Issue 49

Send U-Boot mailing list submissions to
        u-boot at lists.denx.de

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.denx.de/mailman/listinfo/u-boot
or, via email, send a message with subject or body 'help' to
        u-boot-request at lists.denx.de

You can reach the person managing the list at
        u-boot-owner at lists.denx.de

When replying, please edit your Subject line so it is more specific
than "Re: Contents of U-Boot digest..."


Today's Topics:

   1. [PATCH 2/5] powerpc/pamu : PAMU configuration for accessing
      SEC block (Ruchika Gupta)
   2. [PATCH 3/5] drivers/sec : Freescale SEC driver (Ruchika Gupta)
   3. [PATCH 0/5] FSL SECURE BOOT: Add support for next level   image
      validation (Ruchika Gupta)
   4. [PATCH 4/5] FSL SEC Driver : Add support for descriptor
      creation (Ruchika Gupta)
   5. [PATCH 1/5] arch/powerpc/cpu/mpc8xxx: PAMU driver support
      (Ruchika Gupta)
   6. [PATCH 5/5] Added command for validation of images in case        of
      secure boot (Ruchika Gupta)
   7. Re: [PATCH V2] ARM: bcm2835: fix get_timer() to return ms
      (Albert ARIBAUD)
   8. Re: Splash Screen Enable in (u-boot-2013.01.01.tar.bz2)
      U-boot source code. (nandakumar.ramaswamy at pricoltech.com)
   9. Re: Splash Screen Enable in (u-boot-2013.01.01.tar.bz2)
      U-boot source code. ( Andreas Bie?mann )
  10. [PATCH v3 1/7] cros: add cros_ec driver (Hung-ying Tyan)
  11. Re: Splash Screen Enable in (u-boot-2013.01.01.tar.bz2)
      U-boot source code. (Fabio Estevam)
  12. Re: Splash Screen Enable in (u-boot-2013.01.01.tar.bz2)
      U-boot source code. (Fabio Estevam)
  13. Merge conflict on Tegra SPI between u-boot/master and
      u-boot-arm/master (Albert ARIBAUD)
  14. Re: Splash Screen Enable in (u-boot-2013.01.01.tar.bz2)
      U-boot source code. (Anatolij Gustschin)
  15. Re: [PATCH 1/9 v2] Exynos: Change get_timer() to work
      correctly (Akshay Saraswat)
  16. Re: [PATCH v2] mx6: Fix get_board_rev() for the mx6 solo  case
      (Eric Nelson)
  17. Re: [PATCH 3/9 v2] Exynos: pwm: Fix two bugs in the exynos
      pwm configuration code (Akshay Saraswat)
  18. Re: [PATCH 4/9 v2] Exynos: Avoid a divide by zero by
      specifying a non-zero period for pwm 4 (Akshay Saraswat)
  19. [PATCH 00/11 v3] Fix and Re-organise PWM Timer (Akshay Saraswat)
  20. [PATCH 01/11 v3] Exynos5: config: enable time command
      (Akshay Saraswat)
  21. [PATCH 02/11 v3] Exynos: Change get_timer() to work       correctly
      (Akshay Saraswat)
  22. [PATCH 03/11 v3] Exynos: Add timer_get_us function
      (Akshay Saraswat)
  23. [PATCH 04/11 v3] Exynos: pwm: Fix two bugs in the exynos pwm
      configuration code (Akshay Saraswat)
  24. [PATCH 05/11 v3] Exynos: Avoid a divide by zero by specifying
      a non-zero period for pwm 4 (Akshay Saraswat)
  25. [PATCH 08/11 v3] Exynos: clock: Add generic api to get the
      clk freq (Akshay Saraswat)
  26. [PATCH 09/11 v3] Exynos: clock: Correct pwm source clk
      selection (Akshay Saraswat)
  27. [PATCH 11/11 v3] Exynos: pwm: Remove dead code of function
      exynos5_get_pwm_clk (Akshay Saraswat)
  28. [PATCH 10/11 v3] Exynos: pwm: Use generic api to get pwm  clk
      freq (Akshay Saraswat)
  29. [PATCH 06/11 v3] Exynos: Tidy up the pwm_config function in
      the exynos pwm driver (Akshay Saraswat)
  30. Re: [RFC/PATCH 0/4] BCH8 support for OMAP3 (Tom Rini)
  31. Re: [PATCH 1/7] USB: Some cleanup prior to USB 3.0        interface
      addition (Marek Vasut)
  32. Re: [PATCH 2/7] usb: hub: Conditionally power on usb's
      root-hub ports (Marek Vasut)
  33. Re: [PATCH 3/7] usb: Update device class in usb device's
      descriptor (Marek Vasut)
  34. Re: [PATCH 5/7] usb: hub: Increase device enumeration     timeout
      for broken drives (Marek Vasut)
  35. Re: [PATCH 6/7] USB: SS: Add support for Super Speed USB
      interface (Marek Vasut)
  36. Re: [PATCH v9 01/30] mtd: nand: Introduce
      CONFIG_SYS_NAND_BUSWIDTH_16BIT (Beno?t Th?baudeau)
  37. Re: [PATCH 0/5] FSL SECURE BOOT: Add support for next level
      image validation (Otavio Salvador)
  38. Re: [PATCH V2] ARM: bcm2835: fix get_timer() to return ms
      (Stephen Warren)
  39. Re: Merge conflict on Tegra SPI between u-boot/master and
      u-boot-arm/master (Tom Warren)
  40. Re: [PATCH] ARM: bcm2835: fix get_timer() to return mS
      (Stephen Warren)
  41. Re: [PATCH V2] ARM: bcm2835: fix get_timer() to return ms
      (Albert ARIBAUD)
  42. Re: [PATCH v9 01/30] mtd: nand: Introduce
      CONFIG_SYS_NAND_BUSWIDTH_16BIT (Albert ARIBAUD)
  43. Re: Merge conflict on Tegra SPI between u-boot/master and
      u-boot-arm/master (Tom Warren)
  44. Re: [PATCH 1/1 v2] omap3_beagle: Enabling UART3 first allows
      the Transmitter to be empty (Tom Rini)
  45. Re: [PATCH 1/1 v2] omap3_beagle: Enabling UART3 first allows
      the Transmitter to be empty (Tom Rini)


----------------------------------------------------------------------

Message: 1
Date: Thu, 28 Mar 2013 16:16:32 +0530
From: Ruchika Gupta <ruchika.gupta at freescale.com>
Subject: [U-Boot] [PATCH 2/5] powerpc/pamu : PAMU configuration for
        accessing SEC block
To: <u-boot at lists.denx.de>, <afleming at freescale.com>
Cc: Kuldip Giroh <kuldip.giroh at freescale.com>,  Ruchika Gupta
        <ruchika.gupta at freescale.com>
Message-ID:
        <1364467595-15539-3-git-send-email-ruchika.gupta at freescale.com>
Content-Type: text/plain

Signed-off-by: Kuldip Giroh <kuldip.giroh at freescale.com>
Signed-off-by: Ruchika Gupta <ruchika.gupta at freescale.com>
---
Based upon git://git.denx.de/u-boot.git branch master

 arch/powerpc/cpu/mpc8xxx/Makefile         |    2 +-
 arch/powerpc/cpu/mpc8xxx/fsl_pamu_table.c |   68 +++++++++++++++++++++++++++++
 arch/powerpc/include/asm/fsl_pamu.h       |    1 +
 3 files changed, 70 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/cpu/mpc8xxx/fsl_pamu_table.c

diff --git a/arch/powerpc/cpu/mpc8xxx/Makefile b/arch/powerpc/cpu/mpc8xxx/Makefile
index 097599e..7099136 100644
--- a/arch/powerpc/cpu/mpc8xxx/Makefile
+++ b/arch/powerpc/cpu/mpc8xxx/Makefile
@@ -33,7 +33,7 @@ COBJS-$(CONFIG_FSL_IFC) += fsl_ifc.o
 COBJS-$(CONFIG_FSL_LBC) += fsl_lbc.o
 COBJS-$(CONFIG_SYS_SRIO) += srio.o
 COBJS-$(CONFIG_FSL_LAW) += law.o
-COBJS-$(CONFIG_FSL_CORENET) += fsl_pamu.o
+COBJS-$(CONFIG_FSL_CORENET) += fsl_pamu.o fsl_pamu_table.o

 endif

diff --git a/arch/powerpc/cpu/mpc8xxx/fsl_pamu_table.c b/arch/powerpc/cpu/mpc8xxx/fsl_pamu_table.c
new file mode 100644
index 0000000..44cceee
--- /dev/null
+++ b/arch/powerpc/cpu/mpc8xxx/fsl_pamu_table.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <asm/fsl_pamu.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+void construct_pamu_addr_table(struct pamu_addr_tbl *tbl, int *num_entries)
+{
+       int i  = 0;
+
+       tbl->start_addr[i] =
+                       (uint64_t)virt_to_phys((void *)CONFIG_SYS_SDRAM_BASE);
+       tbl->size[i] = (phys_size_t)(min(gd->ram_size, CONFIG_MAX_MEM_MAPPED));
+       tbl->end_addr[i] = tbl->start_addr[i] +  tbl->size[i] - 1;
+
+       i++;
+       tbl->start_addr[i] =
+               (uint64_t)virt_to_phys((void *)CONFIG_SYS_FLASH_BASE_PHYS);
+       tbl->size[i] = 256 * 1024 * 1024; /* 256MB flash */
+       tbl->end_addr[i] = tbl->start_addr[i] +  tbl->size[i] - 1;
+
+       i++;
+#ifdef DEBUG
+       int j;
+       printf("address\t\t\tsize\n");
+       for (j = 0; j < i ; j++)
+               printf("%llx \t\t\t%llx\n",  tbl->start_addr[j],  tbl->size[j]);
+#endif
+
+       *num_entries = i;
+}
+
+int sec_config_pamu_table(uint32_t liodn_ns, uint32_t liodn_s)
+{
+       struct pamu_addr_tbl tbl;
+       int num_entries = 0;
+       int ret = 0;
+
+       construct_pamu_addr_table(&tbl, &num_entries);
+
+       ret = config_pamu(&tbl, num_entries, liodn_ns);
+       if (ret)
+               return ret;
+
+       ret = config_pamu(&tbl, num_entries, liodn_s);
+       if (ret)
+               return ret;
+
+       return ret;
+}
diff --git a/arch/powerpc/include/asm/fsl_pamu.h b/arch/powerpc/include/asm/fsl_pamu.h
index e2cfe97..85ef9bf 100644
--- a/arch/powerpc/include/asm/fsl_pamu.h
+++ b/arch/powerpc/include/asm/fsl_pamu.h
@@ -189,5 +189,6 @@ int pamu_init(void);
 void pamu_enable(void);
 void pamu_disable(void);
 int config_pamu(struct pamu_addr_tbl *tbl, int num_entries, uint32_t liodn);
+int sec_config_pamu_table(uint32_t liodn_ns, uint32_t liodn_s);

 #endif
--
1.7.7.6




------------------------------

Message: 2
Date: Thu, 28 Mar 2013 16:16:33 +0530
From: Ruchika Gupta <ruchika.gupta at freescale.com>
Subject: [U-Boot] [PATCH 3/5] drivers/sec : Freescale SEC driver
To: <u-boot at lists.denx.de>, <afleming at freescale.com>
Cc: Kuldip Giroh <kuldip.giroh at freescale.com>,  Ruchika Gupta
        <ruchika.gupta at freescale.com>
Message-ID:
        <1364467595-15539-4-git-send-email-ruchika.gupta at freescale.com>
Content-Type: text/plain

SEC driver support is required in secure boot

Following files have been picked up from caam driver in Linux :
        include/desc.h

The file drivers/sec/jr.c has some functions derived from caam driver in
Linux.

Signed-off-by: Kuldip Giroh <kuldip.giroh at freescale.com>
Signed-off-by: Ruchika Gupta <ruchika.gupta at freescale.com>
---
Based upon git://git.denx.de/u-boot.git branch master

 Makefile                              |    1 +
 arch/powerpc/include/asm/immap_85xx.h |   50 +-
 arch/powerpc/include/asm/types.h      |    5 +-
 drivers/sec/Makefile                  |   46 +
 drivers/sec/jr.c                      |  319 +++++++
 include/desc.h                        | 1605 +++++++++++++++++++++++++++++++++
 include/jr.h                          |  129 +++
 7 files changed, 2152 insertions(+), 3 deletions(-)
 create mode 100644 drivers/sec/Makefile
 create mode 100644 drivers/sec/jr.c
 create mode 100644 include/desc.h
 create mode 100644 include/jr.h

diff --git a/Makefile b/Makefile
index 12763ce..2b63585 100644
--- a/Makefile
+++ b/Makefile
@@ -329,6 +329,7 @@ LIBS-y += common/libcommon.o
 LIBS-y += lib/libfdt/libfdt.o
 LIBS-y += api/libapi.o
 LIBS-y += post/libpost.o
+LIBS-y += drivers/sec/libsec.o
 LIBS-y += test/libtest.o

 ifneq ($(CONFIG_AM33XX)$(CONFIG_OMAP34XX)$(CONFIG_OMAP44XX)$(CONFIG_OMAP54XX),)
diff --git a/arch/powerpc/include/asm/immap_85xx.h b/arch/powerpc/include/asm/immap_85xx.h
index 17e0f39..ac8f608 100644
--- a/arch/powerpc/include/asm/immap_85xx.h
+++ b/arch/powerpc/include/asm/immap_85xx.h
@@ -2692,6 +2692,50 @@ enum {

 /* Security Engine Block (MS = Most Sig., LS = Least Sig.) */
 #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
+/*
+ *   caam_job_ring - direct job ring setup
+ *   1-4 possible per instantiation, base + 1000/2000/3000/4000
+ *   Padded out to 0x1000
+ */
+typedef struct jr_regs {
+       /* Input Ring */
+       u32 irba_h;             /*IRBAx -  Input desc ring baseaddr */
+       u32 irba_l;
+       u8 res1[4];
+       u32 irs;                /*IRSx - Input ring size */
+       u8 res2[4];
+       u32 irsa;               /* IRSAx - Input ring room remaining */
+       u8 res3[4];
+       u32 irja;               /* IRJAx - Input ring jobs added */
+
+       /* Output ring */
+       u32 orba_h;              /* ORBAx - Output status ring base addr */
+       u32 orba_l;
+       u8 res4[4];
+       u32 ors;                 /* ORSx - Output ring size */
+       u8 res5[4];
+       u32 orjr;                /* ORJRx - Output ring jobs removed */
+       u8 res6[4];
+       u32 orsf;                /* ORSFx - Output ring slots full */
+
+       /* Status /Configuration */
+       u8 res7[4];
+       u32 jrsta;              /* JRSTAx - JobR output status */
+       u8 res8[4];             /* JRINTx - JobR interrupt status */
+       u32 jrint;              /* JRINTx - JobR interrupt status */
+       u32 jrcfg0;             /* JRxCFG - Ring configuration */
+       u32 jrcfg1;
+
+       /*Index. CAAM maintains "head" of each queue */
+       u8 res9[4];
+       u32 irri;               /* IRRIx - Input ring read index */
+       u8 res10[4];
+       u32 orwi;               /* ORWIx - Output ring write index */
+       u8 res11[4];
+       u32 jrcr;               /* JRCRx - JobR command */
+       u8 res12[0xf90];
+} jr_regs_t;
+
 typedef struct ccsr_sec {
        u32     res0;
        u32     mcfgr;          /* Master CFG Register */
@@ -2735,7 +2779,8 @@ typedef struct ccsr_sec {
        u32     chanum_ls;      /* CHA Number Register, LS */
        u32     secvid_ms;      /* SEC Version ID Register, MS */
        u32     secvid_ls;      /* SEC Version ID Register, LS */
-       u8      res9[0x6020];
+       struct jr_regs jr[4];   /* SEC JOB RINGS */
+       u8      res9[0x2020];
        u32     qilcr_ms;       /* Queue Interface LIODN CFG Register, MS */
        u32     qilcr_ls;       /* Queue Interface LIODN CFG Register, LS */
        u8      res10[0x8fd8];
@@ -2828,7 +2873,7 @@ typedef struct ccsr_pme {
        u32     pm_ip_rev_2;    /* PME IP Block Revision Reg 1*/
        u8      res4[0x400];
 } ccsr_pme_t;
-
+
 typedef struct ccsr_pamu {
        u32 ppbah;
        u32 ppbal;
@@ -2949,6 +2994,7 @@ struct ccsr_pman {
 #define CONFIG_SYS_MPC85xx_SATA1_OFFSET                0x220000
 #define CONFIG_SYS_MPC85xx_SATA2_OFFSET                0x221000
 #define CONFIG_SYS_FSL_SEC_OFFSET              0x300000
+#define CONFIG_SYS_SNVS_OFFSET                 0x314000
 #define CONFIG_SYS_FSL_CORENET_PME_OFFSET      0x316000
 #define CONFIG_SYS_FSL_QMAN_OFFSET             0x318000
 #define CONFIG_SYS_FSL_BMAN_OFFSET             0x31a000
diff --git a/arch/powerpc/include/asm/types.h b/arch/powerpc/include/asm/types.h
index b27a6b7..ec9a4c3 100644
--- a/arch/powerpc/include/asm/types.h
+++ b/arch/powerpc/include/asm/types.h
@@ -41,8 +41,11 @@ typedef unsigned long long u64;

 #define BITS_PER_LONG 32

-/* DMA addresses are 32-bits wide */
+#ifdef CONFIG_PHYS_64BIT
+typedef unsigned long long dma_addr_t;
+#else
 typedef u32 dma_addr_t;
+#endif

 #ifdef CONFIG_PHYS_64BIT
 typedef unsigned long long phys_addr_t;
diff --git a/drivers/sec/Makefile b/drivers/sec/Makefile
new file mode 100644
index 0000000..33c707e
--- /dev/null
+++ b/drivers/sec/Makefile
@@ -0,0 +1,46 @@
+#
+# (C) Copyright 2000-2007, 2012
+# Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+include $(TOPDIR)/config.mk
+
+LIB    := $(obj)libsec.o
+
+COBJS-$(CONFIG_SECURE_BOOT) += jr.o
+
+COBJS  := $(COBJS-y)
+SRCS   := $(COBJS:.o=.c)
+OBJS   := $(addprefix $(obj),$(COBJS))
+
+all:   $(LIB)
+
+$(LIB):        $(obj).depend $(OBJS)
+       $(call cmd_link_o_target, $(OBJS))
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
diff --git a/drivers/sec/jr.c b/drivers/sec/jr.c
new file mode 100644
index 0000000..1399be6
--- /dev/null
+++ b/drivers/sec/jr.c
@@ -0,0 +1,319 @@
+/*
+ * Copyright 2011, 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <asm/immap_85xx.h>
+#include <jr.h>
+#include <asm/fsl_pamu.h>
+
+#define CIRC_CNT(head, tail, size)     (((head) - (tail)) & (size - 1))
+#define CIRC_SPACE(head, tail, size)   CIRC_CNT((tail), (head) + 1, (size))
+
+struct jobring jr;
+
+static inline void jr_reset_liodn(void)
+{
+       ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
+       out_be32(&sec->jrliodnr[0].ls, 0);
+       asm volatile("sync" : : : "memory");
+}
+
+static inline void jr_disable_irq(void)
+{
+       ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
+       struct jr_regs *regs = &sec->jr[0];
+       uint32_t jrcfg = in_be32(&regs->jrcfg1);
+
+       jrcfg = jrcfg | JR_INTMASK;
+
+       out_be32(&regs->jrcfg1, jrcfg);
+       asm volatile("sync" : : : "memory");
+
+}
+
+static void jr_initregs(struct jobring *jr)
+{
+       ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
+       struct jr_regs *regs = &sec->jr[0];
+       phys_addr_t ip_base = virt_to_phys((void *)jr->input_ring);
+       phys_addr_t op_base = virt_to_phys((void *)jr->output_ring);
+
+#ifdef CONFIG_PHYS_64BIT
+       out_be32(&regs->irba_h, ip_base >> 32);
+#else
+       out_be32(&regs->irba_h, 0x0);
+#endif
+       out_be32(&regs->irba_l, (uint32_t)ip_base);
+#ifdef CONFIG_PHYS_64BIT
+       out_be32(&regs->orba_h, op_base >> 32);
+#else
+       out_be32(&regs->orba_h, 0x0);
+#endif
+       out_be32(&regs->orba_l, (uint32_t)op_base);
+       out_be32(&regs->ors, JR_SIZE);
+       out_be32(&regs->irs, JR_SIZE);
+
+       asm volatile("sync" : : : "memory");
+       if (!jr->irq)
+               jr_disable_irq();
+}
+
+int jr_init(struct jobring *jr)
+{
+       memset(jr, 0, sizeof(struct jobring));
+
+       jr->jq_id = DEFAULT_JR_ID;
+       jr->irq = DEFAULT_IRQ;
+
+#ifdef CONFIG_FSL_CORENET
+       jr->liodn = DEFAULT_JR_LIODN;
+#endif
+       jr->size = JR_SIZE;
+       jr->input_ring = (dma_addr_t *) malloc(JR_SIZE * sizeof(dma_addr_t));
+       if (!jr->input_ring)
+               return -1;
+       jr->output_ring =
+           (struct op_ring *)malloc(JR_SIZE * sizeof(struct op_ring));
+       if (!jr->output_ring)
+               return -1;
+
+       memset(jr->input_ring, 0, JR_SIZE * sizeof(dma_addr_t));
+       memset(jr->output_ring, 0, JR_SIZE * sizeof(struct op_ring));
+
+       jr_initregs(jr);
+
+       return 0;
+}
+
+int jr_sw_cleanup(struct jobring *jr)
+{
+       jr->head = 0;
+       jr->tail = 0;
+       jr->read_idx = 0;
+       jr->write_idx = 0;
+       memset(jr->info, 0, sizeof(jr->info));
+       memset(jr->input_ring, 0, jr->size * sizeof(dma_addr_t));
+       memset(jr->output_ring, 0, jr->size * sizeof(struct op_ring));
+
+       return 0;
+}
+
+int sec_init(void)
+{
+       int ret = 0;
+
+#ifdef CONFIG_FSL_CORENET
+       uint32_t liodnr;
+       uint32_t liodn_ns;
+       uint32_t liodn_s;
+#endif
+
+#ifdef CONFIG_PHYS_64BIT
+       ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
+       uint32_t mcr = in_be32(&sec->mcfgr);
+
+       out_be32(&sec->mcfgr, mcr | 1 << MCFGR_PS_SHIFT);
+#endif
+
+#ifdef CONFIG_FSL_CORENET
+       liodnr = in_be32(&sec->jrliodnr[0].ls);
+       liodn_ns = (liodnr & JRNSLIODN_MASK) >> JRNSLIODN_SHIFT;
+       liodn_s = (liodnr & JRSLIODN_MASK) >> JRSLIODN_SHIFT;
+#endif
+       ret = jr_init(&jr);
+       if (ret < 0)
+               return -1;
+
+#ifdef CONFIG_FSL_CORENET
+       ret = sec_config_pamu_table(liodn_ns, liodn_s);
+       if (ret < 0)
+               return -1;
+#endif
+
+       return ret;
+}
+
+int jr_hw_reset(void)
+{
+       ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
+       struct jr_regs *regs = &sec->jr[0];
+       uint32_t timeout = 100000;
+       uint32_t jrint, jrcr;
+
+       out_be32(&regs->jrcr, JRCR_RESET);
+       do {
+               jrint = in_be32(&regs->jrint);
+       } while (((jrint & JRINT_ERR_HALT_MASK) ==
+                 JRINT_ERR_HALT_INPROGRESS) && --timeout);
+
+       jrint = in_be32(&regs->jrint);
+       if (((jrint & JRINT_ERR_HALT_MASK) !=
+            JRINT_ERR_HALT_INPROGRESS) && timeout == 0)
+               return -1;
+
+       timeout = 100000;
+       out_be32(&regs->jrcr, JRCR_RESET);
+       do {
+               jrcr = in_be32(&regs->jrcr);
+       } while ((jrcr & JRCR_RESET) && --timeout);
+
+       if (timeout == 0)
+               return -1;
+
+       return 0;
+}
+
+int jr_reset(void)
+{
+       if (jr_hw_reset() < 0)
+               return -1;
+
+       /* Clean up the jobring structure maintained by software */
+       jr_sw_cleanup(&jr);
+
+       return 0;
+}
+
+int sec_reset(void)
+{
+       ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
+       uint32_t mcfgr = in_be32(&sec->mcfgr);
+       uint32_t timeout = 100000;
+
+       mcfgr |= MCFGR_SWRST;
+       out_be32(&sec->mcfgr, mcfgr);
+
+       mcfgr |= MCFGR_DMA_RST;
+       out_be32(&sec->mcfgr, mcfgr);
+       do {
+               mcfgr = in_be32(&sec->mcfgr);
+       } while ((mcfgr & MCFGR_DMA_RST) == MCFGR_DMA_RST && --timeout);
+
+       if (timeout == 0)
+               return -1;
+
+       timeout = 100000;
+       do {
+               mcfgr = in_be32(&sec->mcfgr);
+       } while ((mcfgr & MCFGR_SWRST) == MCFGR_SWRST && --timeout);
+
+       if (timeout == 0)
+               return -1;
+
+       return 0;
+}
+
+/* -1 --- error, can't enqueue -- no space available */
+int jr_enqueue(struct jobring *jr, uint32_t * desc_addr,
+              void (*callback) (uint32_t desc, uint32_t status, void *arg),
+              void *arg)
+{
+       ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
+       struct jr_regs *regs = &sec->jr[0];
+       int head = jr->head;
+       dma_addr_t desc_phys_addr = virt_to_phys(desc_addr);
+
+       if (in_be32(&regs->irsa) == 0
+           || CIRC_SPACE(jr->head, jr->tail, jr->size) <= 0)
+               return JQ_ENQ_ERR;
+
+       jr->input_ring[head] = desc_phys_addr;
+       jr->info[head].desc_phys_addr = desc_phys_addr;
+       jr->info[head].desc_addr = (uint32_t) desc_addr;
+       jr->info[head].callback = (void *) callback;
+       jr->info[head].arg = arg;
+       jr->info[head].op_done = 0;
+
+       jr->head = (head + 1) & (jr->size - 1);
+
+       out_be32(&regs->irja, 1);
+       asm volatile("sync" : : : "memory");
+
+       return 0;
+}
+
+int jr_dequeue(struct jobring *jr)
+{
+       ccsr_sec_t *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
+       struct jr_regs *regs = &sec->jr[0];
+       int head = jr->head;
+       int tail = jr->tail;
+       int idx, i, found;
+       void (*callback) (uint32_t desc, uint32_t status, void *arg);
+       void *arg = NULL;
+
+       while (in_be32(&regs->orsf) && CIRC_CNT(jr->head, jr->tail, jr->size)) {
+               found = 0;
+
+               dma_addr_t op_desc = jr->output_ring[jr->tail].desc;
+               uint32_t status = jr->output_ring[jr->tail].status;
+               uint32_t desc_virt;
+
+               for (i = 0; CIRC_CNT(head, tail + i, jr->size) >= 1; i++) {
+                       idx = (tail + i) & (jr->size - 1);
+                       if (op_desc == jr->info[idx].desc_phys_addr) {
+                               desc_virt = jr->info[idx].desc_addr;
+                               found = 1;
+                               break;
+                       }
+               }
+
+               /* Error condition if match not found */
+               if (!found)
+                       return JQ_DEQ_ERR;
+
+               jr->info[idx].op_done = 1;
+               callback = (void *) jr->info[idx].callback;
+               arg = jr->info[idx].arg;
+
+               /* When the job on tail idx gets done, increment
+                * tail till the point where job completed out of oredr has
+                * been taken into account
+                */
+               if (idx == tail)
+                       do {
+                               tail = (tail + 1) & (jr->size - 1);
+                       } while (jr->info[tail].op_done);
+
+               jr->tail = tail;
+               jr->read_idx = (jr->read_idx + 1) & (jr->size - 1);
+
+               out_be32(&regs->orjr, 1);
+               asm volatile("sync" : : : "memory");
+               jr->info[idx].op_done = 0;
+
+               callback(desc_virt, status, arg);
+       }
+
+       return 0;
+}
diff --git a/include/desc.h b/include/desc.h
new file mode 100644
index 0000000..1b0b080
--- /dev/null
+++ b/include/desc.h
@@ -0,0 +1,1605 @@
+/*
+ * CAAM descriptor composition header
+ * Definitions to support CAAM descriptor instruction generation
+ *
+ * Copyright 2008-2011, 2012 Freescale Semiconductor, Inc.
+ */
+
+#ifndef DESC_H
+#define DESC_H
+
+/* Max size of any CAAM descriptor in 32-bit words, inclusive of header */
+#define MAX_CAAM_DESCSIZE       64
+
+/* Block size of any entity covered/uncovered with a KEK/TKEK */
+#define KEK_BLOCKSIZE          16
+
+/*
+ * Supported descriptor command types as they show up
+ * inside a descriptor command word.
+ */
+#define CMD_SHIFT               27
+#define CMD_MASK                0xf8000000
+
+#define CMD_KEY                 (0x00 << CMD_SHIFT)
+#define CMD_SEQ_KEY             (0x01 << CMD_SHIFT)
+#define CMD_LOAD                (0x02 << CMD_SHIFT)
+#define CMD_SEQ_LOAD            (0x03 << CMD_SHIFT)
+#define CMD_FIFO_LOAD           (0x04 << CMD_SHIFT)
+#define CMD_SEQ_FIFO_LOAD       (0x05 << CMD_SHIFT)
+#define CMD_STORE               (0x0a << CMD_SHIFT)
+#define CMD_SEQ_STORE           (0x0b << CMD_SHIFT)
+#define CMD_FIFO_STORE          (0x0c << CMD_SHIFT)
+#define CMD_SEQ_FIFO_STORE      (0x0d << CMD_SHIFT)
+#define CMD_MOVE_LEN            (0x0e << CMD_SHIFT)
+#define CMD_MOVE                (0x0f << CMD_SHIFT)
+#define CMD_OPERATION           (0x10 << CMD_SHIFT)
+#define CMD_SIGNATURE           (0x12 << CMD_SHIFT)
+#define CMD_JUMP                (0x14 << CMD_SHIFT)
+#define CMD_MATH                (0x15 << CMD_SHIFT)
+#define CMD_DESC_HDR            (0x16 << CMD_SHIFT)
+#define CMD_SHARED_DESC_HDR     (0x17 << CMD_SHIFT)
+#define CMD_SEQ_IN_PTR          (0x1e << CMD_SHIFT)
+#define CMD_SEQ_OUT_PTR         (0x1f << CMD_SHIFT)
+
+/* General-purpose class selector for all commands */
+#define CLASS_SHIFT             25
+#define CLASS_MASK              (0x03 << CLASS_SHIFT)
+
+#define CLASS_NONE              (0x00 << CLASS_SHIFT)
+#define CLASS_1                 (0x01 << CLASS_SHIFT)
+#define CLASS_2                 (0x02 << CLASS_SHIFT)
+#define CLASS_BOTH              (0x03 << CLASS_SHIFT)
+
+/*
+ * Descriptor header command constructs
+ * Covers shared, job, and trusted descriptor headers
+ */
+
+/*
+ * Do Not Run - marks a descriptor inexecutable if there was
+ * a preceding error somewhere
+ */
+#define HDR_DNR                 0x01000000
+
+/*
+ * ONE - should always be set. Combination of ONE (always
+ * set) and ZRO (always clear) forms an endianness sanity check
+ */
+#define HDR_ONE                 0x00800000
+#define HDR_ZRO                 0x00008000
+
+/* Start Index or SharedDesc Length */
+#define HDR_START_IDX_MASK      0x3f
+#define HDR_START_IDX_SHIFT     16
+
+/* If shared descriptor header, 6-bit length */
+#define HDR_DESCLEN_SHR_MASK  0x3f
+
+/* If non-shared header, 7-bit length */
+#define HDR_DESCLEN_MASK      0x7f
+
+/* This is a TrustedDesc (if not SharedDesc) */
+#define HDR_TRUSTED             0x00004000
+
+/* Make into TrustedDesc (if not SharedDesc) */
+#define HDR_MAKE_TRUSTED        0x00002000
+
+/* Save context if self-shared (if SharedDesc) */
+#define HDR_SAVECTX             0x00001000
+
+/* Next item points to SharedDesc */
+#define HDR_SHARED              0x00001000
+
+/*
+ * Reverse Execution Order - execute JobDesc first, then
+ * execute SharedDesc (normally SharedDesc goes first).
+ */
+#define HDR_REVERSE             0x00000800
+
+/* Propogate DNR property to SharedDesc */
+#define HDR_PROP_DNR            0x00000800
+
+/* JobDesc/SharedDesc share property */
+#define HDR_SD_SHARE_MASK       0x03
+#define HDR_SD_SHARE_SHIFT      8
+#define HDR_JD_SHARE_MASK       0x07
+#define HDR_JD_SHARE_SHIFT      8
+
+#define HDR_SHARE_NEVER         (0x00 << HDR_SD_SHARE_SHIFT)
+#define HDR_SHARE_WAIT          (0x01 << HDR_SD_SHARE_SHIFT)
+#define HDR_SHARE_SERIAL        (0x02 << HDR_SD_SHARE_SHIFT)
+#define HDR_SHARE_ALWAYS        (0x03 << HDR_SD_SHARE_SHIFT)
+#define HDR_SHARE_DEFER         (0x04 << HDR_SD_SHARE_SHIFT)
+
+/* JobDesc/SharedDesc descriptor length */
+#define HDR_JD_LENGTH_MASK      0x7f
+#define HDR_SD_LENGTH_MASK      0x3f
+
+/*
+ * KEY/SEQ_KEY Command Constructs
+ */
+
+/* Key Destination Class: 01 = Class 1, 02 - Class 2  */
+#define KEY_DEST_CLASS_SHIFT    25  /* use CLASS_1 or CLASS_2 */
+#define KEY_DEST_CLASS_MASK     (0x03 << KEY_DEST_CLASS_SHIFT)
+
+/* Scatter-Gather Table/Variable Length Field */
+#define KEY_SGF                 0x01000000
+#define KEY_VLF                 0x01000000
+
+/* Immediate - Key follows command in the descriptor */
+#define KEY_IMM                 0x00800000
+
+/*
+ * Encrypted - Key is encrypted either with the KEK, or
+ * with the TDKEK if TK is set
+ */
+#define KEY_ENC                 0x00400000
+
+/*
+ * No Write Back - Do not allow key to be FIFO STOREd
+ */
+#define KEY_NWB                        0x00200000
+
+/*
+ * Enhanced Encryption of Key
+ */
+#define KEY_EKT                        0x00100000
+
+/*
+ * Encrypted with Trusted Key
+ */
+#define KEY_TK                 0x00008000
+
+/*
+ * KDEST - Key Destination: 0 - class key register,
+ * 1 - PKHA 'e', 2 - AFHA Sbox, 3 - MDHA split-key
+ */
+#define KEY_DEST_SHIFT          16
+#define KEY_DEST_MASK           (0x03 << KEY_DEST_SHIFT)
+
+#define KEY_DEST_CLASS_REG      (0x00 << KEY_DEST_SHIFT)
+#define KEY_DEST_PKHA_E         (0x01 << KEY_DEST_SHIFT)
+#define KEY_DEST_AFHA_SBOX      (0x02 << KEY_DEST_SHIFT)
+#define KEY_DEST_MDHA_SPLIT     (0x03 << KEY_DEST_SHIFT)
+
+/* Length in bytes */
+#define KEY_LENGTH_MASK         0x000003ff
+
+/*
+ * LOAD/SEQ_LOAD/STORE/SEQ_STORE Command Constructs
+ */
+
+/*
+ * Load/Store Destination: 0 = class independent CCB,
+ * 1 = class 1 CCB, 2 = class 2 CCB, 3 = DECO
+ */
+#define LDST_CLASS_SHIFT        25
+#define LDST_CLASS_MASK         (0x03 << LDST_CLASS_SHIFT)
+#define LDST_CLASS_IND_CCB      (0x00 << LDST_CLASS_SHIFT)
+#define LDST_CLASS_1_CCB        (0x01 << LDST_CLASS_SHIFT)
+#define LDST_CLASS_2_CCB        (0x02 << LDST_CLASS_SHIFT)
+#define LDST_CLASS_DECO         (0x03 << LDST_CLASS_SHIFT)
+
+/* Scatter-Gather Table/Variable Length Field */
+#define LDST_SGF                0x01000000
+#define LDST_VLF               LDST_SGF
+
+/* Immediate - Key follows this command in descriptor    */
+#define LDST_IMM_MASK           1
+#define LDST_IMM_SHIFT          23
+#define LDST_IMM                (LDST_IMM_MASK << LDST_IMM_SHIFT)
+
+/* SRC/DST - Destination for LOAD, Source for STORE   */
+#define LDST_SRCDST_SHIFT       16
+#define LDST_SRCDST_MASK        (0x7f << LDST_SRCDST_SHIFT)
+
+#define LDST_SRCDST_BYTE_CONTEXT       (0x20 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_BYTE_KEY           (0x40 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_BYTE_INFIFO                (0x7c << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_BYTE_OUTFIFO       (0x7e << LDST_SRCDST_SHIFT)
+
+#define LDST_SRCDST_WORD_MODE_REG      (0x00 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_KEYSZ_REG     (0x01 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DATASZ_REG    (0x02 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_ICVSZ_REG     (0x03 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_CHACTRL       (0x06 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DECOCTRL       (0x06 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_IRQCTRL       (0x07 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DECO_PCLOVRD   (0x07 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_CLRW          (0x08 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DECO_MATH0     (0x08 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_STAT          (0x09 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DECO_MATH1     (0x09 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DECO_MATH2     (0x0a << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DECO_AAD_SZ    (0x0b << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DECO_MATH3     (0x0b << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_CLASS1_ICV_SZ  (0x0c << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_ALTDS_CLASS1   (0x0f << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_PKHA_A_SZ      (0x10 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_PKHA_B_SZ      (0x11 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_PKHA_N_SZ      (0x12 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_PKHA_E_SZ      (0x13 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_DESCBUF        (0x40 << LDST_SRCDST_SHIFT)
+#define LDST_SRCDST_WORD_INFO_FIFO      (0x7a << LDST_SRCDST_SHIFT)
+
+/* Offset in source/destination                        */
+#define LDST_OFFSET_SHIFT       8
+#define LDST_OFFSET_MASK        (0xff << LDST_OFFSET_SHIFT)
+
+/* LDOFF definitions used when DST = LDST_SRCDST_WORD_DECOCTRL */
+/* These could also be shifted by LDST_OFFSET_SHIFT - this reads better */
+#define LDOFF_CHG_SHARE_SHIFT        0
+#define LDOFF_CHG_SHARE_MASK         (0x3 << LDOFF_CHG_SHARE_SHIFT)
+#define LDOFF_CHG_SHARE_NEVER        (0x1 << LDOFF_CHG_SHARE_SHIFT)
+#define LDOFF_CHG_SHARE_OK_NO_PROP   (0x2 << LDOFF_CHG_SHARE_SHIFT)
+#define LDOFF_CHG_SHARE_OK_PROP      (0x3 << LDOFF_CHG_SHARE_SHIFT)
+
+#define LDOFF_ENABLE_AUTO_NFIFO         (1 << 2)
+#define LDOFF_DISABLE_AUTO_NFIFO        (1 << 3)
+
+#define LDOFF_CHG_NONSEQLIODN_SHIFT     4
+#define LDOFF_CHG_NONSEQLIODN_MASK      (0x3 << LDOFF_CHG_NONSEQLIODN_SHIFT)
+#define LDOFF_CHG_NONSEQLIODN_SEQ       (0x1 << LDOFF_CHG_NONSEQLIODN_SHIFT)
+#define LDOFF_CHG_NONSEQLIODN_NON_SEQ   (0x2 << LDOFF_CHG_NONSEQLIODN_SHIFT)
+#define LDOFF_CHG_NONSEQLIODN_TRUSTED   (0x3 << LDOFF_CHG_NONSEQLIODN_SHIFT)
+
+#define LDOFF_CHG_SEQLIODN_SHIFT     6
+#define LDOFF_CHG_SEQLIODN_MASK      (0x3 << LDOFF_CHG_SEQLIODN_SHIFT)
+#define LDOFF_CHG_SEQLIODN_SEQ       (0x1 << LDOFF_CHG_SEQLIODN_SHIFT)
+#define LDOFF_CHG_SEQLIODN_NON_SEQ   (0x2 << LDOFF_CHG_SEQLIODN_SHIFT)
+#define LDOFF_CHG_SEQLIODN_TRUSTED   (0x3 << LDOFF_CHG_SEQLIODN_SHIFT)
+
+/* Data length in bytes                                 */
+#define LDST_LEN_SHIFT          0
+#define LDST_LEN_MASK           (0xff << LDST_LEN_SHIFT)
+
+/* Special Length definitions when dst=deco-ctrl */
+#define LDLEN_ENABLE_OSL_COUNT      (1 << 7)
+#define LDLEN_RST_CHA_OFIFO_PTR     (1 << 6)
+#define LDLEN_RST_OFIFO             (1 << 5)
+#define LDLEN_SET_OFIFO_OFF_VALID   (1 << 4)
+#define LDLEN_SET_OFIFO_OFF_RSVD    (1 << 3)
+#define LDLEN_SET_OFIFO_OFFSET_SHIFT 0
+#define LDLEN_SET_OFIFO_OFFSET_MASK (3 << LDLEN_SET_OFIFO_OFFSET_SHIFT)
+
+/*
+ * FIFO_LOAD/FIFO_STORE/SEQ_FIFO_LOAD/SEQ_FIFO_STORE
+ * Command Constructs
+ */
+
+/*
+ * Load Destination: 0 = skip (SEQ_FIFO_LOAD only),
+ * 1 = Load for Class1, 2 = Load for Class2, 3 = Load both
+ * Store Source: 0 = normal, 1 = Class1key, 2 = Class2key
+ */
+#define FIFOLD_CLASS_SHIFT      25
+#define FIFOLD_CLASS_MASK       (0x03 << FIFOLD_CLASS_SHIFT)
+#define FIFOLD_CLASS_SKIP       (0x00 << FIFOLD_CLASS_SHIFT)
+#define FIFOLD_CLASS_CLASS1     (0x01 << FIFOLD_CLASS_SHIFT)
+#define FIFOLD_CLASS_CLASS2     (0x02 << FIFOLD_CLASS_SHIFT)
+#define FIFOLD_CLASS_BOTH       (0x03 << FIFOLD_CLASS_SHIFT)
+
+#define FIFOST_CLASS_SHIFT      25
+#define FIFOST_CLASS_MASK       (0x03 << FIFOST_CLASS_SHIFT)
+#define FIFOST_CLASS_NORMAL     (0x00 << FIFOST_CLASS_SHIFT)
+#define FIFOST_CLASS_CLASS1KEY  (0x01 << FIFOST_CLASS_SHIFT)
+#define FIFOST_CLASS_CLASS2KEY  (0x02 << FIFOST_CLASS_SHIFT)
+
+/*
+ * Scatter-Gather Table/Variable Length Field
+ * If set for FIFO_LOAD, refers to a SG table. Within
+ * SEQ_FIFO_LOAD, is variable input sequence
+ */
+#define FIFOLDST_SGF_SHIFT      24
+#define FIFOLDST_SGF_MASK       (1 << FIFOLDST_SGF_SHIFT)
+#define FIFOLDST_VLF_MASK       (1 << FIFOLDST_SGF_SHIFT)
+#define FIFOLDST_SGF            (1 << FIFOLDST_SGF_SHIFT)
+#define FIFOLDST_VLF            (1 << FIFOLDST_SGF_SHIFT)
+
+/* Immediate - Data follows command in descriptor */
+#define FIFOLD_IMM_SHIFT      23
+#define FIFOLD_IMM_MASK       (1 << FIFOLD_IMM_SHIFT)
+#define FIFOLD_IMM            (1 << FIFOLD_IMM_SHIFT)
+
+/* Continue - Not the last FIFO store to come */
+#define FIFOST_CONT_SHIFT     23
+#define FIFOST_CONT_MASK      (1 << FIFOST_CONT_SHIFT)
+#define FIFOST_CONT_MASK      (1 << FIFOST_CONT_SHIFT)
+
+/*
+ * Extended Length - use 32-bit extended length that
+ * follows the pointer field. Illegal with IMM set
+ */
+#define FIFOLDST_EXT_SHIFT      22
+#define FIFOLDST_EXT_MASK       (1 << FIFOLDST_EXT_SHIFT)
+#define FIFOLDST_EXT            (1 << FIFOLDST_EXT_SHIFT)
+
+/* Input data type.*/
+#define FIFOLD_TYPE_SHIFT       16
+#define FIFOLD_CONT_TYPE_SHIFT  19 /* shift past last-flush bits */
+#define FIFOLD_TYPE_MASK        (0x3f << FIFOLD_TYPE_SHIFT)
+
+/* PK types */
+#define FIFOLD_TYPE_PK          (0x00 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_MASK     (0x30 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_TYPEMASK (0x0f << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_A0       (0x00 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_A1       (0x01 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_A2       (0x02 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_A3       (0x03 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_B0       (0x04 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_B1       (0x05 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_B2       (0x06 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_B3       (0x07 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_N        (0x08 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_A        (0x0c << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_PK_B        (0x0d << FIFOLD_TYPE_SHIFT)
+
+/* Other types. Need to OR in last/flush bits as desired */
+#define FIFOLD_TYPE_MSG_MASK    (0x38 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_MSG         (0x10 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_MSG1OUT2    (0x18 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_IV          (0x20 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_BITDATA     (0x28 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_AAD         (0x30 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_ICV         (0x38 << FIFOLD_TYPE_SHIFT)
+
+/* Last/Flush bits for use with "other" types above */
+#define FIFOLD_TYPE_ACT_MASK    (0x07 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_NOACTION    (0x00 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_FLUSH1      (0x01 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_LAST1       (0x02 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_LAST2FLUSH  (0x03 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_LAST2       (0x04 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_LAST2FLUSH1 (0x05 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_LASTBOTH    (0x06 << FIFOLD_TYPE_SHIFT)
+#define FIFOLD_TYPE_LASTBOTHFL  (0x07 << FIFOLD_TYPE_SHIFT)
+
+#define FIFOLDST_LEN_MASK       0xffff
+#define FIFOLDST_EXT_LEN_MASK   0xffffffff
+
+/* Output data types */
+#define FIFOST_TYPE_SHIFT       16
+#define FIFOST_TYPE_MASK        (0x3f << FIFOST_TYPE_SHIFT)
+
+#define FIFOST_TYPE_PKHA_A0      (0x00 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_A1      (0x01 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_A2      (0x02 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_A3      (0x03 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_B0      (0x04 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_B1      (0x05 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_B2      (0x06 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_B3      (0x07 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_N       (0x08 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_A       (0x0c << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_B       (0x0d << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_AF_SBOX_JKEK (0x10 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_AF_SBOX_TKEK (0x21 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_E_JKEK  (0x22 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_PKHA_E_TKEK  (0x23 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_KEY_KEK      (0x24 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_KEY_TKEK     (0x25 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_SPLIT_KEK    (0x26 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_SPLIT_TKEK   (0x27 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_OUTFIFO_KEK  (0x28 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_OUTFIFO_TKEK (0x29 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_MESSAGE_DATA (0x30 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_RNGSTORE     (0x34 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_RNGFIFO      (0x35 << FIFOST_TYPE_SHIFT)
+#define FIFOST_TYPE_SKIP         (0x3f << FIFOST_TYPE_SHIFT)
+
+/*
+ * OPERATION Command Constructs
+ */
+
+/* Operation type selectors - OP TYPE */
+#define OP_TYPE_SHIFT           24
+#define OP_TYPE_MASK            (0x07 << OP_TYPE_SHIFT)
+
+#define OP_TYPE_UNI_PROTOCOL    (0x00 << OP_TYPE_SHIFT)
+#define OP_TYPE_PK              (0x01 << OP_TYPE_SHIFT)
+#define OP_TYPE_CLASS1_ALG      (0x02 << OP_TYPE_SHIFT)
+#define OP_TYPE_CLASS2_ALG      (0x04 << OP_TYPE_SHIFT)
+#define OP_TYPE_DECAP_PROTOCOL  (0x06 << OP_TYPE_SHIFT)
+#define OP_TYPE_ENCAP_PROTOCOL  (0x07 << OP_TYPE_SHIFT)
+
+/* ProtocolID selectors - PROTID */
+#define OP_PCLID_SHIFT          16
+#define OP_PCLID_MASK           (0xff << 16)
+
+/* Assuming OP_TYPE = OP_TYPE_UNI_PROTOCOL */
+#define OP_PCLID_IKEV1_PRF      (0x01 << OP_PCLID_SHIFT)
+#define OP_PCLID_IKEV2_PRF      (0x02 << OP_PCLID_SHIFT)
+#define OP_PCLID_SSL30_PRF      (0x08 << OP_PCLID_SHIFT)
+#define OP_PCLID_TLS10_PRF      (0x09 << OP_PCLID_SHIFT)
+#define OP_PCLID_TLS11_PRF      (0x0a << OP_PCLID_SHIFT)
+#define OP_PCLID_DTLS10_PRF     (0x0c << OP_PCLID_SHIFT)
+#define OP_PCLID_PRF            (0x06 << OP_PCLID_SHIFT)
+#define OP_PCLID_BLOB           (0x0d << OP_PCLID_SHIFT)
+#define OP_PCLID_SECRETKEY      (0x11 << OP_PCLID_SHIFT)
+#define OP_PCLID_PUBLICKEYPAIR  (0x14 << OP_PCLID_SHIFT)
+#define OP_PCLID_DSASIGN        (0x15 << OP_PCLID_SHIFT)
+#define OP_PCLID_DSAVERIFY      (0x16 << OP_PCLID_SHIFT)
+
+/* Assuming OP_TYPE = OP_TYPE_DECAP_PROTOCOL/ENCAP_PROTOCOL */
+#define OP_PCLID_IPSEC          (0x01 << OP_PCLID_SHIFT)
+#define OP_PCLID_SRTP           (0x02 << OP_PCLID_SHIFT)
+#define OP_PCLID_MACSEC         (0x03 << OP_PCLID_SHIFT)
+#define OP_PCLID_WIFI           (0x04 << OP_PCLID_SHIFT)
+#define OP_PCLID_WIMAX          (0x05 << OP_PCLID_SHIFT)
+#define OP_PCLID_SSL30          (0x08 << OP_PCLID_SHIFT)
+#define OP_PCLID_TLS10          (0x09 << OP_PCLID_SHIFT)
+#define OP_PCLID_TLS11          (0x0a << OP_PCLID_SHIFT)
+#define OP_PCLID_TLS12          (0x0b << OP_PCLID_SHIFT)
+#define OP_PCLID_DTLS           (0x0c << OP_PCLID_SHIFT)
+
+/*
+ * ProtocolInfo selectors
+ */
+#define OP_PCLINFO_MASK                          0xffff
+
+/* for OP_PCLID_IPSEC */
+#define OP_PCL_IPSEC_CIPHER_MASK                 0xff00
+#define OP_PCL_IPSEC_AUTH_MASK                   0x00ff
+
+#define OP_PCL_IPSEC_DES_IV64                    0x0100
+#define OP_PCL_IPSEC_DES                         0x0200
+#define OP_PCL_IPSEC_3DES                        0x0300
+#define OP_PCL_IPSEC_AES_CBC                     0x0c00
+#define OP_PCL_IPSEC_AES_CTR                     0x0d00
+#define OP_PCL_IPSEC_AES_XTS                     0x1600
+#define OP_PCL_IPSEC_AES_CCM8                    0x0e00
+#define OP_PCL_IPSEC_AES_CCM12                   0x0f00
+#define OP_PCL_IPSEC_AES_CCM16                   0x1000
+#define OP_PCL_IPSEC_AES_GCM8                    0x1200
+#define OP_PCL_IPSEC_AES_GCM12                   0x1300
+#define OP_PCL_IPSEC_AES_GCM16                   0x1400
+
+#define OP_PCL_IPSEC_HMAC_NULL                   0x0000
+#define OP_PCL_IPSEC_HMAC_MD5_96                 0x0001
+#define OP_PCL_IPSEC_HMAC_SHA1_96                0x0002
+#define OP_PCL_IPSEC_AES_XCBC_MAC_96             0x0005
+#define OP_PCL_IPSEC_HMAC_MD5_128                0x0006
+#define OP_PCL_IPSEC_HMAC_SHA1_160               0x0007
+#define OP_PCL_IPSEC_HMAC_SHA2_256_128           0x000c
+#define OP_PCL_IPSEC_HMAC_SHA2_384_192           0x000d
+#define OP_PCL_IPSEC_HMAC_SHA2_512_256           0x000e
+
+/* For SRTP - OP_PCLID_SRTP */
+#define OP_PCL_SRTP_CIPHER_MASK                  0xff00
+#define OP_PCL_SRTP_AUTH_MASK                    0x00ff
+
+#define OP_PCL_SRTP_AES_CTR                      0x0d00
+
+#define OP_PCL_SRTP_HMAC_SHA1_160                0x0007
+
+/* For SSL 3.0 - OP_PCLID_SSL30 */
+#define OP_PCL_SSL30_AES_128_CBC_SHA             0x002f
+#define OP_PCL_SSL30_AES_128_CBC_SHA_2           0x0030
+#define OP_PCL_SSL30_AES_128_CBC_SHA_3           0x0031
+#define OP_PCL_SSL30_AES_128_CBC_SHA_4           0x0032
+#define OP_PCL_SSL30_AES_128_CBC_SHA_5           0x0033
+#define OP_PCL_SSL30_AES_128_CBC_SHA_6           0x0034
+#define OP_PCL_SSL30_AES_128_CBC_SHA_7           0x008c
+#define OP_PCL_SSL30_AES_128_CBC_SHA_8           0x0090
+#define OP_PCL_SSL30_AES_128_CBC_SHA_9           0x0094
+#define OP_PCL_SSL30_AES_128_CBC_SHA_10          0xc004
+#define OP_PCL_SSL30_AES_128_CBC_SHA_11          0xc009
+#define OP_PCL_SSL30_AES_128_CBC_SHA_12          0xc00e
+#define OP_PCL_SSL30_AES_128_CBC_SHA_13          0xc013
+#define OP_PCL_SSL30_AES_128_CBC_SHA_14          0xc018
+#define OP_PCL_SSL30_AES_128_CBC_SHA_15          0xc01d
+#define OP_PCL_SSL30_AES_128_CBC_SHA_16          0xc01e
+#define OP_PCL_SSL30_AES_128_CBC_SHA_17          0xc01f
+
+#define OP_PCL_SSL30_AES_256_CBC_SHA             0x0035
+#define OP_PCL_SSL30_AES_256_CBC_SHA_2           0x0036
+#define OP_PCL_SSL30_AES_256_CBC_SHA_3           0x0037
+#define OP_PCL_SSL30_AES_256_CBC_SHA_4           0x0038
+#define OP_PCL_SSL30_AES_256_CBC_SHA_5           0x0039
+#define OP_PCL_SSL30_AES_256_CBC_SHA_6           0x003a
+#define OP_PCL_SSL30_AES_256_CBC_SHA_7           0x008d
+#define OP_PCL_SSL30_AES_256_CBC_SHA_8           0x0091
+#define OP_PCL_SSL30_AES_256_CBC_SHA_9           0x0095
+#define OP_PCL_SSL30_AES_256_CBC_SHA_10          0xc005
+#define OP_PCL_SSL30_AES_256_CBC_SHA_11          0xc00a
+#define OP_PCL_SSL30_AES_256_CBC_SHA_12          0xc00f
+#define OP_PCL_SSL30_AES_256_CBC_SHA_13          0xc014
+#define OP_PCL_SSL30_AES_256_CBC_SHA_14          0xc019
+#define OP_PCL_SSL30_AES_256_CBC_SHA_15          0xc020
+#define OP_PCL_SSL30_AES_256_CBC_SHA_16          0xc021
+#define OP_PCL_SSL30_AES_256_CBC_SHA_17          0xc022
+
+#define OP_PCL_SSL30_3DES_EDE_CBC_MD5            0x0023
+
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA            0x001f
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_2          0x008b
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_3          0x008f
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_4          0x0093
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_5          0x000a
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_6          0x000d
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_7          0x0010
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_8          0x0013
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_9          0x0016
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_10         0x001b
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_11         0xc003
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_12         0xc008
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_13         0xc00d
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_14         0xc012
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_15         0xc017
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_16         0xc01a
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_17         0xc01b
+#define OP_PCL_SSL30_3DES_EDE_CBC_SHA_18         0xc01c
+
+#define OP_PCL_SSL30_DES40_CBC_MD5               0x0029
+
+#define OP_PCL_SSL30_DES_CBC_MD5                 0x0022
+
+#define OP_PCL_SSL30_DES40_CBC_SHA               0x0008
+#define OP_PCL_SSL30_DES40_CBC_SHA_2             0x000b
+#define OP_PCL_SSL30_DES40_CBC_SHA_3             0x000e
+#define OP_PCL_SSL30_DES40_CBC_SHA_4             0x0011
+#define OP_PCL_SSL30_DES40_CBC_SHA_5             0x0014
+#define OP_PCL_SSL30_DES40_CBC_SHA_6             0x0019
+#define OP_PCL_SSL30_DES40_CBC_SHA_7             0x0026
+
+#define OP_PCL_SSL30_DES_CBC_SHA                 0x001e
+#define OP_PCL_SSL30_DES_CBC_SHA_2               0x0009
+#define OP_PCL_SSL30_DES_CBC_SHA_3               0x000c
+#define OP_PCL_SSL30_DES_CBC_SHA_4               0x000f
+#define OP_PCL_SSL30_DES_CBC_SHA_5               0x0012
+#define OP_PCL_SSL30_DES_CBC_SHA_6               0x0015
+#define OP_PCL_SSL30_DES_CBC_SHA_7               0x001a
+
+#define OP_PCL_SSL30_RC4_128_MD5                 0x0024
+#define OP_PCL_SSL30_RC4_128_MD5_2               0x0004
+#define OP_PCL_SSL30_RC4_128_MD5_3               0x0018
+
+#define OP_PCL_SSL30_RC4_40_MD5                  0x002b
+#define OP_PCL_SSL30_RC4_40_MD5_2                0x0003
+#define OP_PCL_SSL30_RC4_40_MD5_3                0x0017
+
+#define OP_PCL_SSL30_RC4_128_SHA                 0x0020
+#define OP_PCL_SSL30_RC4_128_SHA_2               0x008a
+#define OP_PCL_SSL30_RC4_128_SHA_3               0x008e
+#define OP_PCL_SSL30_RC4_128_SHA_4               0x0092
+#define OP_PCL_SSL30_RC4_128_SHA_5               0x0005
+#define OP_PCL_SSL30_RC4_128_SHA_6               0xc002
+#define OP_PCL_SSL30_RC4_128_SHA_7               0xc007
+#define OP_PCL_SSL30_RC4_128_SHA_8               0xc00c
+#define OP_PCL_SSL30_RC4_128_SHA_9               0xc011
+#define OP_PCL_SSL30_RC4_128_SHA_10              0xc016
+
+#define OP_PCL_SSL30_RC4_40_SHA                  0x0028
+
+
+/* For TLS 1.0 - OP_PCLID_TLS10 */
+#define OP_PCL_TLS10_AES_128_CBC_SHA             0x002f
+#define OP_PCL_TLS10_AES_128_CBC_SHA_2           0x0030
+#define OP_PCL_TLS10_AES_128_CBC_SHA_3           0x0031
+#define OP_PCL_TLS10_AES_128_CBC_SHA_4           0x0032
+#define OP_PCL_TLS10_AES_128_CBC_SHA_5           0x0033
+#define OP_PCL_TLS10_AES_128_CBC_SHA_6           0x0034
+#define OP_PCL_TLS10_AES_128_CBC_SHA_7           0x008c
+#define OP_PCL_TLS10_AES_128_CBC_SHA_8           0x0090
+#define OP_PCL_TLS10_AES_128_CBC_SHA_9           0x0094
+#define OP_PCL_TLS10_AES_128_CBC_SHA_10          0xc004
+#define OP_PCL_TLS10_AES_128_CBC_SHA_11          0xc009
+#define OP_PCL_TLS10_AES_128_CBC_SHA_12          0xc00e
+#define OP_PCL_TLS10_AES_128_CBC_SHA_13          0xc013
+#define OP_PCL_TLS10_AES_128_CBC_SHA_14          0xc018
+#define OP_PCL_TLS10_AES_128_CBC_SHA_15          0xc01d
+#define OP_PCL_TLS10_AES_128_CBC_SHA_16          0xc01e
+#define OP_PCL_TLS10_AES_128_CBC_SHA_17          0xc01f
+
+#define OP_PCL_TLS10_AES_256_CBC_SHA             0x0035
+#define OP_PCL_TLS10_AES_256_CBC_SHA_2           0x0036
+#define OP_PCL_TLS10_AES_256_CBC_SHA_3           0x0037
+#define OP_PCL_TLS10_AES_256_CBC_SHA_4           0x0038
+#define OP_PCL_TLS10_AES_256_CBC_SHA_5           0x0039
+#define OP_PCL_TLS10_AES_256_CBC_SHA_6           0x003a
+#define OP_PCL_TLS10_AES_256_CBC_SHA_7           0x008d
+#define OP_PCL_TLS10_AES_256_CBC_SHA_8           0x0091
+#define OP_PCL_TLS10_AES_256_CBC_SHA_9           0x0095
+#define OP_PCL_TLS10_AES_256_CBC_SHA_10          0xc005
+#define OP_PCL_TLS10_AES_256_CBC_SHA_11          0xc00a
+#define OP_PCL_TLS10_AES_256_CBC_SHA_12          0xc00f
+#define OP_PCL_TLS10_AES_256_CBC_SHA_13          0xc014
+#define OP_PCL_TLS10_AES_256_CBC_SHA_14          0xc019
+#define OP_PCL_TLS10_AES_256_CBC_SHA_15          0xc020
+#define OP_PCL_TLS10_AES_256_CBC_SHA_16          0xc021
+#define OP_PCL_TLS10_AES_256_CBC_SHA_17          0xc022
+
+/* #define OP_PCL_TLS10_3DES_EDE_CBC_MD5            0x0023 */
+
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA            0x001f
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_2          0x008b
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_3          0x008f
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_4          0x0093
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_5          0x000a
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_6          0x000d
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_7          0x0010
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_8          0x0013
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_9          0x0016
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_10         0x001b
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_11         0xc003
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_12         0xc008
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_13         0xc00d
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_14         0xc012
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_15         0xc017
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_16         0xc01a
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_17         0xc01b
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA_18         0xc01c
+
+#define OP_PCL_TLS10_DES40_CBC_MD5               0x0029
+
+#define OP_PCL_TLS10_DES_CBC_MD5                 0x0022
+
+#define OP_PCL_TLS10_DES40_CBC_SHA               0x0008
+#define OP_PCL_TLS10_DES40_CBC_SHA_2             0x000b
+#define OP_PCL_TLS10_DES40_CBC_SHA_3             0x000e
+#define OP_PCL_TLS10_DES40_CBC_SHA_4             0x0011
+#define OP_PCL_TLS10_DES40_CBC_SHA_5             0x0014
+#define OP_PCL_TLS10_DES40_CBC_SHA_6             0x0019
+#define OP_PCL_TLS10_DES40_CBC_SHA_7             0x0026
+
+
+#define OP_PCL_TLS10_DES_CBC_SHA                 0x001e
+#define OP_PCL_TLS10_DES_CBC_SHA_2               0x0009
+#define OP_PCL_TLS10_DES_CBC_SHA_3               0x000c
+#define OP_PCL_TLS10_DES_CBC_SHA_4               0x000f
+#define OP_PCL_TLS10_DES_CBC_SHA_5               0x0012
+#define OP_PCL_TLS10_DES_CBC_SHA_6               0x0015
+#define OP_PCL_TLS10_DES_CBC_SHA_7               0x001a
+
+#define OP_PCL_TLS10_RC4_128_MD5                 0x0024
+#define OP_PCL_TLS10_RC4_128_MD5_2               0x0004
+#define OP_PCL_TLS10_RC4_128_MD5_3               0x0018
+
+#define OP_PCL_TLS10_RC4_40_MD5                  0x002b
+#define OP_PCL_TLS10_RC4_40_MD5_2                0x0003
+#define OP_PCL_TLS10_RC4_40_MD5_3                0x0017
+
+#define OP_PCL_TLS10_RC4_128_SHA                 0x0020
+#define OP_PCL_TLS10_RC4_128_SHA_2               0x008a
+#define OP_PCL_TLS10_RC4_128_SHA_3               0x008e
+#define OP_PCL_TLS10_RC4_128_SHA_4               0x0092
+#define OP_PCL_TLS10_RC4_128_SHA_5               0x0005
+#define OP_PCL_TLS10_RC4_128_SHA_6               0xc002
+#define OP_PCL_TLS10_RC4_128_SHA_7               0xc007
+#define OP_PCL_TLS10_RC4_128_SHA_8               0xc00c
+#define OP_PCL_TLS10_RC4_128_SHA_9               0xc011
+#define OP_PCL_TLS10_RC4_128_SHA_10              0xc016
+
+#define OP_PCL_TLS10_RC4_40_SHA                  0x0028
+
+#define OP_PCL_TLS10_3DES_EDE_CBC_MD5            0xff23
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA160         0xff30
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA224         0xff34
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA256         0xff36
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA384         0xff33
+#define OP_PCL_TLS10_3DES_EDE_CBC_SHA512         0xff35
+#define OP_PCL_TLS10_AES_128_CBC_SHA160          0xff80
+#define OP_PCL_TLS10_AES_128_CBC_SHA224          0xff84
+#define OP_PCL_TLS10_AES_128_CBC_SHA256          0xff86
+#define OP_PCL_TLS10_AES_128_CBC_SHA384          0xff83
+#define OP_PCL_TLS10_AES_128_CBC_SHA512          0xff85
+#define OP_PCL_TLS10_AES_192_CBC_SHA160          0xff20
+#define OP_PCL_TLS10_AES_192_CBC_SHA224          0xff24
+#define OP_PCL_TLS10_AES_192_CBC_SHA256          0xff26
+#define OP_PCL_TLS10_AES_192_CBC_SHA384          0xff23
+#define OP_PCL_TLS10_AES_192_CBC_SHA512          0xff25
+#define OP_PCL_TLS10_AES_256_CBC_SHA160          0xff60
+#define OP_PCL_TLS10_AES_256_CBC_SHA224          0xff64
+#define OP_PCL_TLS10_AES_256_CBC_SHA256          0xff66
+#define OP_PCL_TLS10_AES_256_CBC_SHA384          0xff63
+#define OP_PCL_TLS10_AES_256_CBC_SHA512          0xff65
+
+
+
+/* For TLS 1.1 - OP_PCLID_TLS11 */
+#define OP_PCL_TLS11_AES_128_CBC_SHA             0x002f
+#define OP_PCL_TLS11_AES_128_CBC_SHA_2           0x0030
+#define OP_PCL_TLS11_AES_128_CBC_SHA_3           0x0031
+#define OP_PCL_TLS11_AES_128_CBC_SHA_4           0x0032
+#define OP_PCL_TLS11_AES_128_CBC_SHA_5           0x0033
+#define OP_PCL_TLS11_AES_128_CBC_SHA_6           0x0034
+#define OP_PCL_TLS11_AES_128_CBC_SHA_7           0x008c
+#define OP_PCL_TLS11_AES_128_CBC_SHA_8           0x0090
+#define OP_PCL_TLS11_AES_128_CBC_SHA_9           0x0094
+#define OP_PCL_TLS11_AES_128_CBC_SHA_10          0xc004
+#define OP_PCL_TLS11_AES_128_CBC_SHA_11          0xc009
+#define OP_PCL_TLS11_AES_128_CBC_SHA_12          0xc00e
+#define OP_PCL_TLS11_AES_128_CBC_SHA_13          0xc013
+#define OP_PCL_TLS11_AES_128_CBC_SHA_14          0xc018
+#define OP_PCL_TLS11_AES_128_CBC_SHA_15          0xc01d
+#define OP_PCL_TLS11_AES_128_CBC_SHA_16          0xc01e
+#define OP_PCL_TLS11_AES_128_CBC_SHA_17          0xc01f
+
+#define OP_PCL_TLS11_AES_256_CBC_SHA             0x0035
+#define OP_PCL_TLS11_AES_256_CBC_SHA_2           0x0036
+#define OP_PCL_TLS11_AES_256_CBC_SHA_3           0x0037
+#define OP_PCL_TLS11_AES_256_CBC_SHA_4           0x0038
+#define OP_PCL_TLS11_AES_256_CBC_SHA_5           0x0039
+#define OP_PCL_TLS11_AES_256_CBC_SHA_6           0x003a
+#define OP_PCL_TLS11_AES_256_CBC_SHA_7           0x008d
+#define OP_PCL_TLS11_AES_256_CBC_SHA_8           0x0091
+#define OP_PCL_TLS11_AES_256_CBC_SHA_9           0x0095
+#define OP_PCL_TLS11_AES_256_CBC_SHA_10          0xc005
+#define OP_PCL_TLS11_AES_256_CBC_SHA_11          0xc00a
+#define OP_PCL_TLS11_AES_256_CBC_SHA_12          0xc00f
+#define OP_PCL_TLS11_AES_256_CBC_SHA_13          0xc014
+#define OP_PCL_TLS11_AES_256_CBC_SHA_14          0xc019
+#define OP_PCL_TLS11_AES_256_CBC_SHA_15          0xc020
+#define OP_PCL_TLS11_AES_256_CBC_SHA_16          0xc021
+#define OP_PCL_TLS11_AES_256_CBC_SHA_17          0xc022
+
+/* #define OP_PCL_TLS11_3DES_EDE_CBC_MD5            0x0023 */
+
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA            0x001f
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_2          0x008b
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_3          0x008f
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_4          0x0093
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_5          0x000a
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_6          0x000d
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_7          0x0010
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_8          0x0013
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_9          0x0016
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_10         0x001b
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_11         0xc003
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_12         0xc008
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_13         0xc00d
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_14         0xc012
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_15         0xc017
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_16         0xc01a
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_17         0xc01b
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA_18         0xc01c
+
+#define OP_PCL_TLS11_DES40_CBC_MD5               0x0029
+
+#define OP_PCL_TLS11_DES_CBC_MD5                 0x0022
+
+#define OP_PCL_TLS11_DES40_CBC_SHA               0x0008
+#define OP_PCL_TLS11_DES40_CBC_SHA_2             0x000b
+#define OP_PCL_TLS11_DES40_CBC_SHA_3             0x000e
+#define OP_PCL_TLS11_DES40_CBC_SHA_4             0x0011
+#define OP_PCL_TLS11_DES40_CBC_SHA_5             0x0014
+#define OP_PCL_TLS11_DES40_CBC_SHA_6             0x0019
+#define OP_PCL_TLS11_DES40_CBC_SHA_7             0x0026
+
+#define OP_PCL_TLS11_DES_CBC_SHA                 0x001e
+#define OP_PCL_TLS11_DES_CBC_SHA_2               0x0009
+#define OP_PCL_TLS11_DES_CBC_SHA_3               0x000c
+#define OP_PCL_TLS11_DES_CBC_SHA_4               0x000f
+#define OP_PCL_TLS11_DES_CBC_SHA_5               0x0012
+#define OP_PCL_TLS11_DES_CBC_SHA_6               0x0015
+#define OP_PCL_TLS11_DES_CBC_SHA_7               0x001a
+
+#define OP_PCL_TLS11_RC4_128_MD5                 0x0024
+#define OP_PCL_TLS11_RC4_128_MD5_2               0x0004
+#define OP_PCL_TLS11_RC4_128_MD5_3               0x0018
+
+#define OP_PCL_TLS11_RC4_40_MD5                  0x002b
+#define OP_PCL_TLS11_RC4_40_MD5_2                0x0003
+#define OP_PCL_TLS11_RC4_40_MD5_3                0x0017
+
+#define OP_PCL_TLS11_RC4_128_SHA                 0x0020
+#define OP_PCL_TLS11_RC4_128_SHA_2               0x008a
+#define OP_PCL_TLS11_RC4_128_SHA_3               0x008e
+#define OP_PCL_TLS11_RC4_128_SHA_4               0x0092
+#define OP_PCL_TLS11_RC4_128_SHA_5               0x0005
+#define OP_PCL_TLS11_RC4_128_SHA_6               0xc002
+#define OP_PCL_TLS11_RC4_128_SHA_7               0xc007
+#define OP_PCL_TLS11_RC4_128_SHA_8               0xc00c
+#define OP_PCL_TLS11_RC4_128_SHA_9               0xc011
+#define OP_PCL_TLS11_RC4_128_SHA_10              0xc016
+
+#define OP_PCL_TLS11_RC4_40_SHA                  0x0028
+
+#define OP_PCL_TLS11_3DES_EDE_CBC_MD5            0xff23
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA160         0xff30
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA224         0xff34
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA256         0xff36
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA384         0xff33
+#define OP_PCL_TLS11_3DES_EDE_CBC_SHA512         0xff35
+#define OP_PCL_TLS11_AES_128_CBC_SHA160          0xff80
+#define OP_PCL_TLS11_AES_128_CBC_SHA224          0xff84
+#define OP_PCL_TLS11_AES_128_CBC_SHA256          0xff86
+#define OP_PCL_TLS11_AES_128_CBC_SHA384          0xff83
+#define OP_PCL_TLS11_AES_128_CBC_SHA512          0xff85
+#define OP_PCL_TLS11_AES_192_CBC_SHA160          0xff20
+#define OP_PCL_TLS11_AES_192_CBC_SHA224          0xff24
+#define OP_PCL_TLS11_AES_192_CBC_SHA256          0xff26
+#define OP_PCL_TLS11_AES_192_CBC_SHA384          0xff23
+#define OP_PCL_TLS11_AES_192_CBC_SHA512          0xff25
+#define OP_PCL_TLS11_AES_256_CBC_SHA160          0xff60
+#define OP_PCL_TLS11_AES_256_CBC_SHA224          0xff64
+#define OP_PCL_TLS11_AES_256_CBC_SHA256          0xff66
+#define OP_PCL_TLS11_AES_256_CBC_SHA384          0xff63
+#define OP_PCL_TLS11_AES_256_CBC_SHA512          0xff65
+
+
+/* For TLS 1.2 - OP_PCLID_TLS12 */
+#define OP_PCL_TLS12_AES_128_CBC_SHA             0x002f
+#define OP_PCL_TLS12_AES_128_CBC_SHA_2           0x0030
+#define OP_PCL_TLS12_AES_128_CBC_SHA_3           0x0031
+#define OP_PCL_TLS12_AES_128_CBC_SHA_4           0x0032
+#define OP_PCL_TLS12_AES_128_CBC_SHA_5           0x0033
+#define OP_PCL_TLS12_AES_128_CBC_SHA_6           0x0034
+#define OP_PCL_TLS12_AES_128_CBC_SHA_7           0x008c
+#define OP_PCL_TLS12_AES_128_CBC_SHA_8           0x0090
+#define OP_PCL_TLS12_AES_128_CBC_SHA_9           0x0094
+#define OP_PCL_TLS12_AES_128_CBC_SHA_10          0xc004
+#define OP_PCL_TLS12_AES_128_CBC_SHA_11          0xc009
+#define OP_PCL_TLS12_AES_128_CBC_SHA_12          0xc00e
+#define OP_PCL_TLS12_AES_128_CBC_SHA_13          0xc013
+#define OP_PCL_TLS12_AES_128_CBC_SHA_14          0xc018
+#define OP_PCL_TLS12_AES_128_CBC_SHA_15          0xc01d
+#define OP_PCL_TLS12_AES_128_CBC_SHA_16          0xc01e
+#define OP_PCL_TLS12_AES_128_CBC_SHA_17          0xc01f
+
+#define OP_PCL_TLS12_AES_256_CBC_SHA             0x0035
+#define OP_PCL_TLS12_AES_256_CBC_SHA_2           0x0036
+#define OP_PCL_TLS12_AES_256_CBC_SHA_3           0x0037
+#define OP_PCL_TLS12_AES_256_CBC_SHA_4           0x0038
+#define OP_PCL_TLS12_AES_256_CBC_SHA_5           0x0039
+#define OP_PCL_TLS12_AES_256_CBC_SHA_6           0x003a
+#define OP_PCL_TLS12_AES_256_CBC_SHA_7           0x008d
+#define OP_PCL_TLS12_AES_256_CBC_SHA_8           0x0091
+#define OP_PCL_TLS12_AES_256_CBC_SHA_9           0x0095
+#define OP_PCL_TLS12_AES_256_CBC_SHA_10          0xc005
+#define OP_PCL_TLS12_AES_256_CBC_SHA_11          0xc00a
+#define OP_PCL_TLS12_AES_256_CBC_SHA_12          0xc00f
+#define OP_PCL_TLS12_AES_256_CBC_SHA_13          0xc014
+#define OP_PCL_TLS12_AES_256_CBC_SHA_14          0xc019
+#define OP_PCL_TLS12_AES_256_CBC_SHA_15          0xc020
+#define OP_PCL_TLS12_AES_256_CBC_SHA_16          0xc021
+#define OP_PCL_TLS12_AES_256_CBC_SHA_17          0xc022
+
+/* #define OP_PCL_TLS12_3DES_EDE_CBC_MD5            0x0023 */
+
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA            0x001f
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_2          0x008b
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_3          0x008f
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_4          0x0093
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_5          0x000a
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_6          0x000d
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_7          0x0010
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_8          0x0013
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_9          0x0016
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_10         0x001b
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_11         0xc003
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_12         0xc008
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_13         0xc00d
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_14         0xc012
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_15         0xc017
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_16         0xc01a
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_17         0xc01b
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA_18         0xc01c
+
+#define OP_PCL_TLS12_DES40_CBC_MD5               0x0029
+
+#define OP_PCL_TLS12_DES_CBC_MD5                 0x0022
+
+#define OP_PCL_TLS12_DES40_CBC_SHA               0x0008
+#define OP_PCL_TLS12_DES40_CBC_SHA_2             0x000b
+#define OP_PCL_TLS12_DES40_CBC_SHA_3             0x000e
+#define OP_PCL_TLS12_DES40_CBC_SHA_4             0x0011
+#define OP_PCL_TLS12_DES40_CBC_SHA_5             0x0014
+#define OP_PCL_TLS12_DES40_CBC_SHA_6             0x0019
+#define OP_PCL_TLS12_DES40_CBC_SHA_7             0x0026
+
+#define OP_PCL_TLS12_DES_CBC_SHA                 0x001e
+#define OP_PCL_TLS12_DES_CBC_SHA_2               0x0009
+#define OP_PCL_TLS12_DES_CBC_SHA_3               0x000c
+#define OP_PCL_TLS12_DES_CBC_SHA_4               0x000f
+#define OP_PCL_TLS12_DES_CBC_SHA_5               0x0012
+#define OP_PCL_TLS12_DES_CBC_SHA_6               0x0015
+#define OP_PCL_TLS12_DES_CBC_SHA_7               0x001a
+
+#define OP_PCL_TLS12_RC4_128_MD5                 0x0024
+#define OP_PCL_TLS12_RC4_128_MD5_2               0x0004
+#define OP_PCL_TLS12_RC4_128_MD5_3               0x0018
+
+#define OP_PCL_TLS12_RC4_40_MD5                  0x002b
+#define OP_PCL_TLS12_RC4_40_MD5_2                0x0003
+#define OP_PCL_TLS12_RC4_40_MD5_3                0x0017
+
+#define OP_PCL_TLS12_RC4_128_SHA                 0x0020
+#define OP_PCL_TLS12_RC4_128_SHA_2               0x008a
+#define OP_PCL_TLS12_RC4_128_SHA_3               0x008e
+#define OP_PCL_TLS12_RC4_128_SHA_4               0x0092
+#define OP_PCL_TLS12_RC4_128_SHA_5               0x0005
+#define OP_PCL_TLS12_RC4_128_SHA_6               0xc002
+#define OP_PCL_TLS12_RC4_128_SHA_7               0xc007
+#define OP_PCL_TLS12_RC4_128_SHA_8               0xc00c
+#define OP_PCL_TLS12_RC4_128_SHA_9               0xc011
+#define OP_PCL_TLS12_RC4_128_SHA_10              0xc016
+
+#define OP_PCL_TLS12_RC4_40_SHA                  0x0028
+
+/* #define OP_PCL_TLS12_AES_128_CBC_SHA256          0x003c */
+#define OP_PCL_TLS12_AES_128_CBC_SHA256_2        0x003e
+#define OP_PCL_TLS12_AES_128_CBC_SHA256_3        0x003f
+#define OP_PCL_TLS12_AES_128_CBC_SHA256_4        0x0040
+#define OP_PCL_TLS12_AES_128_CBC_SHA256_5        0x0067
+#define OP_PCL_TLS12_AES_128_CBC_SHA256_6        0x006c
+
+/* #define OP_PCL_TLS12_AES_256_CBC_SHA256          0x003d */
+#define OP_PCL_TLS12_AES_256_CBC_SHA256_2        0x0068
+#define OP_PCL_TLS12_AES_256_CBC_SHA256_3        0x0069
+#define OP_PCL_TLS12_AES_256_CBC_SHA256_4        0x006a
+#define OP_PCL_TLS12_AES_256_CBC_SHA256_5        0x006b
+#define OP_PCL_TLS12_AES_256_CBC_SHA256_6        0x006d
+
+/* AEAD_AES_xxx_CCM/GCM remain to be defined... */
+
+#define OP_PCL_TLS12_3DES_EDE_CBC_MD5            0xff23
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA160         0xff30
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA224         0xff34
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA256         0xff36
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA384         0xff33
+#define OP_PCL_TLS12_3DES_EDE_CBC_SHA512         0xff35
+#define OP_PCL_TLS12_AES_128_CBC_SHA160          0xff80
+#define OP_PCL_TLS12_AES_128_CBC_SHA224          0xff84
+#define OP_PCL_TLS12_AES_128_CBC_SHA256          0xff86
+#define OP_PCL_TLS12_AES_128_CBC_SHA384          0xff83
+#define OP_PCL_TLS12_AES_128_CBC_SHA512          0xff85
+#define OP_PCL_TLS12_AES_192_CBC_SHA160          0xff20
+#define OP_PCL_TLS12_AES_192_CBC_SHA224          0xff24
+#define OP_PCL_TLS12_AES_192_CBC_SHA256          0xff26
+#define OP_PCL_TLS12_AES_192_CBC_SHA384          0xff23
+#define OP_PCL_TLS12_AES_192_CBC_SHA512          0xff25
+#define OP_PCL_TLS12_AES_256_CBC_SHA160          0xff60
+#define OP_PCL_TLS12_AES_256_CBC_SHA224          0xff64
+#define OP_PCL_TLS12_AES_256_CBC_SHA256          0xff66
+#define OP_PCL_TLS12_AES_256_CBC_SHA384          0xff63
+#define OP_PCL_TLS12_AES_256_CBC_SHA512          0xff65
+
+/* For DTLS - OP_PCLID_DTLS */
+
+#define OP_PCL_DTLS_AES_128_CBC_SHA              0x002f
+#define OP_PCL_DTLS_AES_128_CBC_SHA_2            0x0030
+#define OP_PCL_DTLS_AES_128_CBC_SHA_3            0x0031
+#define OP_PCL_DTLS_AES_128_CBC_SHA_4            0x0032
+#define OP_PCL_DTLS_AES_128_CBC_SHA_5            0x0033
+#define OP_PCL_DTLS_AES_128_CBC_SHA_6            0x0034
+#define OP_PCL_DTLS_AES_128_CBC_SHA_7            0x008c
+#define OP_PCL_DTLS_AES_128_CBC_SHA_8            0x0090
+#define OP_PCL_DTLS_AES_128_CBC_SHA_9            0x0094
+#define OP_PCL_DTLS_AES_128_CBC_SHA_10           0xc004
+#define OP_PCL_DTLS_AES_128_CBC_SHA_11           0xc009
+#define OP_PCL_DTLS_AES_128_CBC_SHA_12           0xc00e
+#define OP_PCL_DTLS_AES_128_CBC_SHA_13           0xc013
+#define OP_PCL_DTLS_AES_128_CBC_SHA_14           0xc018
+#define OP_PCL_DTLS_AES_128_CBC_SHA_15           0xc01d
+#define OP_PCL_DTLS_AES_128_CBC_SHA_16           0xc01e
+#define OP_PCL_DTLS_AES_128_CBC_SHA_17           0xc01f
+
+#define OP_PCL_DTLS_AES_256_CBC_SHA              0x0035
+#define OP_PCL_DTLS_AES_256_CBC_SHA_2            0x0036
+#define OP_PCL_DTLS_AES_256_CBC_SHA_3            0x0037
+#define OP_PCL_DTLS_AES_256_CBC_SHA_4            0x0038
+#define OP_PCL_DTLS_AES_256_CBC_SHA_5            0x0039
+#define OP_PCL_DTLS_AES_256_CBC_SHA_6            0x003a
+#define OP_PCL_DTLS_AES_256_CBC_SHA_7            0x008d
+#define OP_PCL_DTLS_AES_256_CBC_SHA_8            0x0091
+#define OP_PCL_DTLS_AES_256_CBC_SHA_9            0x0095
+#define OP_PCL_DTLS_AES_256_CBC_SHA_10           0xc005
+#define OP_PCL_DTLS_AES_256_CBC_SHA_11           0xc00a
+#define OP_PCL_DTLS_AES_256_CBC_SHA_12           0xc00f
+#define OP_PCL_DTLS_AES_256_CBC_SHA_13           0xc014
+#define OP_PCL_DTLS_AES_256_CBC_SHA_14           0xc019
+#define OP_PCL_DTLS_AES_256_CBC_SHA_15           0xc020
+#define OP_PCL_DTLS_AES_256_CBC_SHA_16           0xc021
+#define OP_PCL_DTLS_AES_256_CBC_SHA_17           0xc022
+
+/* #define OP_PCL_DTLS_3DES_EDE_CBC_MD5             0x0023 */
+
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA             0x001f
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_2           0x008b
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_3           0x008f
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_4           0x0093
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_5           0x000a
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_6           0x000d
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_7           0x0010
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_8           0x0013
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_9           0x0016
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_10          0x001b
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_11          0xc003
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_12          0xc008
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_13          0xc00d
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_14          0xc012
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_15          0xc017
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_16          0xc01a
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_17          0xc01b
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA_18          0xc01c
+
+#define OP_PCL_DTLS_DES40_CBC_MD5                0x0029
+
+#define OP_PCL_DTLS_DES_CBC_MD5                  0x0022
+
+#define OP_PCL_DTLS_DES40_CBC_SHA                0x0008
+#define OP_PCL_DTLS_DES40_CBC_SHA_2              0x000b
+#define OP_PCL_DTLS_DES40_CBC_SHA_3              0x000e
+#define OP_PCL_DTLS_DES40_CBC_SHA_4              0x0011
+#define OP_PCL_DTLS_DES40_CBC_SHA_5              0x0014
+#define OP_PCL_DTLS_DES40_CBC_SHA_6              0x0019
+#define OP_PCL_DTLS_DES40_CBC_SHA_7              0x0026
+
+
+#define OP_PCL_DTLS_DES_CBC_SHA                  0x001e
+#define OP_PCL_DTLS_DES_CBC_SHA_2                0x0009
+#define OP_PCL_DTLS_DES_CBC_SHA_3                0x000c
+#define OP_PCL_DTLS_DES_CBC_SHA_4                0x000f
+#define OP_PCL_DTLS_DES_CBC_SHA_5                0x0012
+#define OP_PCL_DTLS_DES_CBC_SHA_6                0x0015
+#define OP_PCL_DTLS_DES_CBC_SHA_7                0x001a
+
+
+#define OP_PCL_DTLS_3DES_EDE_CBC_MD5             0xff23
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA160          0xff30
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA224          0xff34
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA256          0xff36
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA384          0xff33
+#define OP_PCL_DTLS_3DES_EDE_CBC_SHA512          0xff35
+#define OP_PCL_DTLS_AES_128_CBC_SHA160           0xff80
+#define OP_PCL_DTLS_AES_128_CBC_SHA224           0xff84
+#define OP_PCL_DTLS_AES_128_CBC_SHA256           0xff86
+#define OP_PCL_DTLS_AES_128_CBC_SHA384           0xff83
+#define OP_PCL_DTLS_AES_128_CBC_SHA512           0xff85
+#define OP_PCL_DTLS_AES_192_CBC_SHA160           0xff20
+#define OP_PCL_DTLS_AES_192_CBC_SHA224           0xff24
+#define OP_PCL_DTLS_AES_192_CBC_SHA256           0xff26
+#define OP_PCL_DTLS_AES_192_CBC_SHA384           0xff23
+#define OP_PCL_DTLS_AES_192_CBC_SHA512           0xff25
+#define OP_PCL_DTLS_AES_256_CBC_SHA160           0xff60
+#define OP_PCL_DTLS_AES_256_CBC_SHA224           0xff64
+#define OP_PCL_DTLS_AES_256_CBC_SHA256           0xff66
+#define OP_PCL_DTLS_AES_256_CBC_SHA384           0xff63
+#define OP_PCL_DTLS_AES_256_CBC_SHA512           0xff65
+
+/* 802.16 WiMAX protinfos */
+#define OP_PCL_WIMAX_OFDM                        0x0201
+#define OP_PCL_WIMAX_OFDMA                       0x0231
+
+/* 802.11 WiFi protinfos */
+#define OP_PCL_WIFI                              0xac04
+
+/* MacSec protinfos */
+#define OP_PCL_MACSEC                            0x0001
+
+/* PKI unidirectional protocol protinfo bits */
+#define OP_PCL_PKPROT_TEST                       0x0008
+#define OP_PCL_PKPROT_DECRYPT                    0x0004
+#define OP_PCL_PKPROT_ECC                        0x0002
+#define OP_PCL_PKPROT_F2M                        0x0001
+
+/* For non-protocol/alg-only op commands */
+#define OP_ALG_TYPE_SHIFT      24
+#define OP_ALG_TYPE_MASK       (0x7 << OP_ALG_TYPE_SHIFT)
+#define OP_ALG_TYPE_CLASS1     2
+#define OP_ALG_TYPE_CLASS2     4
+
+#define OP_ALG_ALGSEL_SHIFT    16
+#define OP_ALG_ALGSEL_MASK     (0xff << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SUBMASK  (0x0f << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_AES      (0x10 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_DES      (0x20 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_3DES     (0x21 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_ARC4     (0x30 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_MD5      (0x40 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SHA1     (0x41 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SHA224   (0x42 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SHA256   (0x43 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SHA384   (0x44 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SHA512   (0x45 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_RNG      (0x50 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SNOW     (0x60 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SNOW_F8  (0x60 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_KASUMI   (0x70 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_CRC      (0x90 << OP_ALG_ALGSEL_SHIFT)
+#define OP_ALG_ALGSEL_SNOW_F9  (0xA0 << OP_ALG_ALGSEL_SHIFT)
+
+#define OP_ALG_AAI_SHIFT       4
+#define OP_ALG_AAI_MASK                (0x1ff << OP_ALG_AAI_SHIFT)
+
+/* blockcipher AAI set */
+#define OP_ALG_AAI_CTR_MOD128  (0x00 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD8    (0x01 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD16   (0x02 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD24   (0x03 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD32   (0x04 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD40   (0x05 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD48   (0x06 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD56   (0x07 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD64   (0x08 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD72   (0x09 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD80   (0x0a << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD88   (0x0b << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD96   (0x0c << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD104  (0x0d << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD112  (0x0e << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_MOD120  (0x0f << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CBC         (0x10 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_ECB         (0x20 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CFB         (0x30 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_OFB         (0x40 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_XTS         (0x50 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CMAC                (0x60 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_XCBC_MAC    (0x70 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CCM         (0x80 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_GCM         (0x90 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CBC_XCBCMAC (0xa0 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CTR_XCBCMAC (0xb0 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CHECKODD    (0x80 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_DK          (0x100 << OP_ALG_AAI_SHIFT)
+
+/* randomizer AAI set */
+#define OP_ALG_AAI_RNG         (0x00 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_RNG_NOZERO  (0x10 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_RNG_ODD     (0x20 << OP_ALG_AAI_SHIFT)
+
+/* hmac/smac AAI set */
+#define OP_ALG_AAI_HASH                (0x00 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_HMAC                (0x01 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_SMAC                (0x02 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_HMAC_PRECOMP        (0x04 << OP_ALG_AAI_SHIFT)
+
+/* CRC AAI set*/
+#define OP_ALG_AAI_802         (0x01 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_3385                (0x02 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_CUST_POLY   (0x04 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_DIS         (0x10 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_DOS         (0x20 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_DOC         (0x40 << OP_ALG_AAI_SHIFT)
+
+/* Kasumi/SNOW AAI set */
+#define OP_ALG_AAI_F8          (0xc0 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_F9          (0xc8 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_GSM         (0x10 << OP_ALG_AAI_SHIFT)
+#define OP_ALG_AAI_EDGE                (0x20 << OP_ALG_AAI_SHIFT)
+
+
+#define OP_ALG_AS_SHIFT                2
+#define OP_ALG_AS_MASK         (0x3 << OP_ALG_AS_SHIFT)
+#define OP_ALG_AS_UPDATE       (0 << OP_ALG_AS_SHIFT)
+#define OP_ALG_AS_INIT         (1 << OP_ALG_AS_SHIFT)
+#define OP_ALG_AS_FINALIZE     (2 << OP_ALG_AS_SHIFT)
+#define OP_ALG_AS_INITFINAL    (3 << OP_ALG_AS_SHIFT)
+
+#define OP_ALG_ICV_SHIFT       1
+#define OP_ALG_ICV_MASK                (1 << OP_ALG_ICV_SHIFT)
+#define OP_ALG_ICV_OFF         (0 << OP_ALG_ICV_SHIFT)
+#define OP_ALG_ICV_ON          (1 << OP_ALG_ICV_SHIFT)
+
+#define OP_ALG_DIR_SHIFT       0
+#define OP_ALG_DIR_MASK                1
+#define OP_ALG_DECRYPT         0
+#define OP_ALG_ENCRYPT         1
+
+/* PKHA algorithm type set */
+#define OP_ALG_PK                    0x00800000
+#define OP_ALG_PK_FUN_MASK           0x3f /* clrmem, modmath, or cpymem */
+
+/* PKHA mode clear memory functions */
+#define OP_ALG_PKMODE_A_RAM          0x80000
+#define OP_ALG_PKMODE_B_RAM          0x40000
+#define OP_ALG_PKMODE_E_RAM          0x20000
+#define OP_ALG_PKMODE_N_RAM          0x10000
+#define OP_ALG_PKMODE_CLEARMEM       0x00001
+
+/* PKHA mode modular-arithmetic functions */
+#define OP_ALG_PKMODE_MOD_IN_MONTY   0x80000
+#define OP_ALG_PKMODE_MOD_OUT_MONTY  0x40000
+#define OP_ALG_PKMODE_MOD_F2M        0x20000
+#define OP_ALG_PKMODE_MOD_R2_IN      0x10000
+#define OP_ALG_PKMODE_PRJECTV        0x00800
+#define OP_ALG_PKMODE_TIME_EQ        0x400
+#define OP_ALG_PKMODE_OUT_B          0x000
+#define OP_ALG_PKMODE_OUT_A          0x100
+#define OP_ALG_PKMODE_MOD_ADD        0x002
+#define OP_ALG_PKMODE_MOD_SUB_AB     0x003
+#define OP_ALG_PKMODE_MOD_SUB_BA     0x004
+#define OP_ALG_PKMODE_MOD_MULT       0x005
+#define OP_ALG_PKMODE_MOD_EXPO       0x006
+#define OP_ALG_PKMODE_MOD_REDUCT     0x007
+#define OP_ALG_PKMODE_MOD_INV        0x008
+#define OP_ALG_PKMODE_MOD_ECC_ADD    0x009
+#define OP_ALG_PKMODE_MOD_ECC_DBL    0x00a
+#define OP_ALG_PKMODE_MOD_ECC_MULT   0x00b
+#define OP_ALG_PKMODE_MOD_MONT_CNST  0x00c
+#define OP_ALG_PKMODE_MOD_CRT_CNST   0x00d
+#define OP_ALG_PKMODE_MOD_GCD        0x00e
+#define OP_ALG_PKMODE_MOD_PRIMALITY  0x00f
+
+/* PKHA mode copy-memory functions */
+#define OP_ALG_PKMODE_SRC_REG_SHIFT  13
+#define OP_ALG_PKMODE_SRC_REG_MASK   (7 << OP_ALG_PKMODE_SRC_REG_SHIFT)
+#define OP_ALG_PKMODE_DST_REG_SHIFT  10
+#define OP_ALG_PKMODE_DST_REG_MASK   (7 << OP_ALG_PKMODE_DST_REG_SHIFT)
+#define OP_ALG_PKMODE_SRC_SEG_SHIFT  8
+#define OP_ALG_PKMODE_SRC_SEG_MASK   (3 << OP_ALG_PKMODE_SRC_SEG_SHIFT)
+#define OP_ALG_PKMODE_DST_SEG_SHIFT  6
+#define OP_ALG_PKMODE_DST_SEG_MASK   (3 << OP_ALG_PKMODE_DST_SEG_SHIFT)
+
+#define OP_ALG_PKMODE_SRC_REG_A      (0 << OP_ALG_PKMODE_SRC_REG_SHIFT)
+#define OP_ALG_PKMODE_SRC_REG_B      (1 << OP_ALG_PKMODE_SRC_REG_SHIFT)
+#define OP_ALG_PKMODE_SRC_REG_N      (3 << OP_ALG_PKMODE_SRC_REG_SHIFT)
+#define OP_ALG_PKMODE_DST_REG_A      (0 << OP_ALG_PKMODE_DST_REG_SHIFT)
+#define OP_ALG_PKMODE_DST_REG_B      (1 << OP_ALG_PKMODE_DST_REG_SHIFT)
+#define OP_ALG_PKMODE_DST_REG_E      (2 << OP_ALG_PKMODE_DST_REG_SHIFT)
+#define OP_ALG_PKMODE_DST_REG_N      (3 << OP_ALG_PKMODE_DST_REG_SHIFT)
+#define OP_ALG_PKMODE_SRC_SEG_0      (0 << OP_ALG_PKMODE_SRC_SEG_SHIFT)
+#define OP_ALG_PKMODE_SRC_SEG_1      (1 << OP_ALG_PKMODE_SRC_SEG_SHIFT)
+#define OP_ALG_PKMODE_SRC_SEG_2      (2 << OP_ALG_PKMODE_SRC_SEG_SHIFT)
+#define OP_ALG_PKMODE_SRC_SEG_3      (3 << OP_ALG_PKMODE_SRC_SEG_SHIFT)
+#define OP_ALG_PKMODE_DST_SEG_0      (0 << OP_ALG_PKMODE_DST_SEG_SHIFT)
+#define OP_ALG_PKMODE_DST_SEG_1      (1 << OP_ALG_PKMODE_DST_SEG_SHIFT)
+#define OP_ALG_PKMODE_DST_SEG_2      (2 << OP_ALG_PKMODE_DST_SEG_SHIFT)
+#define OP_ALG_PKMODE_DST_SEG_3      (3 << OP_ALG_PKMODE_DST_SEG_SHIFT)
+#define OP_ALG_PKMODE_CPYMEM_N_SZ    0x80
+#define OP_ALG_PKMODE_CPYMEM_SRC_SZ  0x81
+
+/*
+ * SEQ_IN_PTR Command Constructs
+ */
+
+/* Release Buffers */
+#define SQIN_RBS               0x04000000
+
+/* Sequence pointer is really a descriptor */
+#define SQIN_INL               0x02000000
+
+/* Sequence pointer is a scatter-gather table */
+#define SQIN_SGF               0x01000000
+
+/* Appends to a previous pointer */
+#define SQIN_PRE               0x00800000
+
+/* Use extended length following pointer */
+#define SQIN_EXT               0x00400000
+
+/* Restore sequence with pointer/length */
+#define SQIN_RTO               0x00200000
+
+/* Replace job descriptor */
+#define SQIN_RJD               0x00100000
+
+#define SQIN_LEN_SHIFT           0
+#define SQIN_LEN_MASK           (0xffff << SQIN_LEN_SHIFT)
+
+/*
+ * SEQ_OUT_PTR Command Constructs
+ */
+
+/* Sequence pointer is a scatter-gather table */
+#define SQOUT_SGF              0x01000000
+
+/* Appends to a previous pointer */
+#define SQOUT_PRE              0x00800000
+
+/* Restore sequence with pointer/length */
+#define SQOUT_RTO              0x00200000
+
+/* Use extended length following pointer */
+#define SQOUT_EXT              0x00400000
+
+#define SQOUT_LEN_SHIFT           0
+#define SQOUT_LEN_MASK           (0xffff << SQOUT_LEN_SHIFT)
+
+
+/*
+ * SIGNATURE Command Constructs
+ */
+
+/* TYPE field is all that's relevant */
+#define SIGN_TYPE_SHIFT         16
+#define SIGN_TYPE_MASK          (0x0f << SIGN_TYPE_SHIFT)
+
+#define SIGN_TYPE_FINAL         (0x00 << SIGN_TYPE_SHIFT)
+#define SIGN_TYPE_FINAL_RESTORE (0x01 << SIGN_TYPE_SHIFT)
+#define SIGN_TYPE_FINAL_NONZERO (0x02 << SIGN_TYPE_SHIFT)
+#define SIGN_TYPE_IMM_2         (0x0a << SIGN_TYPE_SHIFT)
+#define SIGN_TYPE_IMM_3         (0x0b << SIGN_TYPE_SHIFT)
+#define SIGN_TYPE_IMM_4         (0x0c << SIGN_TYPE_SHIFT)
+
+/*
+ * MOVE Command Constructs
+ */
+
+#define MOVE_AUX_SHIFT          25
+#define MOVE_AUX_MASK           (3 << MOVE_AUX_SHIFT)
+#define MOVE_AUX_MS             (2 << MOVE_AUX_SHIFT)
+#define MOVE_AUX_LS             (1 << MOVE_AUX_SHIFT)
+
+#define MOVE_WAITCOMP_SHIFT     24
+#define MOVE_WAITCOMP_MASK      (1 << MOVE_WAITCOMP_SHIFT)
+#define MOVE_WAITCOMP           (1 << MOVE_WAITCOMP_SHIFT)
+
+#define MOVE_SRC_SHIFT          20
+#define MOVE_SRC_MASK           (0x0f << MOVE_SRC_SHIFT)
+#define MOVE_SRC_CLASS1CTX      (0x00 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_CLASS2CTX      (0x01 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_OUTFIFO        (0x02 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_DESCBUF        (0x03 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_MATH0          (0x04 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_MATH1          (0x05 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_MATH2          (0x06 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_MATH3          (0x07 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_INFIFO         (0x08 << MOVE_SRC_SHIFT)
+#define MOVE_SRC_INFIFO_CL      (0x09 << MOVE_SRC_SHIFT)
+
+#define MOVE_DEST_SHIFT         16
+#define MOVE_DEST_MASK          (0x0f << MOVE_DEST_SHIFT)
+#define MOVE_DEST_CLASS1CTX     (0x00 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_CLASS2CTX     (0x01 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_OUTFIFO       (0x02 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_DESCBUF       (0x03 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_MATH0         (0x04 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_MATH1         (0x05 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_MATH2         (0x06 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_MATH3         (0x07 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_CLASS1INFIFO  (0x08 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_CLASS2INFIFO  (0x09 << MOVE_DEST_SHIFT)
+#define MOVE_DEST_PK_A          (0x0c << MOVE_DEST_SHIFT)
+#define MOVE_DEST_CLASS1KEY     (0x0d << MOVE_DEST_SHIFT)
+#define MOVE_DEST_CLASS2KEY     (0x0e << MOVE_DEST_SHIFT)
+
+#define MOVE_OFFSET_SHIFT       8
+#define MOVE_OFFSET_MASK        (0xff << MOVE_OFFSET_SHIFT)
+
+#define MOVE_LEN_SHIFT          0
+#define MOVE_LEN_MASK           (0xff << MOVE_LEN_SHIFT)
+
+#define MOVELEN_MRSEL_SHIFT     0
+#define MOVELEN_MRSEL_MASK      (0x3 << MOVE_LEN_SHIFT)
+
+/*
+ * MATH Command Constructs
+ */
+
+#define MATH_IFB_SHIFT          26
+#define MATH_IFB_MASK           (1 << MATH_IFB_SHIFT)
+#define MATH_IFB                (1 << MATH_IFB_SHIFT)
+
+#define MATH_NFU_SHIFT          25
+#define MATH_NFU_MASK           (1 << MATH_NFU_SHIFT)
+#define MATH_NFU                (1 << MATH_NFU_SHIFT)
+
+#define MATH_STL_SHIFT          24
+#define MATH_STL_MASK           (1 << MATH_STL_SHIFT)
+#define MATH_STL                (1 << MATH_STL_SHIFT)
+
+/* Function selectors */
+#define MATH_FUN_SHIFT          20
+#define MATH_FUN_MASK           (0x0f << MATH_FUN_SHIFT)
+#define MATH_FUN_ADD            (0x00 << MATH_FUN_SHIFT)
+#define MATH_FUN_ADDC           (0x01 << MATH_FUN_SHIFT)
+#define MATH_FUN_SUB            (0x02 << MATH_FUN_SHIFT)
+#define MATH_FUN_SUBB           (0x03 << MATH_FUN_SHIFT)
+#define MATH_FUN_OR             (0x04 << MATH_FUN_SHIFT)
+#define MATH_FUN_AND            (0x05 << MATH_FUN_SHIFT)
+#define MATH_FUN_XOR            (0x06 << MATH_FUN_SHIFT)
+#define MATH_FUN_LSHIFT         (0x07 << MATH_FUN_SHIFT)
+#define MATH_FUN_RSHIFT         (0x08 << MATH_FUN_SHIFT)
+#define MATH_FUN_SHLD           (0x09 << MATH_FUN_SHIFT)
+#define MATH_FUN_ZBYT           (0x0a << MATH_FUN_SHIFT)
+
+/* Source 0 selectors */
+#define MATH_SRC0_SHIFT         16
+#define MATH_SRC0_MASK          (0x0f << MATH_SRC0_SHIFT)
+#define MATH_SRC0_REG0          (0x00 << MATH_SRC0_SHIFT)
+#define MATH_SRC0_REG1          (0x01 << MATH_SRC0_SHIFT)
+#define MATH_SRC0_REG2          (0x02 << MATH_SRC0_SHIFT)
+#define MATH_SRC0_REG3          (0x03 << MATH_SRC0_SHIFT)
+#define MATH_SRC0_IMM           (0x04 << MATH_SRC0_SHIFT)
+#define MATH_SRC0_SEQINLEN      (0x08 << MATH_SRC0_SHIFT)
+#define MATH_SRC0_SEQOUTLEN     (0x09 << MATH_SRC0_SHIFT)
+#define MATH_SRC0_VARSEQINLEN   (0x0a << MATH_SRC0_SHIFT)
+#define MATH_SRC0_VARSEQOUTLEN  (0x0b << MATH_SRC0_SHIFT)
+#define MATH_SRC0_ZERO          (0x0c << MATH_SRC0_SHIFT)
+
+/* Source 1 selectors */
+#define MATH_SRC1_SHIFT         12
+#define MATH_SRC1_MASK          (0x0f << MATH_SRC1_SHIFT)
+#define MATH_SRC1_REG0          (0x00 << MATH_SRC1_SHIFT)
+#define MATH_SRC1_REG1          (0x01 << MATH_SRC1_SHIFT)
+#define MATH_SRC1_REG2          (0x02 << MATH_SRC1_SHIFT)
+#define MATH_SRC1_REG3          (0x03 << MATH_SRC1_SHIFT)
+#define MATH_SRC1_IMM           (0x04 << MATH_SRC1_SHIFT)
+#define MATH_SRC1_INFIFO        (0x0a << MATH_SRC1_SHIFT)
+#define MATH_SRC1_OUTFIFO       (0x0b << MATH_SRC1_SHIFT)
+#define MATH_SRC1_ONE           (0x0c << MATH_SRC1_SHIFT)
+
+/* Destination selectors */
+#define MATH_DEST_SHIFT         8
+#define MATH_DEST_MASK          (0x0f << MATH_DEST_SHIFT)
+#define MATH_DEST_REG0          (0x00 << MATH_DEST_SHIFT)
+#define MATH_DEST_REG1          (0x01 << MATH_DEST_SHIFT)
+#define MATH_DEST_REG2          (0x02 << MATH_DEST_SHIFT)
+#define MATH_DEST_REG3          (0x03 << MATH_DEST_SHIFT)
+#define MATH_DEST_SEQINLEN      (0x08 << MATH_DEST_SHIFT)
+#define MATH_DEST_SEQOUTLEN     (0x09 << MATH_DEST_SHIFT)
+#define MATH_DEST_VARSEQINLEN   (0x0a << MATH_DEST_SHIFT)
+#define MATH_DEST_VARSEQOUTLEN  (0x0b << MATH_DEST_SHIFT)
+#define MATH_DEST_NONE          (0x0f << MATH_DEST_SHIFT)
+
+/* Length selectors */
+#define MATH_LEN_SHIFT          0
+#define MATH_LEN_MASK           (0x0f << MATH_LEN_SHIFT)
+#define MATH_LEN_1BYTE          0x01
+#define MATH_LEN_2BYTE          0x02
+#define MATH_LEN_4BYTE          0x04
+#define MATH_LEN_8BYTE          0x08
+
+/*
+ * JUMP Command Constructs
+ */
+
+#define JUMP_CLASS_SHIFT        25
+#define JUMP_CLASS_MASK                (3 << JUMP_CLASS_SHIFT)
+#define JUMP_CLASS_NONE                0
+#define JUMP_CLASS_CLASS1      (1 << JUMP_CLASS_SHIFT)
+#define JUMP_CLASS_CLASS2      (2 << JUMP_CLASS_SHIFT)
+#define JUMP_CLASS_BOTH                (3 << JUMP_CLASS_SHIFT)
+
+#define JUMP_JSL_SHIFT          24
+#define JUMP_JSL_MASK           (1 << JUMP_JSL_SHIFT)
+#define JUMP_JSL                (1 << JUMP_JSL_SHIFT)
+
+#define JUMP_TYPE_SHIFT         22
+#define JUMP_TYPE_MASK          (0x03 << JUMP_TYPE_SHIFT)
+#define JUMP_TYPE_LOCAL         (0x00 << JUMP_TYPE_SHIFT)
+#define JUMP_TYPE_NONLOCAL      (0x01 << JUMP_TYPE_SHIFT)
+#define JUMP_TYPE_HALT          (0x02 << JUMP_TYPE_SHIFT)
+#define JUMP_TYPE_HALT_USER     (0x03 << JUMP_TYPE_SHIFT)
+
+#define JUMP_TEST_SHIFT         16
+#define JUMP_TEST_MASK          (0x03 << JUMP_TEST_SHIFT)
+#define JUMP_TEST_ALL           (0x00 << JUMP_TEST_SHIFT)
+#define JUMP_TEST_INVALL        (0x01 << JUMP_TEST_SHIFT)
+#define JUMP_TEST_ANY           (0x02 << JUMP_TEST_SHIFT)
+#define JUMP_TEST_INVANY        (0x03 << JUMP_TEST_SHIFT)
+
+/* Condition codes. JSL bit is factored in */
+#define JUMP_COND_SHIFT         8
+#define JUMP_COND_MASK          (0x100ff << JUMP_COND_SHIFT)
+#define JUMP_COND_PK_0          (0x80 << JUMP_COND_SHIFT)
+#define JUMP_COND_PK_GCD_1      (0x40 << JUMP_COND_SHIFT)
+#define JUMP_COND_PK_PRIME      (0x20 << JUMP_COND_SHIFT)
+#define JUMP_COND_MATH_N        (0x08 << JUMP_COND_SHIFT)
+#define JUMP_COND_MATH_Z        (0x04 << JUMP_COND_SHIFT)
+#define JUMP_COND_MATH_C        (0x02 << JUMP_COND_SHIFT)
+#define JUMP_COND_MATH_NV       (0x01 << JUMP_COND_SHIFT)
+
+#define JUMP_COND_JRP           ((0x80 << JUMP_COND_SHIFT) | JUMP_JSL)
+#define JUMP_COND_SHRD          ((0x40 << JUMP_COND_SHIFT) | JUMP_JSL)
+#define JUMP_COND_SELF          ((0x20 << JUMP_COND_SHIFT) | JUMP_JSL)
+#define JUMP_COND_CALM          ((0x10 << JUMP_COND_SHIFT) | JUMP_JSL)
+#define JUMP_COND_NIP           ((0x08 << JUMP_COND_SHIFT) | JUMP_JSL)
+#define JUMP_COND_NIFP          ((0x04 << JUMP_COND_SHIFT) | JUMP_JSL)
+#define JUMP_COND_NOP           ((0x02 << JUMP_COND_SHIFT) | JUMP_JSL)
+#define JUMP_COND_NCP           ((0x01 << JUMP_COND_SHIFT) | JUMP_JSL)
+
+#define JUMP_OFFSET_SHIFT       0
+#define JUMP_OFFSET_MASK        (0xff << JUMP_OFFSET_SHIFT)
+
+/*
+ * NFIFO ENTRY
+ * Data Constructs
+ *
+ */
+#define NFIFOENTRY_DEST_SHIFT  30
+#define NFIFOENTRY_DEST_MASK   (3 << NFIFOENTRY_DEST_SHIFT)
+#define NFIFOENTRY_DEST_DECO   (0 << NFIFOENTRY_DEST_SHIFT)
+#define NFIFOENTRY_DEST_CLASS1 (1 << NFIFOENTRY_DEST_SHIFT)
+#define NFIFOENTRY_DEST_CLASS2 (2 << NFIFOENTRY_DEST_SHIFT)
+#define NFIFOENTRY_DEST_BOTH   (3 << NFIFOENTRY_DEST_SHIFT)
+
+#define NFIFOENTRY_LC2_SHIFT   29
+#define NFIFOENTRY_LC2_MASK            (1 << NFIFOENTRY_LC2_SHIFT)
+#define NFIFOENTRY_LC2                 (1 << NFIFOENTRY_LC2_SHIFT)
+
+#define NFIFOENTRY_LC1_SHIFT   28
+#define NFIFOENTRY_LC1_MASK            (1 << NFIFOENTRY_LC1_SHIFT)
+#define NFIFOENTRY_LC1                 (1 << NFIFOENTRY_LC1_SHIFT)
+
+#define NFIFOENTRY_FC2_SHIFT   27
+#define NFIFOENTRY_FC2_MASK            (1 << NFIFOENTRY_FC2_SHIFT)
+#define NFIFOENTRY_FC2                 (1 << NFIFOENTRY_FC2_SHIFT)
+
+#define NFIFOENTRY_FC1_SHIFT   26
+#define NFIFOENTRY_FC1_MASK            (1 << NFIFOENTRY_FC1_SHIFT)
+#define NFIFOENTRY_FC1                 (1 << NFIFOENTRY_FC1_SHIFT)
+
+#define NFIFOENTRY_STYPE_SHIFT 24
+#define NFIFOENTRY_STYPE_MASK  (3 << NFIFOENTRY_STYPE_SHIFT)
+#define NFIFOENTRY_STYPE_DFIFO (0 << NFIFOENTRY_STYPE_SHIFT)
+#define NFIFOENTRY_STYPE_OFIFO (1 << NFIFOENTRY_STYPE_SHIFT)
+#define NFIFOENTRY_STYPE_PAD   (2 << NFIFOENTRY_STYPE_SHIFT)
+#define NFIFOENTRY_STYPE_SNOOP (3 << NFIFOENTRY_STYPE_SHIFT)
+
+#define NFIFOENTRY_DTYPE_SHIFT 20
+#define NFIFOENTRY_DTYPE_MASK  (0xF << NFIFOENTRY_DTYPE_SHIFT)
+
+#define NFIFOENTRY_DTYPE_SBOX      (0x0  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_AAD       (0x1  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_IV        (0x2  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_SAD       (0x3  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_ICV       (0xA  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_SKIP      (0xE  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_MSG       (0xF  << NFIFOENTRY_DTYPE_SHIFT)
+
+#define NFIFOENTRY_DTYPE_PK_A0     (0x0  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_A1     (0x1  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_A2     (0x2  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_A3     (0x3  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_B0     (0x4  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_B1     (0x5  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_B2     (0x6  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_B3     (0x7  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_N      (0x8  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_E      (0x9  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_A      (0xC  << NFIFOENTRY_DTYPE_SHIFT)
+#define NFIFOENTRY_DTYPE_PK_B      (0xD  << NFIFOENTRY_DTYPE_SHIFT)
+
+
+#define NFIFOENTRY_BND_SHIFT   19
+#define NFIFOENTRY_BND_MASK            (1 << NFIFOENTRY_BND_SHIFT)
+#define NFIFOENTRY_BND                 (1 << NFIFOENTRY_BND_SHIFT)
+
+#define NFIFOENTRY_PTYPE_SHIFT 16
+#define NFIFOENTRY_PTYPE_MASK  (0x7 << NFIFOENTRY_PTYPE_SHIFT)
+
+#define NFIFOENTRY_PTYPE_ZEROS         (0x0  << NFIFOENTRY_PTYPE_SHIFT)
+#define NFIFOENTRY_PTYPE_RND_NOZEROS   (0x1  << NFIFOENTRY_PTYPE_SHIFT)
+#define NFIFOENTRY_PTYPE_INCREMENT     (0x2  << NFIFOENTRY_PTYPE_SHIFT)
+#define NFIFOENTRY_PTYPE_RND           (0x3  << NFIFOENTRY_PTYPE_SHIFT)
+#define NFIFOENTRY_PTYPE_ZEROS_NZ      (0x4  << NFIFOENTRY_PTYPE_SHIFT)
+#define NFIFOENTRY_PTYPE_RND_NZ_LZ     (0x5  << NFIFOENTRY_PTYPE_SHIFT)
+#define NFIFOENTRY_PTYPE_N             (0x6  << NFIFOENTRY_PTYPE_SHIFT)
+#define NFIFOENTRY_PTYPE_RND_NZ_N      (0x7  << NFIFOENTRY_PTYPE_SHIFT)
+
+#define NFIFOENTRY_OC_SHIFT            15
+#define NFIFOENTRY_OC_MASK             (1 << NFIFOENTRY_OC_SHIFT)
+#define NFIFOENTRY_OC                  (1 << NFIFOENTRY_OC_SHIFT)
+
+#define NFIFOENTRY_AST_SHIFT   14
+#define NFIFOENTRY_AST_MASK            (1 << NFIFOENTRY_OC_SHIFT)
+#define NFIFOENTRY_AST                 (1 << NFIFOENTRY_OC_SHIFT)
+
+#define NFIFOENTRY_BM_SHIFT            11
+#define NFIFOENTRY_BM_MASK             (1 << NFIFOENTRY_BM_SHIFT)
+#define NFIFOENTRY_BM                  (1 << NFIFOENTRY_BM_SHIFT)
+
+#define NFIFOENTRY_PS_SHIFT            10
+#define NFIFOENTRY_PS_MASK             (1 << NFIFOENTRY_PS_SHIFT)
+#define NFIFOENTRY_PS                  (1 << NFIFOENTRY_PS_SHIFT)
+
+
+#define NFIFOENTRY_DLEN_SHIFT  0
+#define NFIFOENTRY_DLEN_MASK   (0xFFF << NFIFOENTRY_DLEN_SHIFT)
+
+#define NFIFOENTRY_PLEN_SHIFT  0
+#define NFIFOENTRY_PLEN_MASK   (0xFF << NFIFOENTRY_PLEN_SHIFT)
+
+/*
+ * PDB internal definitions
+ */
+
+/* IPSec ESP CBC Encap/Decap Options */
+#define PDBOPTS_ESPCBC_ARSNONE  0x00   /* no antireplay window              */
+#define PDBOPTS_ESPCBC_ARS32    0x40   /* 32-entry antireplay window        */
+#define PDBOPTS_ESPCBC_ARS64    0xc0   /* 64-entry antireplay window        */
+#define PDBOPTS_ESPCBC_IVSRC    0x20   /* IV comes from internal random gen */
+#define PDBOPTS_ESPCBC_ESN      0x10   /* extended sequence included        */
+#define PDBOPTS_ESPCBC_OUTFMT   0x08   /* output only decapsulation (decap) */
+#define PDBOPTS_ESPCBC_IPHDRSRC 0x08   /* IP header comes from PDB (encap)  */
+#define PDBOPTS_ESPCBC_INCIPHDR 0x04   /* Prepend IP header to output frame */
+#define PDBOPTS_ESPCBC_IPVSN    0x02   /* process IPv6 header               */
+#define PDBOPTS_ESPCBC_TUNNEL   0x01   /* tunnel mode next-header byte      */
+
+#endif /* DESC_H */
diff --git a/include/jr.h b/include/jr.h
new file mode 100644
index 0000000..6edee47
--- /dev/null
+++ b/include/jr.h
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __JR_H
+#define __JR_H
+
+#include <linux/compiler.h>
+
+#define JR_SIZE 4
+/* Timeout currently defined as 10 sec */
+#define CONFIG_SEC_DEQ_TIMEOUT 10000000U
+
+#define DEFAULT_JR_ID          0
+#define DEFAULT_JR_LIODN       0
+#define DEFAULT_IRQ            0       /* Interrupts not to be configured */
+
+#define MCFGR_SWRST       ((uint32_t)(1)<<31) /* Software Reset */
+#define MCFGR_DMA_RST     ((uint32_t)(1)<<28) /* DMA Reset */
+#define MCFGR_PS_SHIFT          16
+#define JR_INTMASK       0x00000001
+#define JRCR_RESET                  0x01
+#define JRINT_ERR_HALT_INPROGRESS   0x4
+#define JRINT_ERR_HALT_MASK         0xc
+#define JRNSLIODN_SHIFT                16
+#define JRNSLIODN_MASK         0x0fff0000
+#define JRSLIODN_SHIFT         0
+#define JRSLIODN_MASK          0x00000fff
+
+#define JQ_DEQ_ERR             -1
+#define JQ_DEQ_TO_ERR          -2
+#define JQ_ENQ_ERR             -3
+
+struct op_ring {
+       dma_addr_t desc;
+       uint32_t status;
+} __packed;
+
+typedef struct jr_info {
+       void (*callback)(dma_addr_t desc, uint32_t status, void *arg);
+       dma_addr_t desc_phys_addr;
+       uint32_t desc_addr;
+       uint32_t desc_len;
+       uint32_t op_done;
+       void *arg;
+} jr_info_t;
+
+typedef struct jobring {
+       int jq_id;
+       int irq;
+       int liodn;
+       /* Head is the index where software would enq the descriptor in
+        * the i/p ring
+        */
+       int head;
+       /* Tail index would be used by s/w ehile enqueuing to determine if
+        * there is any space left in the s/w maintained i/p rings
+        */
+       /* Also in case of deq tail will be incremented only in case of
+        * in-order job completion
+        */
+       int tail;
+       /* Read index of the output ring. It may not match with tail in case
+        * of out of order completetion
+        */
+       int read_idx;
+       /* Write index to input ring. Would be always equal to head */
+       int write_idx;
+       /* Size of the rings. */
+       int size;
+       /* The ip and output rings have to be accessed by SEC. So the
+        * pointers will ahve to point to the housekeeping region provided
+        * by SEC
+        */
+       /*Circular  Ring of i/p descriptors */
+       dma_addr_t *input_ring;
+       /* Circular Ring of o/p descriptors */
+       /* Circula Ring containing info regarding descriptors in i/p
+        * and o/p ring
+        */
+       /* This ring can be on the stack */
+       jr_info_t info[JR_SIZE];
+       struct op_ring *output_ring;
+} jobring_t;
+
+struct result {
+       int done;
+       int err;
+       uint32_t status;
+       char outstr[256];
+};
+
+int sec_init(void);
+int jr_reset(void);
+int jr_enqueue(struct jobring *jr, uint32_t *desc_addr,
+               void (*callback)(uint32_t desc, uint32_t status, void *arg),
+               void *arg);
+int jr_dequeue(struct jobring *jr);
+int caam_jr_strstatus(char *outstr, u32 status);
+
+#endif
--
1.7.7.6




------------------------------

Message: 3
Date: Thu, 28 Mar 2013 16:16:30 +0530
From: Ruchika Gupta <ruchika.gupta at freescale.com>
Subject: [U-Boot] [PATCH 0/5] FSL SECURE BOOT: Add support for next
        level   image validation
To: <u-boot at lists.denx.de>, <afleming at freescale.com>
Cc: Ruchika Gupta <ruchika.gupta at freescale.com>
Message-ID:
        <1364467595-15539-1-git-send-email-ruchika.gupta at freescale.com>
Content-Type: text/plain

The patch set adds support for next level image validation (linux,
rootfs, dtb) in secure boot scenarios.

The patch set adds the following functaionality :
1. In secure boot, PAMU is not in bypassed mode. For validating next level images,
CAAM block needs to be accessed. In order to access the CAAM block, first PAMU
needs to be configured to allow access to CAAM block from core. This patch set
adds the basic driver for PAMU.

2. Support has been added for using job ring interface of SEC block to do
cryptographic operations. Descriptors for the following crypto operations
have been added
a) RSA modular exponentiation
b) SHA-256
c) cryptographic blob encryption/decryption

3. esbc_validate command added which uses the SEC block and verifies the images.
esbc_validate command is meant for validating header and
signature of images (Boot Script and ESBC uboot client).
SHA-256 and RSA operations are performed using SEC block in HW.
This command works on both high-end (P4080) and low-end (P1010) platforms.


Ruchika Gupta (5):
  arch/powerpc/cpu/mpc8xxx: PAMU driver support
  powerpc/pamu : PAMU configuration for accessing SEC block
  drivers/sec : Freescale SEC driver
  FSL SEC Driver : Add support for descriptor creation
  Added command for validation of images in case of secure boot

 Makefile                                     |    1 +
 arch/powerpc/cpu/mpc85xx/Makefile            |    2 +
 arch/powerpc/cpu/mpc85xx/cmd_esbc_validate.c |   54 +
 arch/powerpc/cpu/mpc85xx/cpu_init.c          |   17 +
 arch/powerpc/cpu/mpc85xx/fsl_sfp_snvs.c      |  163 +++
 arch/powerpc/cpu/mpc85xx/fsl_validate.c      |  543 +++++++++
 arch/powerpc/cpu/mpc8xxx/Makefile            |    3 +-
 arch/powerpc/cpu/mpc8xxx/fsl_pamu.c          |  488 ++++++++
 arch/powerpc/cpu/mpc8xxx/fsl_pamu_table.c    |   68 ++
 arch/powerpc/include/asm/fsl_pamu.h          |  194 ++++
 arch/powerpc/include/asm/fsl_secure_boot.h   |   68 ++-
 arch/powerpc/include/asm/fsl_sfp_snvs.h      |   42 +
 arch/powerpc/include/asm/immap_85xx.h        |  121 ++-
 arch/powerpc/include/asm/types.h             |    5 +-
 drivers/sec/Makefile                         |   46 +
 drivers/sec/error.c                          |  259 +++++
 drivers/sec/jobdesc.c                        |  157 +++
 drivers/sec/jr.c                             |  319 +++++
 drivers/sec/rsa_sec.c                        |   95 ++
 drivers/sec/sha.c                            |  111 ++
 include/desc.h                               | 1605 ++++++++++++++++++++++++++
 include/desc_constr.h                        |  200 ++++
 include/jobdesc.h                            |   55 +
 include/jr.h                                 |  129 ++
 include/rsa_sec.h                            |   59 +
 include/sha.h                                |  100 ++
 26 files changed, 4900 insertions(+), 4 deletions(-)
 create mode 100644 arch/powerpc/cpu/mpc85xx/cmd_esbc_validate.c
 create mode 100644 arch/powerpc/cpu/mpc85xx/fsl_sfp_snvs.c
 create mode 100644 arch/powerpc/cpu/mpc85xx/fsl_validate.c
 create mode 100644 arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
 create mode 100644 arch/powerpc/cpu/mpc8xxx/fsl_pamu_table.c
 create mode 100644 arch/powerpc/include/asm/fsl_pamu.h
 create mode 100644 arch/powerpc/include/asm/fsl_sfp_snvs.h
 create mode 100644 drivers/sec/Makefile
 create mode 100644 drivers/sec/error.c
 create mode 100644 drivers/sec/jobdesc.c
 create mode 100644 drivers/sec/jr.c
 create mode 100644 drivers/sec/rsa_sec.c
 create mode 100644 drivers/sec/sha.c
 create mode 100644 include/desc.h
 create mode 100644 include/desc_constr.h
 create mode 100644 include/jobdesc.h
 create mode 100644 include/jr.h
 create mode 100644 include/rsa_sec.h
 create mode 100644 include/sha.h

--
1.7.7.6




------------------------------

Message: 4
Date: Thu, 28 Mar 2013 16:16:34 +0530
From: Ruchika Gupta <ruchika.gupta at freescale.com>
Subject: [U-Boot] [PATCH 4/5] FSL SEC Driver : Add support for
        descriptor      creation
To: <u-boot at lists.denx.de>, <afleming at freescale.com>
Cc: Kuldip Giroh <kuldip.giroh at freescale.com>,  Ruchika Gupta
        <ruchika.gupta at freescale.com>
Message-ID:
        <1364467595-15539-5-git-send-email-ruchika.gupta at freescale.com>
Content-Type: text/plain

The patch add supports for descriptor creation for doing
1.SHA256 and RSA Modular exponentiation.
2. Cryptographic blob encryption/decryption

Following files have been picked up from caam driver in Linux :
        drivers/sec/error.c
        include/desc_constr.h

Signed-off-by: Kuldip Giroh <kuldip.giroh at freescale.com>
Signed-off-by: Ruchika Gupta <ruchika.gupta at freescale.com>
---
Based upon git://git.denx.de/u-boot.git branch master

 drivers/sec/Makefile  |    2 +-
 drivers/sec/error.c   |  259 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/sec/jobdesc.c |  157 ++++++++++++++++++++++++++++++
 drivers/sec/rsa_sec.c |   95 ++++++++++++++++++
 drivers/sec/sha.c     |  111 +++++++++++++++++++++
 include/desc_constr.h |  200 ++++++++++++++++++++++++++++++++++++++
 include/jobdesc.h     |   55 +++++++++++
 include/rsa_sec.h     |   59 +++++++++++
 include/sha.h         |  100 +++++++++++++++++++
 9 files changed, 1037 insertions(+), 1 deletions(-)
 create mode 100644 drivers/sec/error.c
 create mode 100644 drivers/sec/jobdesc.c
 create mode 100644 drivers/sec/rsa_sec.c
 create mode 100644 drivers/sec/sha.c
 create mode 100644 include/desc_constr.h
 create mode 100644 include/jobdesc.h
 create mode 100644 include/rsa_sec.h
 create mode 100644 include/sha.h

diff --git a/drivers/sec/Makefile b/drivers/sec/Makefile
index 33c707e..01eafba 100644
--- a/drivers/sec/Makefile
+++ b/drivers/sec/Makefile
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk

 LIB    := $(obj)libsec.o

-COBJS-$(CONFIG_SECURE_BOOT) += jr.o
+COBJS-$(CONFIG_SECURE_BOOT) += jr.o jobdesc.o sha.o rsa_sec.o error.o

 COBJS  := $(COBJS-y)
 SRCS   := $(COBJS:.o=.c)
diff --git a/drivers/sec/error.c b/drivers/sec/error.c
new file mode 100644
index 0000000..f8bd273
--- /dev/null
+++ b/drivers/sec/error.c
@@ -0,0 +1,259 @@
+/*
+ * CAAM Error Reporting
+ *
+ * Copyright 2009-2012 Freescale Semiconductor, Inc.
+ */
+
+#include <common.h>
+#include <jr.h>
+#include <malloc.h>
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#define JRSTA_SSRC_SHIFT            28
+#define JRSTA_CCBERR_CHAID_MASK     0x00f0
+#define JRSTA_CCBERR_CHAID_SHIFT    4
+#define JRSTA_CCBERR_ERRID_MASK     0x000
+
+#define JRSTA_DECOERR_JUMP          0x08000000
+#define JRSTA_DECOERR_INDEX_SHIFT   8
+#define JRSTA_DECOERR_INDEX_MASK    0xff00
+#define JRSTA_DECOERR_ERROR_MASK    0x00ff
+
+#define SPRINTFCAT(str, format, param, max_alloc)              \
+{                                                              \
+       char *tmp;                                              \
+                                                               \
+       tmp = malloc(sizeof(format) + max_alloc);               \
+       sprintf(tmp, format, param);                            \
+       strcat(str, tmp);                                       \
+       free(tmp);                                              \
+}
+
+static void report_jump_idx(u32 status, char *outstr)
+{
+       u8 idx = (status & JRSTA_DECOERR_INDEX_MASK) >>
+                 JRSTA_DECOERR_INDEX_SHIFT;
+
+       if (status & JRSTA_DECOERR_JUMP)
+               strcat(outstr, "jump tgt desc idx ");
+       else
+               strcat(outstr, "desc idx ");
+
+       SPRINTFCAT(outstr, "%d: ", idx, sizeof("255"));
+}
+
+static void report_ccb_status(u32 status, char *outstr)
+{
+       char *cha_id_list[] = {
+               "",
+               "AES",
+               "DES, 3DES",
+               "ARC4",
+               "MD5, SHA-1, SH-224, SHA-256, SHA-384, SHA-512",
+               "RNG",
+               "SNOW f8",
+               "Kasumi f8, f9",
+               "All Public Key Algorithms",
+               "CRC",
+               "SNOW f9",
+       };
+       char *err_id_list[] = {
+               "None. No error.",
+               "Mode error.",
+               "Data size error.",
+               "Key size error.",
+               "PKHA A memory size error.",
+               "PKHA B memory size error.",
+               "Data arrived out of sequence error.",
+               "PKHA divide-by-zero error.",
+               "PKHA modulus even error.",
+               "DES key parity error.",
+               "ICV check failed.",
+               "Hardware error.",
+               "Unsupported CCM AAD size.",
+               "Class 1 CHA is not reset",
+               "Invalid CHA combination was selected",
+               "Invalid CHA selected.",
+       };
+       u8 cha_id = (status & JRSTA_CCBERR_CHAID_MASK) >>
+                   JRSTA_CCBERR_CHAID_SHIFT;
+       u8 err_id = status & JRSTA_CCBERR_ERRID_MASK;
+
+       report_jump_idx(status, outstr);
+
+       if (cha_id < ARRAY_SIZE(cha_id_list)) {
+               SPRINTFCAT(outstr, "%s: ", cha_id_list[cha_id],
+                          strlen(cha_id_list[cha_id]));
+       } else {
+               SPRINTFCAT(outstr, "unidentified cha_id value 0x%02x: ",
+                          cha_id, sizeof("ff"));
+       }
+
+       if (err_id < ARRAY_SIZE(err_id_list)) {
+               SPRINTFCAT(outstr, "%s", err_id_list[err_id],
+                          strlen(err_id_list[err_id]));
+       } else {
+               SPRINTFCAT(outstr, "unidentified err_id value 0x%02x",
+                          err_id, sizeof("ff"));
+       }
+}
+
+static void report_jump_status(u32 status, char *outstr)
+{
+       SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
+}
+
+static void report_deco_status(u32 status, char *outstr)
+{
+       const struct {
+               u8 value;
+               char *error_text;
+       } desc_error_list[] = {
+               { 0x00, "None. No error." },
+               { 0x01, "SGT Length Error. The descriptor is trying to read "
+                       "more data than is contained in the SGT table." },
+               { 0x02, "Reserved." },
+               { 0x03, "Job Ring Control Error. There is a bad value in the "
+                       "Job Ring Control register." },
+               { 0x04, "Invalid Descriptor Command. The Descriptor Command "
+                       "field is invalid." },
+               { 0x05, "Reserved." },
+               { 0x06, "Invalid KEY Command" },
+               { 0x07, "Invalid LOAD Command" },
+               { 0x08, "Invalid STORE Command" },
+               { 0x09, "Invalid OPERATION Command" },
+               { 0x0A, "Invalid FIFO LOAD Command" },
+               { 0x0B, "Invalid FIFO STORE Command" },
+               { 0x0C, "Invalid MOVE Command" },
+               { 0x0D, "Invalid JUMP Command. A nonlocal JUMP Command is "
+                       "invalid because the target is not a Job Header "
+                       "Command, or the jump is from a Trusted Descriptor to "
+                       "a Job Descriptor, or because the target Descriptor "
+                       "contains a Shared Descriptor." },
+               { 0x0E, "Invalid MATH Command" },
+               { 0x0F, "Invalid SIGNATURE Command" },
+               { 0x10, "Invalid Sequence Command. A SEQ IN PTR OR SEQ OUT PTR "
+                       "Command is invalid or a SEQ KEY, SEQ LOAD, SEQ FIFO "
+                       "LOAD, or SEQ FIFO STORE decremented the input or "
+                       "output sequence length below 0. This error may result "
+                       "if a built-in PROTOCOL Command has encountered a "
+                       "malformed PDU." },
+               { 0x11, "Skip data type invalid. The type must be 0xE or 0xF."},
+               { 0x12, "Shared Descriptor Header Error" },
+               { 0x13, "Header Error. Invalid length or parity, or certain "
+                       "other problems." },
+               { 0x14, "Burster Error. Burster has gotten to an illegal "
+                       "state" },
+               { 0x15, "Context Register Length Error. The descriptor is "
+                       "trying to read or write past the end of the Context "
+                       "Register. A SEQ LOAD or SEQ STORE with the VLF bit "
+                       "set was executed with too large a length in the "
+                       "variable length register (VSOL for SEQ STORE or VSIL "
+                       "for SEQ LOAD)." },
+               { 0x16, "DMA Error" },
+               { 0x17, "Reserved." },
+               { 0x1A, "Job failed due to JR reset" },
+               { 0x1B, "Job failed due to Fail Mode" },
+               { 0x1C, "DECO Watchdog timer timeout error" },
+               { 0x1D, "DECO tried to copy a key from another DECO but the "
+                       "other DECO's Key Registers were locked" },
+               { 0x1E, "DECO attempted to copy data from a DECO that had an "
+                       "unmasked Descriptor error" },
+               { 0x1F, "LIODN error. DECO was trying to share from itself or "
+                       "from another DECO but the two Non-SEQ LIODN values "
+                       "didn't match or the 'shared from' DECO's Descriptor "
+                       "required that the SEQ LIODNs be the same and they "
+                       "aren't." },
+               { 0x20, "DECO has completed a reset initiated via the DRR "
+                       "register" },
+               { 0x21, "Nonce error. When using EKT (CCM) key encryption "
+                       "option in the FIFO STORE Command, the Nonce counter "
+                       "reached its maximum value and this encryption mode "
+                       "can no longer be used." },
+               { 0x22, "Meta data is too large (> 511 bytes) for TLS decap "
+                       "(input frame; block ciphers) and IPsec decap (output "
+                       "frame, when doing the next header byte update) and "
+                       "DCRC (output frame)." },
+               { 0x80, "DNR (do not run) error" },
+               { 0x81, "undefined protocol command" },
+               { 0x82, "invalid setting in PDB" },
+               { 0x83, "Anti-replay LATE error" },
+               { 0x84, "Anti-replay REPLAY error" },
+               { 0x85, "Sequence number overflow" },
+               { 0x86, "Sigver invalid signature" },
+               { 0x87, "DSA Sign Illegal test descriptor" },
+               { 0x88, "Protocol Format Error - A protocol has seen an error "
+                       "in the format of data received. When running RSA, "
+                       "this means that formatting with random padding was "
+                       "used, and did not follow the form: 0x00, 0x02, 8-to-N "
+                       "bytes of non-zero pad, 0x00, F data." },
+               { 0x89, "Protocol Size Error - A protocol has seen an error in "
+                       "size. When running RSA, pdb size N < (size of F) when "
+                       "no formatting is used; or pdb size N < (F + 11) when "
+                       "formatting is used." },
+               { 0xC1, "Blob Command error: Undefined mode" },
+               { 0xC2, "Blob Command error: Secure Memory Blob mode error" },
+               { 0xC4, "Blob Command error: Black Blob key or input size "
+                       "error" },
+               { 0xC5, "Blob Command error: Invalid key destination" },
+               { 0xC8, "Blob Command error: Trusted/Secure mode error" },
+               { 0xF0, "IPsec TTL or hop limit field either came in as 0, "
+                       "or was decremented to 0" },
+               { 0xF1, "3GPP HFN matches or exceeds the Threshold" },
+       };
+       u8 desc_error = status & JRSTA_DECOERR_ERROR_MASK;
+       int i;
+
+       report_jump_idx(status, outstr);
+
+       for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
+               if (desc_error_list[i].value == desc_error)
+                       break;
+
+       if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text) {
+               SPRINTFCAT(outstr, "%s", desc_error_list[i].error_text,
+                          strlen(desc_error_list[i].error_text));
+       } else {
+               SPRINTFCAT(outstr, "unidentified error value 0x%02x",
+                          desc_error, sizeof("ff"));
+       }
+}
+
+static void report_jr_status(u32 status, char *outstr)
+{
+}
+
+static void report_cond_code_status(u32 status, char *outstr)
+{
+       SPRINTFCAT(outstr, "%s() not implemented", __func__, sizeof(__func__));
+}
+
+int caam_jr_strstatus(char *outstr, u32 status)
+{
+       int ret = 0;
+       struct stat_src {
+               void (*report_ssed)(u32 status, char *outstr);
+               char *error;
+       } status_src[] = {
+               { NULL, "No error" },
+               { NULL, NULL },
+               { report_ccb_status, "CCB" },
+               { report_jump_status, "Jump" },
+               { report_deco_status, "DECO" },
+               { NULL, NULL },
+               { report_jr_status, "Job Ring" },
+               { report_cond_code_status, "Condition Code" },
+       };
+       u32 ssrc = status >> JRSTA_SSRC_SHIFT;
+
+       sprintf(outstr, "%s: ", status_src[ssrc].error);
+
+       if (status_src[ssrc].report_ssed) {
+               status_src[ssrc].report_ssed(status, outstr);
+               ret = -1;
+       } else
+               ret = 0;
+
+       return ret;
+}
diff --git a/drivers/sec/jobdesc.c b/drivers/sec/jobdesc.c
new file mode 100644
index 0000000..21b4017
--- /dev/null
+++ b/drivers/sec/jobdesc.c
@@ -0,0 +1,157 @@
+/*
+ * SEC Descriptor Construction Library
+ * Basic job descriptor construction
+ *
+ * Copyright (c) 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <common.h>
+#include <desc_constr.h>
+#include <jobdesc.h>
+
+void inline_cnstr_jobdesc_blob_encrypt(uint32_t *desc, uint8_t *key_idnfr,
+                uint32_t keysz, uint8_t *plain_txt, uint8_t *enc_blob,
+                                       uint32_t in_sz, uint32_t out_sz)
+{
+
+       dma_addr_t dma_addr_key_idnfr, dma_addr_in, dma_addr_out;
+       uint32_t key_sz = 16 ;
+
+       dma_addr_key_idnfr = virt_to_phys((void *)key_idnfr);
+       dma_addr_in     = virt_to_phys((void *)plain_txt);
+       dma_addr_out    = virt_to_phys((void *)enc_blob);
+
+       init_job_desc(desc, 0);
+       append_key(desc, dma_addr_key_idnfr, key_sz, CLASS_2);
+
+       if (in_sz > 0xffff) {
+               append_seq_in_ptr(desc, dma_addr_in, 0, SQIN_EXT);
+               append_cmd(desc, in_sz);
+       } else {
+               append_seq_in_ptr(desc, dma_addr_in, in_sz, 0);
+       }
+
+       if (out_sz > 0xffff) {
+               append_seq_out_ptr(desc, dma_addr_out, 0, SQOUT_EXT);
+               append_cmd(desc, out_sz);
+       } else {
+               append_seq_out_ptr(desc, dma_addr_out, out_sz, 0);
+       }
+       append_operation(desc, OP_TYPE_ENCAP_PROTOCOL | OP_PCLID_BLOB);
+}
+
+void inline_cnstr_jobdesc_blob_decrypt(uint32_t *desc, uint8_t *key_idnfr,
+                       uint32_t keysz, uint8_t *enc_blob, uint8_t *plain_txt,
+                                             uint32_t in_sz, uint32_t out_sz)
+{
+       dma_addr_t dma_addr_key_idnfr, dma_addr_in, dma_addr_out;
+       uint32_t key_sz = 16 ;
+
+       dma_addr_key_idnfr = virt_to_phys((void *)key_idnfr);
+       dma_addr_in     = virt_to_phys((void *)enc_blob);
+       dma_addr_out    = virt_to_phys((void *)plain_txt);
+
+       init_job_desc(desc, 0);
+       append_key(desc, dma_addr_key_idnfr, key_sz, CLASS_2);
+       if (in_sz > 0xffff) {
+               append_seq_in_ptr(desc, dma_addr_in, 0, SQIN_EXT);
+               append_cmd(desc, in_sz);
+       } else {
+               append_seq_in_ptr(desc, dma_addr_in, in_sz, 0);
+       }
+
+       if (out_sz > 0xffff) {
+               append_seq_out_ptr(desc, dma_addr_out, 0, SQOUT_EXT);
+               append_cmd(desc, out_sz);
+       } else {
+               append_seq_out_ptr(desc, dma_addr_out, out_sz, 0);
+       }
+
+       append_operation(desc, OP_TYPE_DECAP_PROTOCOL | OP_PCLID_BLOB);
+}
+
+
+/* Change key size to bytes form bits in calling function*/
+void inline_cnstr_jobdesc_pkha_rsaexp(uint32_t *desc,
+                                     struct pk_in_params *pkin, uint8_t *out,
+                                     uint32_t out_siz)
+{
+       dma_addr_t dma_addr_e, dma_addr_a, dma_addr_n, dma_addr_out;
+
+       dma_addr_e = virt_to_phys((void *)pkin->e);
+       dma_addr_a = virt_to_phys((void *)pkin->a);
+       dma_addr_n = virt_to_phys((void *)pkin->n);
+       dma_addr_out = virt_to_phys((void *)out);
+
+       init_job_desc(desc, 0);
+       append_key(desc, dma_addr_e, pkin->e_siz, KEY_DEST_PKHA_E | CLASS_1);
+
+       append_fifo_load(desc, dma_addr_a,
+                        pkin->a_siz, LDST_CLASS_1_CCB | FIFOLD_TYPE_PK_A);
+
+       append_fifo_load(desc, dma_addr_n,
+                        pkin->n_siz, LDST_CLASS_1_CCB | FIFOLD_TYPE_PK_N);
+
+       append_operation(desc, OP_TYPE_PK | OP_ALG_PK | OP_ALG_PKMODE_MOD_EXPO);
+
+       append_fifo_store(desc, dma_addr_out, out_siz,
+                         LDST_CLASS_1_CCB | FIFOST_TYPE_PKHA_B);
+}
+
+void inline_cnstr_jobdesc_sha256(uint32_t *desc,
+                                uint8_t *msg, uint32_t msgsz,
+                                uint8_t *digest)
+{
+       /* SHA 256 , output is of length 32 words */
+       uint32_t storelen = 32;
+       dma_addr_t dma_addr_in, dma_addr_out;
+
+       dma_addr_in = virt_to_phys((void *)msg);
+       dma_addr_out = virt_to_phys((void *)digest);
+
+       init_job_desc(desc, 0);
+       append_operation(desc,
+                        OP_TYPE_CLASS2_ALG | OP_ALG_ALGSEL_SHA256 |
+                        OP_ALG_AAI_HASH | OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT
+                        | OP_ALG_ICV_OFF);
+       if (msgsz > 0xffff) {
+               append_fifo_load(desc, dma_addr_in, 0,
+                                LDST_CLASS_2_CCB | FIFOLDST_SGF |
+                                FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST2 |
+                                FIFOLDST_EXT);
+               append_cmd(desc, msgsz);
+       } else
+               append_fifo_load(desc, dma_addr_in, msgsz,
+                                LDST_CLASS_2_CCB | FIFOLDST_SGF |
+                                FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST2);
+       append_store(desc, dma_addr_out, storelen,
+                    LDST_CLASS_2_CCB | LDST_SRCDST_BYTE_CONTEXT);
+}
diff --git a/drivers/sec/rsa_sec.c b/drivers/sec/rsa_sec.c
new file mode 100644
index 0000000..6e114aa
--- /dev/null
+++ b/drivers/sec/rsa_sec.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <common.h>
+#include <rsa_sec.h>
+#include <jobdesc.h>
+
+extern struct jobring jr;
+
+void rsa_done(uint32_t desc, uint32_t status, void *arg)
+{
+       struct result *x = arg;
+       x->status = status;
+#ifdef DEBUG
+       x->err = caam_jr_strstatus(x->outstr, status);
+#else
+       if (status)
+               x->err = -1;
+#endif
+
+       x->done = 1;
+}
+
+/* This functionw ould return teh status returned by SEC .
+ * If non zero , means there was some error reported by SEC */
+int rsa_public_verif_sec(unsigned char *sign, uint8_t *to, uint8_t *rsa_pub_key,
+                       int klen, struct rsa_context *ctx)
+{
+       unsigned long long timeval;
+       unsigned long long timeout;
+       int ret = 0;
+       memset(ctx, 0, sizeof(struct rsa_context));
+
+       ctx->pkin.a = sign;
+       ctx->pkin.a_siz = klen;
+       ctx->pkin.n = rsa_pub_key;
+       ctx->pkin.n_siz = klen;
+       ctx->pkin.e = rsa_pub_key + klen;
+       ctx->pkin.e_siz = klen;
+
+       inline_cnstr_jobdesc_pkha_rsaexp(ctx->rsa_desc,
+                             &ctx->pkin, to,
+                             klen);
+
+       ret = jr_enqueue(&jr, ctx->rsa_desc, rsa_done, &ctx->op);
+       if (ret)
+               return ret;
+
+       timeval = get_ticks();
+       timeout = usec2ticks(CONFIG_SEC_DEQ_TIMEOUT);
+
+       while (ctx->op.done != 1) {
+               if (jr_dequeue(&jr))
+                       return JQ_DEQ_ERR;
+
+               if ((get_ticks() - timeval) > timeout) {
+                       printf("SEC Dequeue timed out\n");
+                       return JQ_DEQ_TO_ERR;
+               }
+       }
+
+       if (ctx->op.err < 0)
+               return ctx->op.status;
+
+       return 0;
+}
diff --git a/drivers/sec/sha.c b/drivers/sec/sha.c
new file mode 100644
index 0000000..4bbae65
--- /dev/null
+++ b/drivers/sec/sha.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <common.h>
+#include <jobdesc.h>
+#include <sha.h>
+
+extern struct jobring jr;
+
+void sha_done(uint32_t desc, uint32_t status, void *arg)
+{
+       struct result *x = arg;
+       x->status = status;
+       x->err = caam_jr_strstatus(x->outstr, status);
+       x->done = 1;
+}
+
+/* This function initializes the sha-256 context */
+void sha_init(struct sha_ctx *ctx)
+{
+       memset(ctx, 0, sizeof(struct sha_ctx));
+       ctx->jr = &jr;
+}
+
+void sha_update(struct sha_ctx *ctx, u8 *buffer, u32 length)
+{
+       dma_addr_t addr = virt_to_phys((void *)buffer);
+#ifdef CONFIG_PHYS_64BIT
+       ctx->sg_tbl[ctx->sg_num].addr_hi = addr >> 32;
+#else
+       ctx->sg_tbl[ctx->sg_num].addr_hi = 0x0;
+#endif
+       ctx->sg_tbl[ctx->sg_num].addr_lo = addr;
+       ctx->sg_tbl[ctx->sg_num].length = length;
+       ctx->sg_num++;
+}
+
+int sha_final(struct sha_ctx *ctx)
+{
+       int ret = 0, i = 0;
+       ctx->sg_tbl[ctx->sg_num - 1].final = 1;
+       uint32_t len = 0;
+
+       for (i = 0; i < ctx->sg_num; i++)
+               len +=  ctx->sg_tbl[i].length;
+
+       inline_cnstr_jobdesc_sha256(ctx->sha_desc,
+                          (uint8_t *)ctx->sg_tbl, len, ctx->hash);
+
+       ret = jr_enqueue(ctx->jr, ctx->sha_desc, sha_done, &ctx->op);
+       if (ret)
+               return ret;
+
+       return ret;
+}
+
+
+/* This  function  completes the calulation of the sha-256 */
+int sha_digest(struct sha_ctx *ctx, uint8_t *digest)
+{
+       unsigned long long timeval = get_ticks();
+       unsigned long long timeout = usec2ticks(CONFIG_SEC_DEQ_TIMEOUT);
+       int ret = 0;
+
+       while (ctx->op.done != 1) {
+               ret = jr_dequeue(ctx->jr);
+               if (ret)
+                       return ret;
+
+               if ((get_ticks() - timeval) > timeout) {
+                       printf("SEC Dequeue timed out\n");
+                       return JQ_DEQ_TO_ERR;
+               }
+       }
+
+       if (ctx->op.err < 0)
+               return ctx->op.status;
+
+       memcpy(digest, ctx->hash, sizeof(ctx->hash));
+
+       return 0;
+}
diff --git a/include/desc_constr.h b/include/desc_constr.h
new file mode 100644
index 0000000..e3e778f
--- /dev/null
+++ b/include/desc_constr.h
@@ -0,0 +1,200 @@
+/*
+ * caam descriptor construction helper functions
+ *
+ * Copyright 2008-2011, 2012 Freescale Semiconductor, Inc.
+ */
+
+#include "desc.h"
+
+#define IMMEDIATE (1 << 23)
+#define CAAM_CMD_SZ sizeof(u32)
+#define CAAM_PTR_SZ sizeof(dma_addr_t)
+#define CAAM_DESC_BYTES_MAX (CAAM_CMD_SZ * 64)
+
+#define PRINT_POS
+
+#define DISABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
+                               LDST_SRCDST_WORD_DECOCTRL | \
+                               (LDOFF_DISABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
+#define ENABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
+                              LDST_SRCDST_WORD_DECOCTRL | \
+                              (LDOFF_ENABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
+
+static inline int desc_len(u32 *desc)
+{
+       return *desc & HDR_DESCLEN_MASK;
+}
+
+static inline int desc_bytes(void *desc)
+{
+       return desc_len(desc) * CAAM_CMD_SZ;
+}
+
+static inline u32 *desc_end(u32 *desc)
+{
+       return desc + desc_len(desc);
+}
+
+static inline void *sh_desc_pdb(u32 *desc)
+{
+       return desc + 1;
+}
+
+static inline void init_desc(u32 *desc, u32 options)
+{
+       *desc = options | HDR_ONE | 1;
+}
+
+static inline void init_sh_desc(u32 *desc, u32 options)
+{
+       PRINT_POS;
+       init_desc(desc, CMD_SHARED_DESC_HDR | options);
+}
+
+static inline void init_sh_desc_pdb(u32 *desc, u32 options, size_t pdb_bytes)
+{
+       u32 pdb_len = pdb_bytes / CAAM_CMD_SZ + 1;
+
+       init_sh_desc(desc, ((pdb_len << HDR_START_IDX_SHIFT) + pdb_len) |
+                    options);
+}
+
+static inline void init_job_desc(u32 *desc, u32 options)
+{
+       init_desc(desc, CMD_DESC_HDR | options);
+}
+
+static inline void append_ptr(u32 *desc, dma_addr_t ptr)
+{
+       dma_addr_t *offset = (dma_addr_t *)desc_end(desc);
+
+       *offset = ptr;
+
+       (*desc) += CAAM_PTR_SZ / CAAM_CMD_SZ;
+}
+
+static inline void init_job_desc_shared(u32 *desc, dma_addr_t ptr, int len,
+                                       u32 options)
+{
+       PRINT_POS;
+       init_job_desc(desc, HDR_SHARED | options |
+                     (len << HDR_START_IDX_SHIFT));
+       append_ptr(desc, ptr);
+}
+
+static inline void append_data(u32 *desc, void *data, int len)
+{
+       u32 *offset = desc_end(desc);
+
+       if (len) /* avoid sparse warning: memcpy with byte count of 0 */
+               memcpy(offset, data, len);
+
+       (*desc) += (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
+}
+
+static inline void append_cmd(u32 *desc, u32 command)
+{
+       u32 *cmd = desc_end(desc);
+
+       *cmd = command;
+
+       (*desc)++;
+}
+
+static inline void append_cmd_ptr(u32 *desc, dma_addr_t ptr, int len,
+                                 u32 command)
+{
+       append_cmd(desc, command | len);
+       append_ptr(desc, ptr);
+}
+
+static inline void append_cmd_data(u32 *desc, void *data, int len,
+                                  u32 command)
+{
+       append_cmd(desc, command | IMMEDIATE | len);
+       append_data(desc, data, len);
+}
+
+static inline u32 *append_jump(u32 *desc, u32 options)
+{
+       u32 *cmd = desc_end(desc);
+
+       PRINT_POS;
+       append_cmd(desc, CMD_JUMP | options);
+
+       return cmd;
+}
+
+static inline void set_jump_tgt_here(u32 *desc, u32 *jump_cmd)
+{
+       *jump_cmd = *jump_cmd | (desc_len(desc) - (jump_cmd - desc));
+}
+
+#define APPEND_CMD(cmd, op) \
+static inline void append_##cmd(u32 *desc, u32 options) \
+{ \
+       PRINT_POS; \
+       append_cmd(desc, CMD_##op | options); \
+}
+APPEND_CMD(operation, OPERATION)
+APPEND_CMD(move, MOVE)
+
+#define APPEND_CMD_LEN(cmd, op) \
+static inline void append_##cmd(u32 *desc, unsigned int len, u32 options) \
+{ \
+       PRINT_POS; \
+       append_cmd(desc, CMD_##op | len | options); \
+}
+APPEND_CMD_LEN(seq_store, SEQ_STORE)
+APPEND_CMD_LEN(seq_fifo_load, SEQ_FIFO_LOAD)
+APPEND_CMD_LEN(seq_fifo_store, SEQ_FIFO_STORE)
+
+#define APPEND_CMD_PTR(cmd, op) \
+static inline void append_##cmd(u32 *desc, dma_addr_t ptr, unsigned int len, \
+                               u32 options) \
+{ \
+       PRINT_POS; \
+       append_cmd_ptr(desc, ptr, len, CMD_##op | options); \
+}
+APPEND_CMD_PTR(key, KEY)
+APPEND_CMD_PTR(seq_in_ptr, SEQ_IN_PTR)
+APPEND_CMD_PTR(seq_out_ptr, SEQ_OUT_PTR)
+APPEND_CMD_PTR(load, LOAD)
+APPEND_CMD_PTR(store, STORE)
+APPEND_CMD_PTR(fifo_load, FIFO_LOAD)
+APPEND_CMD_PTR(fifo_store, FIFO_STORE)
+
+#define APPEND_CMD_PTR_TO_IMM(cmd, op) \
+static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
+                                        unsigned int len, u32 options) \
+{ \
+       PRINT_POS; \
+       append_cmd_data(desc, data, len, CMD_##op | options); \
+}
+APPEND_CMD_PTR_TO_IMM(load, LOAD);
+APPEND_CMD_PTR_TO_IMM(fifo_load, FIFO_LOAD);
+
+/*
+ * 2nd variant for commands whose specified immediate length differs
+ * from length of immediate data provided, e.g., split keys
+ */
+#define APPEND_CMD_PTR_TO_IMM2(cmd, op) \
+static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
+                                        unsigned int data_len, \
+                                        unsigned int len, u32 options) \
+{ \
+       PRINT_POS; \
+       append_cmd(desc, CMD_##op | IMMEDIATE | len | options); \
+       append_data(desc, data, data_len); \
+}
+APPEND_CMD_PTR_TO_IMM2(key, KEY);
+
+#define APPEND_CMD_RAW_IMM(cmd, op, type) \
+static inline void append_##cmd##_imm_##type(u32 *desc, type immediate, \
+                                            u32 options) \
+{ \
+       PRINT_POS; \
+       append_cmd(desc, CMD_##op | IMMEDIATE | options | sizeof(type)); \
+       append_cmd(desc, immediate); \
+}
+APPEND_CMD_RAW_IMM(load, LOAD, u32);
diff --git a/include/jobdesc.h b/include/jobdesc.h
new file mode 100644
index 0000000..6eb2827
--- /dev/null
+++ b/include/jobdesc.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __JOBDESC_H
+#define __JOBDESC_H
+
+#include <common.h>
+#include <sha.h>
+#include <rsa_sec.h>
+
+void inline_cnstr_jobdesc_pkha_rsaexp(uint32_t *desc,
+                             struct pk_in_params *pkin, uint8_t *out,
+                             uint32_t out_siz);
+
+void inline_cnstr_jobdesc_sha256(uint32_t *desc,
+       uint8_t *msg, uint32_t msgsz, uint8_t *digest);
+
+void inline_cnstr_jobdesc_blob_encrypt(uint32_t *desc, uint8_t *key_idnfr,
+       uint32_t keysz, uint8_t *plain_txt, uint8_t *enc_blob, uint32_t in_sz,
+       uint32_t out_sz);
+
+void inline_cnstr_jobdesc_blob_decrypt(uint32_t *desc, uint8_t *key_idnfr,
+       uint32_t keysz, uint8_t *plain_txt, uint8_t *enc_blob, uint32_t in_sz,
+       uint32_t out_sz);
+
+#endif
diff --git a/include/rsa_sec.h b/include/rsa_sec.h
new file mode 100644
index 0000000..1f6e218
--- /dev/null
+++ b/include/rsa_sec.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __RSA_SEC_H
+#define __RSA_SEC_H
+
+#include <common.h>
+#include <jr.h>
+
+struct pk_in_params {
+       uint8_t *e;
+       uint32_t e_siz;
+       uint8_t *n;
+       uint32_t n_siz;
+       uint8_t *a;
+       uint32_t a_siz;
+       uint8_t *b;
+       uint32_t b_siz;
+};
+
+struct rsa_context {
+       struct pk_in_params pkin;
+       uint32_t rsa_desc[64];
+       struct result op;
+};
+
+int rsa_public_verif_sec(unsigned char *sign, uint8_t *to, uint8_t *rsa_pub_key,
+                       int klen, struct rsa_context *ctx);
+
+#endif
diff --git a/include/sha.h b/include/sha.h
new file mode 100644
index 0000000..ea4c4c8
--- /dev/null
+++ b/include/sha.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SHA_H
+#define _SHA_H
+
+#include <jr.h>
+
+/* number of bytes in the SHA256-256 digest */
+#define SHA256_DIGEST_SIZE 32
+
+/*
+ * number of words in the digest - Digest is kept internally
+ * as 8 32-bit words
+ */
+#define _SHA256_DIGEST_LENGTH 8
+
+/*
+ * block length - A block, treated as a sequence of
+ * 32-bit words
+ */
+#define SHA256_BLOCK_LENGTH 16
+
+/* number of bytes in the block */
+#define SHA256_DATA_SIZE 64
+
+#define MAX_SG         12
+
+/*
+ * Scatter Gather Entry - Speicifies the the Scatter Gather Format
+ * related information
+ */
+struct sg_entry {
+       uint16_t reserved_zero;
+       uint16_t addr_hi;       /* Memory Address of the start of the
+                                * buffer - hi
+                                */
+       uint32_t addr_lo;       /* Memory Address - lo */
+       unsigned int extension:1;
+       unsigned int final:1;
+       unsigned int length:30; /* Length of the data in the frame */
+       uint8_t reserved_zero2;
+       uint8_t bpid;           /* Buffer Pool Id */
+       unsigned int reserved_offset:3;
+       unsigned int offset:13;
+};
+
+/*
+ * SHA256-256 context
+ * contain the following fields
+ * State
+ * count low
+ * count high
+ * block data buffer
+ * index to the buffer
+ */
+struct sha_ctx {
+       struct sg_entry sg_tbl[MAX_SG];
+       uint32_t sha_desc[64];
+       u8 hash[SHA256_DIGEST_SIZE];
+       struct result op;
+       uint32_t sg_num;
+       struct jobring *jr;
+};
+
+void sha_init(struct sha_ctx *ctx);
+void sha_update(struct sha_ctx *ctx, uint8_t *data, uint32_t length);
+int sha_final(struct sha_ctx *ctx);
+int sha_digest(struct sha_ctx *ctx, uint8_t *digest);
+
+#endif
--
1.7.7.6




------------------------------

Message: 5
Date: Thu, 28 Mar 2013 16:16:31 +0530
From: Ruchika Gupta <ruchika.gupta at freescale.com>
Subject: [U-Boot] [PATCH 1/5] arch/powerpc/cpu/mpc8xxx: PAMU driver
        support
To: <u-boot at lists.denx.de>, <afleming at freescale.com>
Cc: Kuldip Giroh <kuldip.giroh at freescale.com>,  Ruchika Gupta
        <ruchika.gupta at freescale.com>
Message-ID:
        <1364467595-15539-2-git-send-email-ruchika.gupta at freescale.com>
Content-Type: text/plain

PAMU driver basic support for usage in Secure Boot.
In secure boot PAMU is not in bypass mode. Hence to use
any peripheral (SEC Job ring in our case), PAMU has to be
configured.

The Header file fsl_pamu.h and few functions in driver have been derived
from Freescale Libos.

Signed-off-by: Kuldip Giroh <kuldip.giroh at freescale.com>
Signed-off-by: Ruchika Gupta <ruchika.gupta at freescale.com>
---
Based upon git://git.denx.de/u-boot.git branch master

 arch/powerpc/cpu/mpc8xxx/Makefile     |    3 +-
 arch/powerpc/cpu/mpc8xxx/fsl_pamu.c   |  488 +++++++++++++++++++++++++++++++++
 arch/powerpc/include/asm/fsl_pamu.h   |  193 +++++++++++++
 arch/powerpc/include/asm/immap_85xx.h |   18 ++
 4 files changed, 701 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
 create mode 100644 arch/powerpc/include/asm/fsl_pamu.h

diff --git a/arch/powerpc/cpu/mpc8xxx/Makefile b/arch/powerpc/cpu/mpc8xxx/Makefile
index 3dc8e05..097599e 100644
--- a/arch/powerpc/cpu/mpc8xxx/Makefile
+++ b/arch/powerpc/cpu/mpc8xxx/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright 2009-2010 Freescale Semiconductor, Inc.
+# Copyright 2009-2010, 2012 Freescale Semiconductor, Inc.
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -33,6 +33,7 @@ COBJS-$(CONFIG_FSL_IFC) += fsl_ifc.o
 COBJS-$(CONFIG_FSL_LBC) += fsl_lbc.o
 COBJS-$(CONFIG_SYS_SRIO) += srio.o
 COBJS-$(CONFIG_FSL_LAW) += law.o
+COBJS-$(CONFIG_FSL_CORENET) += fsl_pamu.o

 endif

diff --git a/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c b/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
new file mode 100644
index 0000000..bdbec07
--- /dev/null
+++ b/arch/powerpc/cpu/mpc8xxx/fsl_pamu.c
@@ -0,0 +1,488 @@
+/*
+ * FSL PAMU driver
+ *
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *  Few functions in this file have been picked up from Freescale LibOS library
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <asm/fsl_pamu.h>
+
+paace_t *ppaact;
+paace_t *sec;
+
+static inline int __ilog2_roundup_64(uint64_t val)
+{
+
+       if ((val & (val - 1)) == 0)
+               return __ilog2_u64(val);
+       else
+               return  __ilog2_u64(val) + 1;
+}
+
+
+static inline int count_lsb_zeroes(unsigned long val)
+{
+       return ffs(val) - 1;
+}
+
+static unsigned int map_addrspace_size_to_wse(uint64_t addrspace_size)
+{
+       /* window size is 2^(WSE+1) bytes */
+       return count_lsb_zeroes(addrspace_size >> PAMU_PAGE_SHIFT) +
+               PAMU_PAGE_SHIFT - 1;
+}
+
+static unsigned int map_subwindow_cnt_to_wce(uint32_t subwindow_cnt)
+{
+       /* window count is 2^(WCE+1) bytes */
+       return count_lsb_zeroes(subwindow_cnt) - 1;
+}
+
+static void pamu_setup_default_xfer_to_host_ppaace(paace_t *ppaace)
+{
+       set_bf(ppaace->addr_bitfields, PAACE_AF_PT, PAACE_PT_PRIMARY);
+       set_bf(ppaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
+               PAACE_M_COHERENCE_REQ);
+}
+
+static void pamu_setup_default_xfer_to_host_spaace(paace_t *spaace)
+{
+       set_bf(spaace->addr_bitfields, PAACE_AF_PT, PAACE_PT_SECONDARY);
+       set_bf(spaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
+              PAACE_M_COHERENCE_REQ);
+}
+
+static unsigned long get_fspi(void)
+{
+       static int i;
+       unsigned long fspi = i * DEFAULT_NUM_SUBWINDOWS;
+       i++;
+       return fspi;
+}
+
+
+/** Sets up PPAACE entry for specified liodn
+ *
+ * @param[in] liodn      Logical IO device number
+ * @param[in] win_addr   starting address of DSA window
+ * @param[in] win-size   size of DSA window
+ * @param[in] omi        Operation mapping index -- if ~omi == 0 then omi
+                               not defined
+ * @param[in] stashid    cache stash id for associated cpu -- if ~stashid == 0
+                               then stashid not defined
+ * @param[in] snoopid    snoop id for hardware coherency -- if ~snoopid == 0
+                               then snoopid not defined
+ * @param[in] subwin_cnt number of sub-windows
+ *
+ * @return Returns 0 upon success else error code < 0 returned
+ */
+static int pamu_config_ppaace(uint32_t liodn, uint64_t win_addr,
+       uint64_t win_size, uint32_t omi,
+       uint32_t snoopid, uint32_t stashid,
+       uint32_t subwin_cnt)
+{
+       unsigned long fspi;
+       paace_t *ppaace;
+
+       if ((win_size & (win_size - 1)) || win_size < PAMU_PAGE_SIZE)
+               return -1;
+
+       if (win_addr & (win_size - 1))
+               return -2;
+
+       if (liodn > NUM_PPAACT_ENTRIES) {
+               printf("Entries in PPACT not sufficient\n");
+               return -3;
+       }
+
+       ppaace = &ppaact[liodn];
+
+       /* window size is 2^(WSE+1) bytes */
+       set_bf(ppaace->addr_bitfields, PPAACE_AF_WSE,
+               map_addrspace_size_to_wse(win_size));
+
+       pamu_setup_default_xfer_to_host_ppaace(ppaace);
+
+       if (sizeof(phys_addr_t) > 4)
+               ppaace->wbah = (u64)win_addr >> (PAMU_PAGE_SHIFT + 20);
+       else
+               ppaace->wbah = 0;
+
+       set_bf(ppaace->addr_bitfields, PPAACE_AF_WBAL,
+              (win_addr >> PAMU_PAGE_SHIFT));
+
+       /* set up operation mapping if it's configured */
+       if (omi < OME_NUMBER_ENTRIES) {
+               set_bf(ppaace->impl_attr, PAACE_IA_OTM, PAACE_OTM_INDEXED);
+               ppaace->op_encode.index_ot.omi = omi;
+       } else if (~omi != 0)
+               return -3;
+
+       /* configure stash id */
+       if (~stashid != 0)
+               set_bf(ppaace->impl_attr, PAACE_IA_CID, stashid);
+
+       /* configure snoop id */
+       if (~snoopid != 0)
+               ppaace->domain_attr.to_host.snpid = snoopid;
+
+       if (subwin_cnt) {
+               /* We have a single SPAACE for 1 LIODN. So index would
+                       be always 0 */
+               fspi = get_fspi();
+
+               /* window count is 2^(WCE+1) bytes */
+               set_bf(ppaace->impl_attr, PAACE_IA_WCE,
+                      map_subwindow_cnt_to_wce(subwin_cnt));
+               set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0x1);
+               ppaace->fspi = fspi;
+       } else
+               set_bf(ppaace->addr_bitfields, PAACE_AF_AP, PAACE_AP_PERMS_ALL);
+
+       asm volatile("sync" : : : "memory");
+       /* Mark the ppace entry valid */
+       ppaace->addr_bitfields |= PAACE_V_VALID;
+       asm volatile("sync" : : : "memory");
+
+       return 0;
+}
+
+static int pamu_config_spaace(uint32_t liodn,
+       uint64_t subwin_size, uint64_t subwin_addr, uint64_t size,
+       uint32_t omi, uint32_t snoopid, uint32_t stashid)
+{
+       paace_t *paace;
+       unsigned long fspi;
+       /* Align start addr of subwin to subwindoe size */
+       uint64_t sec_addr = subwin_addr & ~(subwin_size - 1);
+       uint64_t end_addr = subwin_addr + size;
+       int size_shift = __ilog2_u64(subwin_size);
+       uint64_t win_size = 0;
+       uint32_t index, swse;
+
+       /* Recalculate the size */
+       size = end_addr - sec_addr;
+
+       if (!subwin_size)
+               return -1;
+
+       if (liodn > NUM_PPAACT_ENTRIES) {
+               printf("LIODN Number to be programmed %d"
+                       "greater than number of PPAACT entries %d\n",
+                               liodn, NUM_PPAACT_ENTRIES);
+               return -1;
+       }
+
+       while (sec_addr < end_addr) {
+#ifdef DEBUG
+               printf("sec_addr < end_addr is %llx < %llx\n", sec_addr,
+                       end_addr);
+#endif
+               paace = &ppaact[liodn];
+               if (!paace)
+                       return -1;
+
+               fspi = paace->fspi;
+
+               /* Calculating the win_size here as if we map in index 0,
+                       paace entry woudl need to  be programmed for SWSE */
+               win_size = end_addr - sec_addr;
+               win_size = 1 << __ilog2_roundup_64(win_size);
+
+               if (win_size > subwin_size)
+                       win_size = subwin_size;
+               else if (win_size < PAMU_PAGE_SIZE)
+                       win_size = PAMU_PAGE_SIZE;
+
+#ifdef DEBUG
+               printf("win_size is %x\n", win_size);
+#endif
+
+               swse = map_addrspace_size_to_wse(win_size);
+               index = fspi +  (sec_addr >> size_shift);
+
+               if (index == 0 || (index % DEFAULT_NUM_SUBWINDOWS) == 0) {
+                       set_bf(paace->win_bitfields, PAACE_WIN_SWSE, swse);
+                       set_bf(paace->addr_bitfields, PAACE_AF_AP,
+                               PAACE_AP_PERMS_ALL);
+                       sec_addr += subwin_size;
+                       continue;
+               }
+
+               paace = sec + index - 1;
+
+#ifdef DEBUG
+               printf("SPAACT:Writing at location %p, index %d\n", paace,
+                       index);
+#endif
+
+               pamu_setup_default_xfer_to_host_spaace(paace);
+               set_bf(paace->addr_bitfields, SPAACE_AF_LIODN, liodn);
+               set_bf(paace->addr_bitfields, PAACE_AF_AP, PAACE_AP_PERMS_ALL);
+
+               /* configure snoop id */
+               if (~snoopid != 0)
+                       paace->domain_attr.to_host.snpid = snoopid;
+
+               if (paace->addr_bitfields & PAACE_V_VALID) {
+#ifdef DEBUG
+                       printf("Reached overlap condition\n");
+                       printf("%d < %d\n", get_bf(paace->win_bitfields,
+                               PAACE_WIN_SWSE), swse);
+#endif
+                       if (get_bf(paace->win_bitfields, PAACE_WIN_SWSE) < swse)
+                               set_bf(paace->win_bitfields, PAACE_WIN_SWSE,
+                                       swse);
+               } else
+                       set_bf(paace->win_bitfields, PAACE_WIN_SWSE, swse);
+
+               paace->addr_bitfields |= PAACE_V_VALID;
+               sec_addr += subwin_size;
+       }
+
+       return 0;
+}
+
+int pamu_init(void)
+{
+       u32 base_addr = CONFIG_SYS_PAMU_ADDR;
+       ccsr_pamu_t *regs;
+       u32 i = 0;
+       u64 ppaact_phys, ppaact_lim, ppaact_size;
+       u64 spaact_phys, spaact_lim, spaact_size;
+
+       ppaact_size = sizeof(paace_t) * NUM_PPAACT_ENTRIES;
+       spaact_size = sizeof(paace_t) * NUM_SPAACT_ENTRIES;
+
+       /* Allocate space for Primary PAACT Table */
+       ppaact = memalign(PAMU_TABLE_ALIGNMENT, ppaact_size);
+       if (!ppaact)
+               return -1;
+       memset(ppaact, 0, ppaact_size);
+
+       /* Allocate space for Secondary PAACT Table */
+       sec = memalign(PAMU_TABLE_ALIGNMENT, spaact_size);
+       if (!sec)
+               return -1;
+       memset(sec, 0, spaact_size);
+
+       ppaact_phys = virt_to_phys((void *)ppaact);
+       ppaact_lim = ppaact_phys + ppaact_size;
+
+       spaact_phys = (uint64_t)virt_to_phys((void *)sec);
+       spaact_lim = spaact_phys + spaact_size;
+
+       /* Configure all PAMU's */
+       for (i = 0; i < CONFIG_NUM_PAMU; i++) {
+               regs = (ccsr_pamu_t *)base_addr;
+
+               out_be32(&regs->ppbah, ppaact_phys >> 32);
+               out_be32(&regs->ppbal, (uint32_t)ppaact_phys);
+
+               out_be32(&regs->pplah, (ppaact_lim) >> 32);
+               out_be32(&regs->pplal, (uint32_t)ppaact_lim);
+
+               if (sec != NULL) {
+                       out_be32(&regs->spbah, spaact_phys >> 32);
+                       out_be32(&regs->spbal, (uint32_t)spaact_phys);
+                       out_be32(&regs->splah, spaact_lim >> 32);
+                       out_be32(&regs->splal, (uint32_t)spaact_lim);
+               }
+               asm volatile("sync" : : : "memory");
+
+               base_addr += PAMU_OFFSET;
+       }
+
+       return 0;
+}
+
+void pamu_enable(void)
+{
+       u32 i = 0;
+       u32 base_addr = CONFIG_SYS_PAMU_ADDR;
+       for (i = 0; i < CONFIG_NUM_PAMU; i++) {
+               setbits_be32((void *)base_addr + PAMU_PCR_OFFSET,
+                       PAMU_PCR_PE);
+               asm volatile("sync" : : : "memory");
+               base_addr += PAMU_OFFSET;
+       }
+}
+
+void pamu_reset(void)
+{
+       u32 i  = 0;
+       u32 base_addr = CONFIG_SYS_PAMU_ADDR;
+       ccsr_pamu_t *regs;
+
+       for (i = 0; i < CONFIG_NUM_PAMU; i++) {
+               regs = (ccsr_pamu_t *)base_addr;
+       /* Clear PPAACT Base register */
+               out_be32(&regs->ppbah, 0);
+               out_be32(&regs->ppbal, 0);
+               out_be32(&regs->pplah, 0);
+               out_be32(&regs->pplal, 0);
+               out_be32(&regs->spbah, 0);
+               out_be32(&regs->spbal, 0);
+               out_be32(&regs->splah, 0);
+               out_be32(&regs->splal, 0);
+
+               clrbits_be32((void *)regs + PAMU_PCR_OFFSET, PAMU_PCR_PE);
+               asm volatile("sync" : : : "memory");
+               base_addr += PAMU_OFFSET;
+       }
+}
+
+void pamu_disable(void)
+{
+       u32 i  = 0;
+       u32 base_addr = CONFIG_SYS_PAMU_ADDR;
+
+
+       for (i = 0; i < CONFIG_NUM_PAMU; i++) {
+               clrbits_be32((void *)base_addr + PAMU_PCR_OFFSET, PAMU_PCR_PE);
+               asm volatile("sync" : : : "memory");
+               base_addr += PAMU_OFFSET;
+       }
+}
+
+
+static uint64_t find_max(uint64_t arr[], int num)
+{
+       int i = 0;
+       int max = 0;
+       for (i = 1 ; i < num; i++)
+               if (arr[max] < arr[i])
+                       max = i;
+
+       return arr[max];
+}
+
+static uint64_t find_min(uint64_t arr[], int num)
+{
+       int i = 0;
+       int min = 0;
+       for (i = 1 ; i < num; i++)
+               if (arr[min] > arr[i])
+                       min = i;
+
+       return arr[min];
+}
+
+static uint32_t get_win_cnt(uint64_t size)
+{
+       uint32_t win_cnt = DEFAULT_NUM_SUBWINDOWS;
+
+       while (win_cnt && (size/win_cnt) < PAMU_PAGE_SIZE)
+               win_cnt >>= 1;
+
+       return win_cnt;
+}
+
+int config_pamu(struct pamu_addr_tbl *tbl, int num_entries, uint32_t liodn)
+{
+       int i = 0;
+       int ret = 0;
+       uint32_t num_sec_windows = 0;
+       uint32_t num_windows = 0;
+       uint64_t min_addr, max_addr;
+       uint64_t size;
+       uint64_t subwin_size;
+       int sizebit;
+
+       min_addr = find_min(tbl->start_addr, num_entries);
+       max_addr = find_max(tbl->end_addr, num_entries);
+       size = max_addr - min_addr + 1;
+
+       if (!size)
+               return -1;
+
+       sizebit = __ilog2_roundup_64(size);
+       size = 1 << sizebit;
+#ifdef DEBUG
+       printf("min start_addr is %llx\n", min_addr);
+       printf("max end_addr is %llx\n", max_addr);
+       printf("size found is  %llx\n", size);
+#endif
+
+       if (size < PAMU_PAGE_SIZE)
+               size = PAMU_PAGE_SIZE;
+
+       while (1) {
+               min_addr = min_addr & ~(size - 1);
+               if (min_addr + size > max_addr)
+                       break;
+               size <<= 1;
+               if (!size)
+                       return -1;
+       }
+#ifdef DEBUG
+       printf("PAACT :Base addr is %llx\n", min_addr);
+       printf("PAACT : Size is %llx\n", size);
+#endif
+       num_windows = get_win_cnt(size);
+       /* For a single window, no spaact entries are required
+        * sec_sub_window count = 0 */
+       if (num_windows > 1)
+               num_sec_windows = num_windows;
+       else
+               num_sec_windows = 0;
+
+       ret = pamu_config_ppaace(liodn, min_addr,
+                       size , -1, -1, -1, num_sec_windows);
+
+       if (ret < 0)
+               return ret;
+
+#ifdef DEBUG
+       printf("configured ppace\n");
+#endif
+
+       if (num_sec_windows) {
+               subwin_size = size >> count_lsb_zeroes(num_sec_windows);
+#ifdef DEBUG
+               printf("subwin_size is %llx\n", subwin_size);
+#endif
+
+               for (i = 0; i < num_entries; i++) {
+                       ret = pamu_config_spaace(liodn,
+                               subwin_size, tbl->start_addr[i] - min_addr,
+                               tbl->size[i], -1, -1, -1);
+
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       return ret;
+}
diff --git a/arch/powerpc/include/asm/fsl_pamu.h b/arch/powerpc/include/asm/fsl_pamu.h
new file mode 100644
index 0000000..e2cfe97
--- /dev/null
+++ b/arch/powerpc/include/asm/fsl_pamu.h
@@ -0,0 +1,193 @@
+/* Copyright (c) 2012 Freescale Semiconductor, Inc.
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Freescale Semiconductor nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __PAMU_H
+#define __PAMU_H
+
+#define CONFIG_NUM_PAMU                16
+#define NUM_PPAACT_ENTRIES     512
+#define NUM_SPAACT_ENTRIES     128
+
+/* PAMU_OFFSET to the next pamu space in ccsr */
+#define PAMU_OFFSET 0x1000
+
+#define PAMU_TABLE_ALIGNMENT 0x00001000
+
+#define PAMU_PAGE_SHIFT 12
+#define PAMU_PAGE_SIZE  4096U
+
+#define PAACE_M_COHERENCE_REQ   0x01
+
+#define PAACE_DA_HOST_CR                0x80
+#define PAACE_DA_HOST_CR_SHIFT          7
+
+#define PAACE_AF_PT                     0x00000002
+#define PAACE_AF_PT_SHIFT               1
+
+#define PAACE_PT_PRIMARY       0x0
+#define PAACE_PT_SECONDARY     0x1
+
+#define PPAACE_AF_WBAL                 0xfffff000
+#define PPAACE_AF_WBAL_SHIFT           12
+
+#define        OME_NUMBER_ENTRIES      16   /* based on P4080 2.0 silicon plan */
+
+#define PAACE_IA_CID                   0x00FF0000
+#define PAACE_IA_CID_SHIFT             16
+#define PAACE_IA_WCE                   0x000000F0
+#define PAACE_IA_WCE_SHIFT             4
+#define PAACE_IA_ATM                   0x0000000C
+#define PAACE_IA_ATM_SHIFT             2
+#define PAACE_IA_OTM                   0x00000003
+#define PAACE_IA_OTM_SHIFT             0
+
+#define PAACE_OTM_NO_XLATE      0x00
+#define PAACE_OTM_IMMEDIATE     0x01
+#define PAACE_OTM_INDEXED       0x02
+#define PAACE_OTM_RESERVED      0x03
+#define PAACE_ATM_NO_XLATE      0x00
+#define PAACE_ATM_WINDOW_XLATE  0x01
+#define PAACE_ATM_PAGE_XLATE    0x02
+#define PAACE_ATM_WIN_PG_XLATE  \
+       (PAACE_ATM_WINDOW_XLATE | PAACE_ATM_PAGE_XLATE)
+#define PAACE_WIN_TWBAL                        0xfffff000
+#define PAACE_WIN_TWBAL_SHIFT          12
+#define PAACE_WIN_SWSE                 0x00000fc0
+#define PAACE_WIN_SWSE_SHIFT           6
+
+#define PAACE_AF_AP                    0x00000018
+#define PAACE_AF_AP_SHIFT              3
+#define PAACE_AF_DD                    0x00000004
+#define PAACE_AF_DD_SHIFT              2
+#define PAACE_AF_PT                    0x00000002
+#define PAACE_AF_PT_SHIFT              1
+#define PAACE_AF_V                     0x00000001
+#define PAACE_AF_V_SHIFT               0
+#define PPAACE_AF_WSE                  0x00000fc0
+#define PPAACE_AF_WSE_SHIFT            6
+#define PPAACE_AF_MW                   0x00000020
+#define PPAACE_AF_MW_SHIFT             5
+
+#define PAACE_AP_PERMS_DENIED  0x0
+#define PAACE_AP_PERMS_QUERY   0x1
+#define PAACE_AP_PERMS_UPDATE  0x2
+#define PAACE_AP_PERMS_ALL     0x3
+
+#define SPAACE_AF_LIODN                        0xffff0000
+#define SPAACE_AF_LIODN_SHIFT          16
+#define PAACE_V_VALID          0x1
+
+#define set_bf(v, m, x)             (v = ((v) & ~(m)) | (((x) << \
+                                       (m##_SHIFT)) & (m)))
+#define get_bf(v, m)            (((v) & (m)) >> (m##_SHIFT))
+
+#define DEFAULT_NUM_SUBWINDOWS         128
+#define PAMU_PCR_OFFSET 0xc10
+#define PAMU_PCR_PE    0x40000000
+
+struct pamu_addr_tbl {
+       phys_addr_t start_addr[10];
+       phys_addr_t end_addr[10];
+       phys_size_t size[10];
+};
+
+typedef struct paace_t {
+       /* PAACE Offset 0x00 */
+       uint32_t wbah;                  /* only valid for Primary PAACE */
+       uint32_t addr_bitfields;        /* See P/S PAACE_AF_* */
+
+       /* PAACE Offset 0x08 */
+       /* Interpretation of first 32 bits dependent on DD above */
+       union {
+               struct {
+                       /* Destination ID, see PAACE_DID_* defines */
+                       uint8_t did;
+                       /* Partition ID */
+                       uint8_t pid;
+                       /* Snoop ID */
+                       uint8_t snpid;
+                       /* coherency_required : 1 reserved : 7 */
+                       uint8_t coherency_required; /* See PAACE_DA_* */
+               } to_host;
+               struct {
+                       /* Destination ID, see PAACE_DID_* defines */
+                       uint8_t  did;
+                       uint8_t  reserved1;
+                       uint16_t reserved2;
+               } to_io;
+       } domain_attr;
+
+       /* Implementation attributes + window count + address & operation
+        * translation modes
+        */
+       uint32_t impl_attr;                     /* See PAACE_IA_* */
+
+       /* PAACE Offset 0x10 */
+       /* Translated window base address */
+       uint32_t twbah;
+       uint32_t win_bitfields;                 /* See PAACE_WIN_* */
+
+       /* PAACE Offset 0x18 */
+       /* first secondary paace entry */
+       uint32_t fspi;                  /* only valid for Primary PAACE */
+       union {
+               struct {
+                       uint8_t ioea;
+                       uint8_t moea;
+                       uint8_t ioeb;
+                       uint8_t moeb;
+               } immed_ot;
+               struct {
+                       uint16_t reserved;
+                       uint16_t omi;
+               } index_ot;
+       } op_encode;
+
+       /* PAACE Offset 0x20 */
+       uint32_t reserved1[2];                  /* not currently implemented */
+
+       /* PAACE Offset 0x28 */
+       uint32_t reserved2[2];                  /* not currently implemented */
+
+       /* PAACE Offset 0x30 */
+       uint32_t reserved3[2];                  /* not currently implemented */
+
+       /* PAACE Offset 0x38 */
+       uint32_t reserved4[2];                  /* not currently implemented */
+
+} paace_t;
+
+int pamu_init(void);
+void pamu_enable(void);
+void pamu_disable(void);
+int config_pamu(struct pamu_addr_tbl *tbl, int num_entries, uint32_t liodn);
+
+#endif
diff --git a/arch/powerpc/include/asm/immap_85xx.h b/arch/powerpc/include/asm/immap_85xx.h
index 4eb3f79..17e0f39 100644
--- a/arch/powerpc/include/asm/immap_85xx.h
+++ b/arch/powerpc/include/asm/immap_85xx.h
@@ -2829,6 +2829,21 @@ typedef struct ccsr_pme {
        u8      res4[0x400];
 } ccsr_pme_t;

+typedef struct ccsr_pamu {
+       u32 ppbah;
+       u32 ppbal;
+       u32 pplah;
+       u32 pplal;
+       u32 spbah;
+       u32 spbal;
+       u32 splah;
+       u32 splal;
+       u32 obah;
+       u32 obal;
+       u32 olah;
+       u32 olal;
+} ccsr_pamu_t;
+
 typedef struct ccsr_usb_phy {
        u8      res0[0x18];
        u32     usb_enable_override;
@@ -2905,6 +2920,7 @@ struct ccsr_pman {
 #define CONFIG_SYS_FSL_CORENET_SERDES_OFFSET   0xEA000
 #define CONFIG_SYS_FSL_CORENET_SERDES2_OFFSET  0xEB000
 #define CONFIG_SYS_FSL_CPC_OFFSET              0x10000
+#define CONFIG_SYS_FSL_PAMU_OFFSET             0x20000
 #define CONFIG_SYS_MPC85xx_DMA1_OFFSET         0x100000
 #define CONFIG_SYS_MPC85xx_DMA2_OFFSET         0x101000
 #define CONFIG_SYS_MPC85xx_DMA_OFFSET          CONFIG_SYS_MPC85xx_DMA1_OFFSET
@@ -3085,6 +3101,8 @@ struct ccsr_pman {
        (CONFIG_SYS_IMMR + CONFIG_SYS_FSL_FM2_OFFSET)
 #define CONFIG_SYS_FSL_SRIO_ADDR \
        (CONFIG_SYS_IMMR + CONFIG_SYS_FSL_SRIO_OFFSET)
+#define CONFIG_SYS_PAMU_ADDR \
+       (CONFIG_SYS_IMMR + CONFIG_SYS_FSL_PAMU_OFFSET)

 #define CONFIG_SYS_PCI1_ADDR \
        (CONFIG_SYS_IMMR + CONFIG_SYS_MPC85xx_PCI1_OFFSET)
--
1.7.7.6




------------------------------

Message: 6
Date: Thu, 28 Mar 2013 16:16:35 +0530
From: Ruchika Gupta <ruchika.gupta at freescale.com>
Subject: [U-Boot] [PATCH 5/5] Added command for validation of images
        in case of secure boot
To: <u-boot at lists.denx.de>, <afleming at freescale.com>
Cc: Kuldip Giroh <kuldip.giroh at freescale.com>,  Ruchika Gupta
        <ruchika.gupta at freescale.com>
Message-ID:
        <1364467595-15539-6-git-send-email-ruchika.gupta at freescale.com>
Content-Type: text/plain

        1. Default environment will be used for secure boot flow
           which can't be edited or saved.
        2. Command for secure boot is predefined in the default
           environment which will run on autoboot (and autoboot is
           the only option allowed in case of secure boot) and it
           looks like this:
           #define CONFIG_SECBOOT \
            "setenv bs_hdraddr 0xe8e00000;"                 \
            "esbc_validate $bs_hdraddr;"                    \
            "source $img_addr;"                             \
            "esbc_halt;"
           #endif
        3. esbc_validate command is meant for validating header and
           signature of images (Boot Script and ESBC uboot client).
           SHA-256 and RSA operations are performed using SEC block in HW.
           This command works on both high-end (P4080) and
           low-end (P1010) platforms.
           Command usage:
           esbc_validate img_hdr_addr [pub_key_hash]
        4. Boot Script can contain esbc_validate commands and bootm command.
           Uboot source command used in default secure boot command will
           run the bootscript.
        5. ESBC uboot client can be linux. Additionally, rootfs and device
           tree blob can also be signed.
        6. In the event of header or signature failure in validation,
           ITS and ITF bits determine further course of action.
        7. In case of soft failure, appropriate error is dumped on console
           and next esbc_validate command is executed.
        8. In case of hard failure, SoC is issued RESET REQUEST after
           dumping error on the console.
        9. Command esbc_halt added to ensure either bootm executes
           after validation of images or core should just spin.

Signed-off-by: Kuldip Giroh <kuldip.giroh at freescale.com>
Signed-off-by: Ruchika Gupta <ruchika.gupta at freescale.com>
---
Based upon git://git.denx.de/u-boot.git branch master

 arch/powerpc/cpu/mpc85xx/Makefile            |    2 +
 arch/powerpc/cpu/mpc85xx/cmd_esbc_validate.c |   54 +++
 arch/powerpc/cpu/mpc85xx/cpu_init.c          |   17 +
 arch/powerpc/cpu/mpc85xx/fsl_sfp_snvs.c      |  163 ++++++++
 arch/powerpc/cpu/mpc85xx/fsl_validate.c      |  543 ++++++++++++++++++++++++++
 arch/powerpc/include/asm/fsl_secure_boot.h   |   68 ++++-
 arch/powerpc/include/asm/fsl_sfp_snvs.h      |   42 ++
 arch/powerpc/include/asm/immap_85xx.h        |   55 +++
 8 files changed, 943 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/cpu/mpc85xx/cmd_esbc_validate.c
 create mode 100644 arch/powerpc/cpu/mpc85xx/fsl_sfp_snvs.c
 create mode 100644 arch/powerpc/cpu/mpc85xx/fsl_validate.c
 create mode 100644 arch/powerpc/include/asm/fsl_sfp_snvs.h

diff --git a/arch/powerpc/cpu/mpc85xx/Makefile b/arch/powerpc/cpu/mpc85xx/Makefile
index 6776c85..66b7b67 100644
--- a/arch/powerpc/cpu/mpc85xx/Makefile
+++ b/arch/powerpc/cpu/mpc85xx/Makefile
@@ -109,6 +109,8 @@ COBJS-$(CONFIG_QE)  += qe_io.o
 COBJS-$(CONFIG_CPM2)   += serial_scc.o
 COBJS-$(CONFIG_SYS_FSL_QORIQ_CHASSIS1) += fsl_corenet_serdes.o
 COBJS-$(CONFIG_SYS_FSL_QORIQ_CHASSIS2) += fsl_corenet2_serdes.o
+COBJS-$(CONFIG_SECURE_BOOT) += fsl_sfp_snvs.o
+COBJS-$(CONFIG_CMD_ESBC_VALIDATE) += cmd_esbc_validate.o fsl_validate.o

 # SoC specific SERDES support
 COBJS-$(CONFIG_MPC8536) += mpc8536_serdes.o
diff --git a/arch/powerpc/cpu/mpc85xx/cmd_esbc_validate.c b/arch/powerpc/cpu/mpc85xx/cmd_esbc_validate.c
new file mode 100644
index 0000000..a95f04e
--- /dev/null
+++ b/arch/powerpc/cpu/mpc85xx/cmd_esbc_validate.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2010-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <command.h>
+#include <common.h>
+#include <asm/fsl_validate.h>
+
+static int do_esbc_validate(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       if (argc < 2)
+               return cmd_usage(cmdtp);
+
+       return fsl_secboot_validate(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+       esbc_validate,  3,      0,      do_esbc_validate,
+       "Validates signature of a given image using RSA verification"
+       "algorithm as part of Freescale Secure Boot Process",
+       "<hdr_addr> <hash_val>"
+);
+
+static int do_esbc_halt(cmd_tbl_t *cmdtp, int flag, int argc,
+                               char * const argv[])
+{
+       printf("Core is entering spin loop.\n");
+       while (1);
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       esbc_halt,      1,      0,      do_esbc_halt,
+       "Put the core in spin loop if control reaches to uboot"
+       "from bootscript",
+       ""
+);
diff --git a/arch/powerpc/cpu/mpc85xx/cpu_init.c b/arch/powerpc/cpu/mpc85xx/cpu_init.c
index de9d916..41d7bf8 100644
--- a/arch/powerpc/cpu/mpc85xx/cpu_init.c
+++ b/arch/powerpc/cpu/mpc85xx/cpu_init.c
@@ -46,6 +46,14 @@
 #include <errno.h>
 #endif

+#if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_CORENET)
+#include <asm/fsl_pamu.h>
+#endif
+#ifdef CONFIG_SECURE_BOOT
+#include <jr.h>
+#include <asm/fsl_secboot_err.h>
+#endif
+
 #include "../../../../drivers/block/fsl_sata.h"

 DECLARE_GLOBAL_DATA_PTR;
@@ -650,6 +658,15 @@ skip_l2:
        }
 #endif

+#if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_CORENET)
+       if (pamu_init() < 0)
+               fsl_secboot_handle_error(ERROR_ESBC_PAMU_INIT);
+#endif
+
+#ifdef CONFIG_SECURE_BOOT
+       if (sec_init() < 0)
+               fsl_secboot_handle_error(ERROR_ESBC_SEC_INIT);
+#endif

        return 0;
 }
diff --git a/arch/powerpc/cpu/mpc85xx/fsl_sfp_snvs.c b/arch/powerpc/cpu/mpc85xx/fsl_sfp_snvs.c
new file mode 100644
index 0000000..7382eea
--- /dev/null
+++ b/arch/powerpc/cpu/mpc85xx/fsl_sfp_snvs.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2010-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <asm/fsl_sfp_snvs.h>
+#include <configs/corenet_ds.h>
+#include <common.h>
+
+int change_sec_mon_state(u32 initial_state, u32 final_state)
+{
+       ccsr_snvs_regs_t *snvs_regs = (void *)(CONFIG_SYS_SNVS_ADDR);
+       u32 sts = in_be32(&snvs_regs->hp_stat);
+       int timeout = 10;
+
+       if ((sts & HPSR_SSM_ST_MASK) != initial_state)
+               return -1;
+
+       if (initial_state == HPSR_SSM_ST_TRUST) {
+               switch (final_state) {
+               case HPSR_SSM_ST_NON_SECURE:
+                       printf("SNVS state transitioning to Soft Fail.\n");
+                       setbits_be32(&snvs_regs->hp_com, HPCOMR_SW_SV);
+
+                       /*
+                        * poll till SNVS is in
+                        * Soft Fail state
+                        */
+                       while (((sts & HPSR_SSM_ST_MASK) !=
+                               HPSR_SSM_ST_SOFT_FAIL)) {
+                               while (timeout) {
+                                       sts = in_be32(&snvs_regs->hp_stat);
+
+                                       if ((sts & HPSR_SSM_ST_MASK) ==
+                                               HPSR_SSM_ST_SOFT_FAIL)
+                                               break;
+
+                                       udelay(10);
+                                       timeout--;
+                               }
+                       }
+
+                       if (timeout == 0) {
+                               printf("SNVS state transition timeout.\n");
+                               branch_to_self();
+                       }
+
+                       timeout = 10;
+
+                       printf("SNVS state transitioning to Non Secure.\n");
+                       setbits_be32(&snvs_regs->hp_com, HPCOMR_SSM_ST);
+
+                       /*
+                        * poll till SNVS is in
+                        * Non Secure state
+                        */
+                       while (((sts & HPSR_SSM_ST_MASK) !=
+                               HPSR_SSM_ST_NON_SECURE)) {
+                               while (timeout) {
+                                       sts = in_be32(&snvs_regs->hp_stat);
+
+                                       if ((sts & HPSR_SSM_ST_MASK) ==
+                                               HPSR_SSM_ST_NON_SECURE)
+                                               break;
+
+                                       udelay(10);
+                                       timeout--;
+                               }
+                       }
+
+                       if (timeout == 0) {
+                               printf("SNVS state transition timeout.\n");
+                               branch_to_self();
+                       }
+                       break;
+               case HPSR_SSM_ST_SOFT_FAIL:
+                       printf("SNVS state transitioning to Soft Fail.\n");
+                       setbits_be32(&snvs_regs->hp_com, HPCOMR_SW_FSV);
+
+                       /*
+                        * polling loop till SNVS is in
+                        * Soft Fail state
+                        */
+                       while (((sts & HPSR_SSM_ST_MASK) !=
+                               HPSR_SSM_ST_SOFT_FAIL)) {
+                               while (timeout) {
+                                       sts = in_be32(&snvs_regs->hp_stat);
+
+                                       if ((sts & HPSR_SSM_ST_MASK) ==
+                                               HPSR_SSM_ST_SOFT_FAIL)
+                                               break;
+
+                                       udelay(10);
+                                       timeout--;
+                               }
+                       }
+
+                       if (timeout == 0) {
+                               printf("SNVS state transition timeout.\n");
+                               branch_to_self();
+                       }
+                       break;
+               default:
+                       return -1;
+               }
+       } else if (initial_state == HPSR_SSM_ST_NON_SECURE) {
+               switch (final_state) {
+               case HPSR_SSM_ST_SOFT_FAIL:
+                       printf("SNVS state transitioning to Soft Fail.\n");
+                       setbits_be32(&snvs_regs->hp_com, HPCOMR_SW_FSV);
+
+                       /*
+                        * polling loop till SNVS is in
+                        * Soft Fail state
+                        */
+                       while (((sts & HPSR_SSM_ST_MASK) !=
+                               HPSR_SSM_ST_SOFT_FAIL)) {
+                               while (timeout) {
+                                       sts = in_be32(&snvs_regs->hp_stat);
+
+                                       if ((sts & HPSR_SSM_ST_MASK) ==
+                                               HPSR_SSM_ST_SOFT_FAIL)
+                                               break;
+
+                                       udelay(10);
+                                       timeout--;
+                               }
+                       }
+
+                       if (timeout == 0) {
+                               printf("SNVS state transition timeout.\n");
+                               branch_to_self();
+                       }
+                       break;
+               default:
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+void generate_reset_req(void)
+{
+       ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+       printf("Generating reset request");
+       out_be32(&gur->rstcr, 0x2);     /* HRESET_REQ */
+       branch_to_self();
+}
diff --git a/arch/powerpc/cpu/mpc85xx/fsl_validate.c b/arch/powerpc/cpu/mpc85xx/fsl_validate.c
new file mode 100644
index 0000000..a184933
--- /dev/null
+++ b/arch/powerpc/cpu/mpc85xx/fsl_validate.c
@@ -0,0 +1,543 @@
+/*
+ * Copyright 2010-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <asm/fsl_validate.h>
+#include <asm/fsl_secboot_err.h>
+#include <asm/fsl_sfp_snvs.h>
+#include <command.h>
+#include <common.h>
+#include <malloc.h>
+#include <rsa_sec.h>
+#include <sha.h>
+#include <jr.h>
+#include <asm/fsl_pamu.h>
+
+#define SHA256_BITS    256
+#define SHA256_BYTES   (256/8)
+#define SHA256_NIBBLES (256/4)
+#define NUM_HEX_CHARS  (sizeof(ulong) * 2)
+
+
+/* This array contains DER value for SHA-256 */
+static const u8 hash_identifier[] = { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60,
+               0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00,
+               0x04, 0x20
+               };
+
+static u8 hash_val[SHA256_BYTES];
+static const u8 barker_code[ESBC_BARKER_LEN] = { 0x68, 0x39, 0x27, 0x81 };
+
+void branch_to_self(void) __attribute__ ((noreturn));
+
+/*
+ * This function will put core in infinite loop.
+ * This will be called when the ESBC can not proceed further due
+ * to some errors.
+ */
+void branch_to_self(void)
+{
+       printf("Core is in infinite loop due to errors.\n");
+       while (1);
+}
+
+/*
+ * Handles the ESBC uboot client header verification failure.
+ * This  function  handles all the errors which might occur in the
+ * parsing and checking of ESBC uboot client header. It will also
+ * set the error bits in the SNVS.
+ */
+static void fsl_secboot_header_verification_failure(void)
+{
+       ccsr_snvs_regs_t *snvs_regs = (void *)(CONFIG_SYS_SNVS_ADDR);
+       ccsr_sfp_regs_t *sfp_regs = (void *)(CONFIG_SYS_SFP_ADDR);
+       u32 sts = in_be32(&snvs_regs->hp_stat);
+
+       /* 29th bit of OSPR is ITS */
+       u32 its = in_be32(&sfp_regs->ospr) >> 2;
+
+       /*
+        * Read the SNVS status register
+        * Read SSM_ST field
+        */
+       sts = in_be32(&snvs_regs->hp_stat);
+       if ((sts & HPSR_SSM_ST_MASK) == HPSR_SSM_ST_TRUST) {
+               if (its == 1)
+                       change_sec_mon_state(HPSR_SSM_ST_TRUST,
+                               HPSR_SSM_ST_SOFT_FAIL);
+               else
+                       change_sec_mon_state(HPSR_SSM_ST_TRUST,
+                               HPSR_SSM_ST_NON_SECURE);
+       }
+
+       generate_reset_req();
+}
+
+/*
+ * Handles the ESBC uboot client image verification failure.
+ * This  function  handles all the errors which might occur in the
+ * public key hash comparison and signature verification of
+ * ESBC uboot client image. It will also
+ * set the error bits in the SNVS.
+ */
+static void fsl_secboot_image_verification_failure(void)
+{
+       ccsr_snvs_regs_t *snvs_regs = (void *)(CONFIG_SYS_SNVS_ADDR);
+       ccsr_sfp_regs_t *sfp_regs = (void *)(CONFIG_SYS_SFP_ADDR);
+       u32 sts = in_be32(&snvs_regs->hp_stat);
+
+       /* 31st bit of OVPR is ITF */
+       u32 itf = in_be32(&sfp_regs->ovpr) & ITS_MASK >> ITS_BIT;
+
+       /*
+        * Read the SNVS status register
+        * Read SSM_ST field
+        */
+       sts = in_be32(&snvs_regs->hp_stat);
+       if ((sts & HPSR_SSM_ST_MASK) == HPSR_SSM_ST_TRUST) {
+               if (itf == 1) {
+                       change_sec_mon_state(HPSR_SSM_ST_TRUST,
+                               HPSR_SSM_ST_SOFT_FAIL);
+
+                       generate_reset_req();
+               } else {
+                       change_sec_mon_state(HPSR_SSM_ST_TRUST,
+                               HPSR_SSM_ST_NON_SECURE);
+               }
+       }
+}
+
+static void fsl_secboot_bootscript_parse_failure(void)
+{
+       fsl_secboot_header_verification_failure();
+}
+
+/*
+ * Handles the errors in esbc boot.
+ * This  function  handles all the errors which might occur in the
+ * esbc boot phase. It will call the appropriate api to log the
+ * errors and set the error bits in the SNVS.
+ */
+void fsl_secboot_handle_error(int error)
+{
+       const struct fsl_secboot_errcode *e;
+
+       for (e = fsl_secboot_errcodes; e->errcode != ERROR_ESBC_CLIENT_MAX;
+               e++) {
+               if (e->errcode == error)
+                       printf("ERROR :: %x :: %s\n", error, e->name);
+       }
+
+       switch (error) {
+       case ERROR_ESBC_CLIENT_HEADER_BARKER:
+       case ERROR_ESBC_CLIENT_HEADER_IMG_SIZE:
+       case ERROR_ESBC_CLIENT_HEADER_KEY_LEN:
+       case ERROR_ESBC_CLIENT_HEADER_SIG_LEN:
+       case ERROR_ESBC_CLIENT_HEADER_KEY_LEN_NOT_TWICE_SIG_LEN:
+       case ERROR_ESBC_CLIENT_HEADER_KEY_MOD_1:
+       case ERROR_ESBC_CLIENT_HEADER_KEY_MOD_2:
+       case ERROR_ESBC_CLIENT_HEADER_SIG_KEY_MOD:
+       case ERROR_ESBC_CLIENT_HEADER_SG_ESBC_EP:
+       case ERROR_ESBC_CLIENT_HEADER_SG_ENTIRES_BAD:
+               fsl_secboot_header_verification_failure();
+               break;
+       case ERROR_ESBC_SEC_RESET:
+       case ERROR_ESBC_SEC_DEQ:
+       case ERROR_ESBC_SEC_ENQ:
+       case ERROR_ESBC_SEC_DEQ_TO:
+       case ERROR_ESBC_SEC_JOBQ_STATUS:
+       case ERROR_ESBC_CLIENT_HASH_COMPARE_KEY:
+       case ERROR_ESBC_CLIENT_HASH_COMPARE_EM:
+               fsl_secboot_image_verification_failure();
+               break;
+       case ERROR_ESBC_MISSING_BOOTM:
+               fsl_secboot_bootscript_parse_failure();
+               break;
+       case ERROR_ESBC_WRONG_CMD:
+       default:
+               branch_to_self();
+               break;
+       }
+}
+
+static void fsl_secblk_handle_error(int error)
+{
+       switch (error) {
+       case JQ_ENQ_ERR:
+               fsl_secboot_handle_error(ERROR_ESBC_SEC_ENQ);
+               break;
+       case JQ_DEQ_ERR:
+               fsl_secboot_handle_error(ERROR_ESBC_SEC_DEQ);
+               break;
+       case JQ_DEQ_TO_ERR:
+                fsl_secboot_handle_error(ERROR_ESBC_SEC_DEQ_TO);
+               break;
+       default:
+               printf("Job Queue Output status %x\n", error);
+               fsl_secboot_handle_error(ERROR_ESBC_SEC_JOBQ_STATUS);
+               break;
+       }
+}
+
+/*
+ * Calculate hash of key obtained via offset present in ESBC uboot
+ * client hdr. This function calculates the hash of key which is obtained
+ * through offset present in ESBC uboot client header.
+ */
+static int calc_img_key_hash(struct sha_ctx *ctx,
+                               struct fsl_secboot_img_priv *img)
+{
+       int i;
+       int ret = 0;
+
+       /* calc hash of the esbc key */
+       sha_init(ctx);
+       sha_update(ctx, img->img_key, img->hdr.key_len);
+       ret = sha_final(ctx);
+       if (ret)
+               return ret;
+
+       ret = sha_digest(ctx, hash_val);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < SHA256_BYTES; i++)
+               img->img_key_hash[i] = hash_val[i];
+
+       return 0;
+}
+
+/*
+ * Calculate hash of ESBC hdr and ESBC. This function calculates the
+ * single hash of ESBC header and ESBC image. If SG flag is on, all
+ * SG entries are also hashed alongwith the complete SG table.
+ */
+static int calc_esbchdr_esbc_hash(struct sha_ctx *ctx,
+       struct fsl_secboot_img_priv *img)
+{
+       int i = 0;
+       int ret = 0;
+
+       /* calculate the hash of the CSF header */
+       sha_init(ctx);
+       sha_update(ctx, (u8 *) &img->hdr,
+               sizeof(struct fsl_secboot_img_hdr));
+       sha_update(ctx, img->img_key, img->hdr.key_len);
+
+       if (img->hdr.sg_flag) {
+               /* calculate hash of the SG table */
+               sha_update(ctx, (u8 *) &img->sgtbl,
+                       img->hdr.sg_entries *
+                       sizeof(struct fsl_secboot_sg_table));
+
+               /* calculate the hash of each entry in the table */
+               for (i = 0; i < img->hdr.sg_entries; i++)
+                       sha_update(ctx, img->sgtbl[i].pdata,
+                               img->sgtbl[i].len);
+       } else {
+               /* contiguous ESBC */
+               sha_update(ctx, (u8 *) img->hdr.pimg,
+                       img->hdr.img_size);
+       }
+
+       ret = sha_final(ctx);
+       if (ret)
+               return ret;
+
+       ret = sha_digest(ctx, hash_val);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+/*
+ * Construct encoded hash EM' wrt PKCSv1.5. This function calculates the
+ * pointers for padding, DER value and hash. And finally, constructs EM'
+ * which includes hash of complete CSF header and ESBC image. If SG flag
+ * is on, hash of SG table and entries is also included.
+ */
+static void construct_img_encoded_hash_second(struct fsl_secboot_img_priv *img)
+{
+       /*
+        * RSA PKCSv1.5 encoding format for encoded message is below
+        * EM = 0x0 || 0x1 || PS || 0x0 || DER || Hash
+        * PS is Padding String
+        * DER is DER value for SHA-256
+        * Hash is SHA-256 hash
+        * *********************************************************
+        * representative points to first byte of EM initially and is
+        * filled with 0x0
+        * representative is incremented by 1 and second byte is filled
+        * with 0x1
+        * padding points to third byte of EM
+        * digest points to full length of EM - 32 bytes
+        * hash_id (DER value) points to 19 bytes before pDigest
+        * separator is one byte which separates padding and DER
+        */
+
+       size_t len;
+       u8 *representative;
+       u8 *padding, *digest;
+       u8 *hash_id, *separator;
+       int i;
+
+       len = (img->hdr.key_len / 2) - 1;
+       representative = img->img_encoded_hash_second;
+       representative[0] = 0;
+       representative[1] = 1;  /* block type 1 */
+
+       padding = &representative[2];
+       digest = &representative[1] + len - 32;
+       hash_id = digest - sizeof(hash_identifier);
+       separator = hash_id - 1;
+
+       /* fill padding area pointed by padding with 0xff */
+       memset(padding, 0xff, separator - padding);
+
+       /* fill byte pointed by separator */
+       *separator = 0;
+
+       /* fill SHA-256 DER value  pointed by HashId */
+       memcpy(hash_id, hash_identifier, sizeof(hash_identifier));
+
+       /* fill hash pointed by Digest */
+       for (i = 0; i < SHA256_BYTES; i++)
+               digest[i] = hash_val[i];
+}
+
+/*
+ * Reads and validates the ESBC client header.
+ * This function reads key and signature from the ESBC client header.
+ * If Scatter/Gather flag is on, lengths and offsets of images
+ * present as SG entries are also read. This function also checks
+ * whether the header is valid or not.
+ */
+static int read_validate_esbc_client_header(struct fsl_secboot_img_priv *img)
+{
+       char buf[20];
+       struct fsl_secboot_img_hdr *hdr = &img->hdr;
+       void *esbc = (u8 *) img->ehdrloc;
+       u8 *k, *s;
+
+       /* check barker code */
+       if (memcmp(hdr->barker, barker_code, ESBC_BARKER_LEN))
+               return ERROR_ESBC_CLIENT_HEADER_BARKER;
+
+       sprintf(buf, "%p", hdr->pimg);
+       setenv("img_addr", buf);
+
+       if (!hdr->img_size)
+               return ERROR_ESBC_CLIENT_HEADER_IMG_SIZE;
+
+       /* key length should be twice of signature length */
+       if (hdr->key_len == 2 * hdr->sign_len) {
+               /* check key length */
+               if (!((hdr->key_len == 2 * KEY_SIZE_BYTES / 4) ||
+                       (hdr->key_len == 2 * KEY_SIZE_BYTES / 2) ||
+                       (hdr->key_len == 2 * KEY_SIZE_BYTES)))
+                       return ERROR_ESBC_CLIENT_HEADER_KEY_LEN;
+
+               /* check signature length */
+               if (!((hdr->sign_len == KEY_SIZE_BYTES / 4) ||
+                       (hdr->sign_len == KEY_SIZE_BYTES / 2) ||
+                       (hdr->sign_len == KEY_SIZE_BYTES)))
+                       return ERROR_ESBC_CLIENT_HEADER_SIG_LEN;
+       } else {
+               return ERROR_ESBC_CLIENT_HEADER_KEY_LEN_NOT_TWICE_SIG_LEN;
+       }
+
+       memcpy(&img->img_key, esbc + hdr->pkey, hdr->key_len);
+       memcpy(&img->img_sign, esbc + hdr->psign, hdr->sign_len);
+
+       /* No SG support */
+       if (hdr->sg_flag)
+               return ERROR_ESBC_CLIENT_HEADER_SG;
+
+       /* modulus most significant bit should be set */
+       k = (u8 *) &img->img_key;
+
+       if ((k[0] & 0x80) == 0)
+               return ERROR_ESBC_CLIENT_HEADER_KEY_MOD_1;
+
+       /* modulus value should be odd */
+       if ((k[hdr->key_len / 2 - 1] & 0x1) == 0)
+               return ERROR_ESBC_CLIENT_HEADER_KEY_MOD_2;
+
+       /* Check signature value < modulus value */
+       s = (u8 *) &img->img_sign;
+
+       if (!(memcmp(s, k, hdr->sign_len) < 0))
+               return ERROR_ESBC_CLIENT_HEADER_SIG_KEY_MOD;
+
+       return ESBC_VALID_HDR;
+}
+
+static inline int str2long(const char *p, ulong *num)
+{
+       char *endptr;
+
+       if (!p)
+               return 0;
+       else
+               *num = simple_strtoul(p, &endptr, 16);
+
+       return *p != '\0' && *endptr == '\0';
+}
+
+int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc,
+               char * const argv[])
+{
+       int hash_srk = 1;
+       ccsr_sfp_regs_t *sfp_regs = (void *)(CONFIG_SYS_SFP_ADDR);
+       ulong hash[SHA256_BYTES/sizeof(ulong)];
+       char hash_str[NUM_HEX_CHARS + 1];
+       struct sha_ctx ctx;
+       struct rsa_context rsa_ctx;
+       ulong addr = simple_strtoul(argv[1], NULL, 16);
+       struct fsl_secboot_img_priv *img;
+       struct fsl_secboot_img_hdr *hdr;
+       void *esbc;
+       int ret, i;
+       u32 srk_hash[8];
+
+       if (argc == 3) {
+               char *cp = argv[2];
+               int i = 0;
+
+               if (*cp == '0' && *(cp + 1) == 'x')
+                       cp += 2;
+
+               /* The input string expected is in hex, where
+                * each 4 bits would be represented by a hex
+                * sha256 hash is 256 bits long, which would mean
+                * num of characters = 256 / 4
+                */
+               if (strlen(cp) != SHA256_NIBBLES) {
+                       printf("%s is not a 256 bits hex string as expected\n",
+                               argv[2]);
+                       return -1;
+               }
+
+               for (i = 0; i < sizeof(hash)/sizeof(ulong); i++) {
+                       strncpy(hash_str, cp + (i * NUM_HEX_CHARS),
+                               NUM_HEX_CHARS);
+                       hash_str[NUM_HEX_CHARS] = '\0';
+                       if (!str2long(hash_str, &hash[i])) {
+                               printf("%s is not a 256 bits hex string "
+                                       "as expected\n", argv[2]);
+                               return -1;
+                       }
+               }
+
+               hash_srk = 0;
+       }
+
+#ifdef CONFIG_FSL_CORENET
+       pamu_enable();
+#endif
+       img = malloc(sizeof(struct fsl_secboot_img_priv));
+
+       if (!img)
+               return -1;
+
+       memset(img, 0, sizeof(struct fsl_secboot_img_priv));
+
+       hdr = &img->hdr;
+       img->ehdrloc = addr;
+       esbc = (u8 *) img->ehdrloc;
+
+       memcpy(hdr, esbc, sizeof(struct fsl_secboot_img_hdr));
+
+       /* read and validate esbc header */
+       ret = read_validate_esbc_client_header(img);
+
+       if (ret != ESBC_VALID_HDR) {
+               fsl_secboot_handle_error(ret);
+               goto exit1;
+               return 0;
+       }
+
+       /* SRKH present in SFP */
+       for (i = 0; i < NUM_SRKH_REGS; i++)
+               srk_hash[i] = in_be32(&sfp_regs->srk_hash[i]);
+
+       /*
+        * Calculate hash of key obtained via offset present in
+        * ESBC uboot client hdr
+        */
+       ret = calc_img_key_hash(&ctx, img);
+       if (ret) {
+               fsl_secblk_handle_error(ret);
+               goto exit;
+       }
+
+       /* Compare hash obtained above with SRK hash present in SFP */
+       if (hash_srk)
+               ret = memcmp(srk_hash, img->img_key_hash, SHA256_BYTES);
+       else
+               ret = memcmp(&hash, &img->img_key_hash, SHA256_BYTES);
+
+       if (ret != 0) {
+               fsl_secboot_handle_error(ERROR_ESBC_CLIENT_HASH_COMPARE_KEY);
+               goto exit;
+       }
+
+       ret = calc_esbchdr_esbc_hash(&ctx, img);
+       if (ret) {
+               fsl_secblk_handle_error(ret);
+               goto exit;
+       }
+
+       /* Construct encoded hash EM' wrt PKCSv1.5 */
+       construct_img_encoded_hash_second(img);
+
+       ret = rsa_public_verif_sec(img->img_sign, img->img_encoded_hash,
+               img->img_key, img->hdr.key_len / 2, &rsa_ctx);
+       if (ret) {
+               fsl_secblk_handle_error(ret);
+               goto exit;
+       }
+
+       /*
+        * compare the encoded messages EM' and EM wrt RSA PKCSv1.5
+        * memcmp returns zero on success
+        * memcmp returns non-zero on failure
+        */
+       ret = memcmp(&img->img_encoded_hash_second, &img->img_encoded_hash,
+               img->hdr.sign_len);
+
+       if (ret) {
+               fsl_secboot_handle_error(ERROR_ESBC_CLIENT_HASH_COMPARE_EM);
+               goto exit;
+       }
+
+       printf("esbc_validate command successful\n");
+
+exit:
+       if (jr_reset() < 0) {
+               fsl_secboot_handle_error(ERROR_ESBC_SEC_RESET);
+               return 0;
+       }
+exit1:
+#ifdef CONFIG_FSL_CORENET
+       pamu_disable();
+#endif
+
+       return 0;
+}
diff --git a/arch/powerpc/include/asm/fsl_secure_boot.h b/arch/powerpc/include/asm/fsl_secure_boot.h
index d1c1967..6847362 100644
--- a/arch/powerpc/include/asm/fsl_secure_boot.h
+++ b/arch/powerpc/include/asm/fsl_secure_boot.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2010-2011 Freescale Semiconductor, Inc.
+ * Copyright 2010-2012 Freescale Semiconductor, Inc.
  *
  * See file CREDITS for list of people who contributed to this
  * project.
@@ -40,4 +40,70 @@
 #endif
 #define CONFIG_SYS_PBI_FLASH_WINDOW            0xcff80000

+/*
+ * Define the key hash for boot script here if public/private key pair used to
+ * sign bootscript are different from the SRK hash put in the fuse
+ * Example of defining KEY_HASH is
+ * #define CONFIG_BOOTSCRIPT_KEY_HASH \
+ *      "41066b564c6ffcef40ccbc1e0a5d0d519604000c785d97bbefd25e4d288d1c8b"
+ */
+
+#define CONFIG_CMD_ESBC_VALIDATE
+
+#if defined(CONFIG_FSL_CORENET)
+#define CONFIG_BOOTSCRIPT_HDR_ADDR     0xe8e00000
+#else
+#define CONFIG_BOOTSCRIPT_HDR_ADDR     0xee020000
+#endif
+
+/*
+ * Control should not reach back to uboot after validation of images
+ * for secure boot flow and therefore bootscript should have
+ * the bootm command. If control reaches back to uboot anyhow
+ * after validating images, core should just spin.
+ */
+#ifdef CONFIG_BOOTSCRIPT_KEY_HASH
+#define CONFIG_SECBOOT \
+       "setenv bs_hdraddr " __stringify(CONFIG_BOOTSCRIPT_HDR_ADDR)";"    \
+       "esbc_validate $bs_hdraddr " __stringify(CONFIG_BOOTSCRIPT_KEY_HASH)";"\
+       "source $img_addr;"                                     \
+       "esbc_halt;"
+#else
+#define CONFIG_SECBOOT \
+       "setenv bs_hdraddr " __stringify(CONFIG_BOOTSCRIPT_HDR_ADDR)";"  \
+       "esbc_validate $bs_hdraddr;"                    \
+       "source $img_addr;"                             \
+       "esbc_halt;"
+#endif
+
+/* For secure boot flow, default environment used will be used */
+#if defined(CONFIG_SYS_RAMBOOT)
+#if defined(CONFIG_RAMBOOT_SPIFLASH)
+#undef CONFIG_ENV_IS_IN_SPI_FLASH
+#elif defined(CONFIG_NAND)
+#undef CONFIG_ENV_IS_IN_NAND
+#endif
+#else /*CONFIG_SYS_RAMBOOT*/
+#undef CONFIG_ENV_IS_IN_FLASH
+#endif
+
+#define CONFIG_ENV_IS_NOWHERE
+
+/*
+ * We don't want boot delay for secure boot flow
+ * before autoboot starts
+ */
+#undef CONFIG_BOOTDELAY
+#define CONFIG_BOOTDELAY       0
+#undef CONFIG_BOOTCOMMAND
+#define CONFIG_BOOTCOMMAND             CONFIG_SECBOOT
+
+/*
+ * CONFIG_ZERO_BOOTDELAY_CHECK should not be defined for
+ * secure boot flow as defining this would enable a user to
+ * reach uboot prompt by pressing some key before start of
+ * autoboot
+ */
+#undef CONFIG_ZERO_BOOTDELAY_CHECK
+
 #endif
diff --git a/arch/powerpc/include/asm/fsl_sfp_snvs.h b/arch/powerpc/include/asm/fsl_sfp_snvs.h
new file mode 100644
index 0000000..c215359
--- /dev/null
+++ b/arch/powerpc/include/asm/fsl_sfp_snvs.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _FSL_SFP_SNVS_
+#define _FSL_SFP_SNVS_
+
+#include <common.h>
+
+/* Number of SRKH registers */
+#define NUM_SRKH_REGS  8
+
+/*
+ * SNVS read. This specifies the possible reads
+ * from the SNVS
+ */
+enum {
+       SNVS_SSM_ST,
+       SNVS_SW_FSV,
+       SNVS_SW_SV,
+};
+
+void branch_to_self(void);
+int change_sec_mon_state(uint32_t initial_state, uint32_t final_state);
+void generate_reset_req(void);
+
+#endif
diff --git a/arch/powerpc/include/asm/immap_85xx.h b/arch/powerpc/include/asm/immap_85xx.h
index ac8f608..38f8b59 100644
--- a/arch/powerpc/include/asm/immap_85xx.h
+++ b/arch/powerpc/include/asm/immap_85xx.h
@@ -2949,6 +2949,48 @@ struct ccsr_pman {
        u8      res_f4[0xf0c];
 };
 #endif
+#ifdef CONFIG_SFP_v3_0
+typedef struct ccsr_sfp_regs {
+       u32 ospr;               /* 0x200 */
+       u32 reserved0[14];
+       u32 srk_hash[8];        /* 0x23c Super Root Key Hash */
+       u32 oem_uid;            /* 0x9c OEM Unique ID */
+       u8 reserved2[0x04];
+       u32 ovpr;                       /* 0xA4  Intent To Secure */
+       u8 reserved4[0x08];
+       u32 fsl_uid;            /* 0xB0  FSL Unique ID */
+} ccsr_sfp_regs_t;
+#else
+typedef struct ccsr_sfp_regs {
+       u8 reserved0[0x40];
+       u32 ospr;       /* 0x40  OEM Security Policy Register */
+       u8 reserved2[0x38];
+       u32 srk_hash[8];        /* 0x7c  Super Root Key Hash */
+       u32 oem_uid;    /* 0x9c  OEM Unique ID */
+       u8 reserved4[0x4];
+       u32 ovpr;       /* 0xA4  OEM Validation Policy Register */
+       u8 reserved8[0x8];
+       u32 fsl_uid;    /* 0xB0  FSL Unique ID */
+} ccsr_sfp_regs_t;
+#endif
+#define ITS_MASK       0x00000004
+#define ITS_BIT                2
+
+typedef struct ccsr_snvs_regs {
+       u8 reserved0[0x04];
+       u32 hp_com;     /* 0x04 SNVS_HP Command Register */
+       u8 reserved2[0x0c];
+       u32 hp_stat;    /* 0x08 SNVS_HP Status Register */
+} ccsr_snvs_regs_t;
+
+#define HPCOMR_SW_SV 0x100             /* Security Violation bit */
+#define HPCOMR_SW_FSV 0x200            /* Fatal Security Violation bit */
+#define HPCOMR_SSM_ST 0x1              /* SSM_ST field in SNVS command reg */
+#define HPSR_SSM_ST_CHECK      0x900   /* SNVS is in check state */
+#define HPSR_SSM_ST_NON_SECURE 0xb00   /* SNVS is in non secure state */
+#define HPSR_SSM_ST_TRUST      0xd00   /* SNVS is in trusted state */
+#define HPSR_SSM_ST_SOFT_FAIL  0x300   /* SNVS is in soft fail state */
+#define HPSR_SSM_ST_MASK       0xf00   /* Mask for SSM_ST field */

 #ifdef CONFIG_FSL_CORENET
 #define CONFIG_SYS_FSL_CORENET_CCM_OFFSET      0x0000
@@ -2962,6 +3004,14 @@ struct ccsr_pman {
 #define CONFIG_SYS_MPC8xxx_DDR3_OFFSET         0xA000
 #define CONFIG_SYS_FSL_CORENET_CLK_OFFSET      0xE1000
 #define CONFIG_SYS_FSL_CORENET_RCPM_OFFSET     0xE2000
+#ifdef CONFIG_SFP_v3_0
+/* In SFPv3, OSPR register is now at offset 0x200.
+ * So directly mapping sfp register map to this address */
+#define CONFIG_SYS_OSPR_OFFSET                 0x200
+#define CONFIG_SYS_SFP_OFFSET           (0xE8000 + CONFIG_SYS_OSPR_OFFSET)
+#else
+#define CONFIG_SYS_SFP_OFFSET                  0xE8000
+#endif
 #define CONFIG_SYS_FSL_CORENET_SERDES_OFFSET   0xEA000
 #define CONFIG_SYS_FSL_CORENET_SERDES2_OFFSET  0xEB000
 #define CONFIG_SYS_FSL_CPC_OFFSET              0x10000
@@ -3163,6 +3213,11 @@ struct ccsr_pman {
 #define CONFIG_SYS_PCIE4_ADDR \
        (CONFIG_SYS_IMMR + CONFIG_SYS_MPC85xx_PCIE4_OFFSET)

+#define CONFIG_SYS_SFP_ADDR  \
+       (CONFIG_SYS_IMMR + CONFIG_SYS_SFP_OFFSET)
+#define CONFIG_SYS_SNVS_ADDR  \
+       (CONFIG_SYS_IMMR + CONFIG_SYS_SNVS_OFFSET)
+
 #define TSEC_BASE_ADDR         (CONFIG_SYS_IMMR + CONFIG_SYS_TSEC1_OFFSET)
 #define MDIO_BASE_ADDR         (CONFIG_SYS_IMMR + CONFIG_SYS_MDIO1_OFFSET)

--
1.7.7.6




------------------------------

Message: 7
Date: Thu, 28 Mar 2013 12:15:08 +0100
From: Albert ARIBAUD <albert.u.boot at aribaud.net>
Subject: Re: [U-Boot] [PATCH V2] ARM: bcm2835: fix get_timer() to
        return ms
To: Stephen Warren <swarren at wwwdotorg.org>
Cc: u-boot at lists.denx.de
Message-ID: <20130328121508.34cb49f4 at lilith>
Content-Type: text/plain; charset=US-ASCII

Hi Stephen,

On Wed, 27 Mar 2013 22:43:23 -0600, Stephen Warren
<swarren at wwwdotorg.org> wrote:

> Apparently, CONFIG_SYS_HZ must be 1000. Change this, and fix the timer
> driver to conform to this.
>
> Have the timer implementation export a custom API get_timer_us() for use
> by the BCM2835 MMC API, which needs us resolution for a HW workaround.
>
> Signed-off-by: Stephen Warren <swarren at wwwdotorg.org>
> ---
> v2: Export custom API get_timer_us() to allow the MMC driver to maintain
>     its current workaround implementation.
> ---

This patch and "mmc: bcm2835: fix delays in bug workaround" cannot be
both applied together. Can you do a V2 for the delays fix patch too?

Amicalement,
--
Albert.


------------------------------

Message: 8
Date: Thu, 28 Mar 2013 17:19:15 +0530 (IST)
From: nandakumar.ramaswamy at pricoltech.com
Subject: Re: [U-Boot] Splash Screen Enable in
        (u-boot-2013.01.01.tar.bz2) U-boot source code.
To: "Anatolij Gustschin" <agust at denx.de>
Cc: u-boot at lists.denx.de
Message-ID: <1364471355.594629270 at apps.rackspace.com>
Content-Type: text/plain; charset="utf-8"


Hello,

1) Please share me, if any one used mx53loco - LVDS settings for hannstar (mcimx-lvds1) display as per the below,

setenv bootargs_base 'setenv bootargs console=ttymxc0,115200 console=tty1 video=mxcdi1fb:RGB666,TOSHIBA-XGA di1_primary ldb=single,di=1,ch1_map=SPWG'

2) And I have modified the below files and codes for splash screen support for mx53loco as per the mx6qsabrelite.c. Please correct me, if I wrong.

File Name: mx53loco.h

Included:
#define CONFIG_SPLASH_SCREEN
#define CONFIG_SPLASH_SCREEN_ALIGN
#define CONFIG_SPLASH_SCREEN_LVDS
#define CONFIG_CMD_BMP

File Name: mx53loco_video.c

Include:
static struct fb_videomode const mcimx_lvds1 = {
 .name        = "Hannstar-XGA",
 .refresh    = 60,
 .xres        = 1024,
 .yres        = 768,
 .pixclock    = 15385,
 .left_margin    = 220,
 .right_margin    = 40,
 .upper_margin    = 21,
 .lower_margin    = 7,
 .hsync_len    = 60,
 .vsync_len    = 10,
 .sync        = 4,
};

int board_video_skip(void)
{
 int ret;
 char const *e = getenv("panel");

 printf("Display Panel Name: %s\n", e);

 if (e) {
 if (strcmp(e, "seiko") == 0) {
 ret = ipuv3_fb_init(&seiko_wvga, 0, IPU_PIX_FMT_RGB24);
 if (ret)
 printf("Seiko cannot be configured: %d\n", ret);
 return ret;
 }
 else if (strcmp(e, "Hannstar-XGA") == 0) {
 ret = ipuv3_fb_init(&mcimx_lvds1, 0, IPU_PIX_FMT_LVDS666);
 if (ret)
 printf("MCIMX_LVDS1 cannot be configured: %d\n", ret);
 return ret;
 }
 }

 /*
 * 'panel' env variable not found or has different value than 'seiko'
 *  Defaulting to claa lcd.
 */
 ret = ipuv3_fb_init(&claa_wvga, 0, IPU_PIX_FMT_RGB565);
 if (ret)
 printf("CLAA cannot be configured: %d\n", ret);
 return ret;
}

And I tried the below command. But not get the correct output (SPLASH Image) through U-Boot.

MX53LOCO U-Boot > tftp 100000 /tftpboot/lvds.bmp
Using FEC device
TFTP from server 192.168.1.176; our IP address is 192.168.1.189
Filename '/tftpboot/lvds.bmp'.
Load address: 0x100000
Loading: T T T T T

Please give your suggestion and solution ASAP.

Note: I am trying to display from SD-card.

Thanks & Regards,
Nandakumar R.


-----Original Message-----
From: "Anatolij Gustschin" <agust at denx.de>
Sent: Tuesday, 26 March, 2013 13:00
To: nandakumar.ramaswamy at pricoltech.com
Cc: "Jens Scharsig" <esw at bus-elektronik.de>, u-boot at lists.denx.de
Subject: Re: [U-Boot] Splash Screen Enable in (u-boot-2013.01.01.tar.bz2) U-boot source code.



Hello,

On Tue, 26 Mar 2013 11:46:10 +0530 (IST)
nandakumar.ramaswamy at pricoltech.com wrote:
...
> Actually I tried with U-Boot latest release (u-boot-2013.01.01.tar.bz2)
> also.But I am not able to see the SPLASH SCREEN.
> So, please share the SPLASH SCREEN image enable procedure for latest
> U-boot (u-boot-2013.01.01.tar.bz2) source code for i.mx53loco.

U-Boot release 2013.01.01 for mx53loco supports two LCD panels,
CLAA07LC0ACW and Seiko-43WVF1G. If you have a different panel, you
will have to add support for it. If you have Seiko panel, please set
up environment variable panel as follows:

=> setenv panel seiko
=> saveenv

and reboot, then use load a bmp file and use "bmp" command to display
it.

Thanks,

Anatolij

--
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-50 Fax: +49-8142-66989-80 Email: office at denx.de

 Disclaimer:
This e-mail, and any files transmitted with it are "Pricol Technologies Confidential" and intended solely for the use of the individual or entity to whom it is addressed. Any copying, dissemination, disclosure or use of its contents is prohibited. If you have received this e-mail in error, please discard the message and notify us at itsupport at pricoltech.com directly.
E-mail communication is not guaranteed to be secure, error or virus-free. They are capable of interception, corruption and delays. Anyone communicating with us via e-mail accepts the risks of e-mail communications and their consequences.

------------------------------

Message: 9
Date: Thu, 28 Mar 2013 13:18:33 +0100
From: " Andreas Bie?mann " <andreas.devel at googlemail.com>
Subject: Re: [U-Boot] Splash Screen Enable in
        (u-boot-2013.01.01.tar.bz2) U-boot source code.
To: nandakumar.ramaswamy at pricoltech.com
Cc: u-boot at lists.denx.de
Message-ID: <51543519.8080404 at gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Dear nandakumar.ramaswamy at pricoltech.com,

please stop TOFU [1].

On 03/28/2013 12:49 PM, nandakumar.ramaswamy at pricoltech.com wrote:
>
> Hello,

<snip>

> And I tried the below command. But not get the correct output (SPLASH Image) through U-Boot.
>
> MX53LOCO U-Boot > tftp 100000 /tftpboot/lvds.bmp
> Using FEC device
> TFTP from server 192.168.1.176; our IP address is 192.168.1.189
> Filename '/tftpboot/lvds.bmp'.
> Load address: 0x100000
> Loading: T T T T T
>
> Please give your suggestion and solution ASAP.

please read about asking smart questions [2].

> Note: I am trying to display from SD-card.

So why you try to read data via tftp? How about fatload or ext2load?

As Anatolij pointed out you need to use the bmp command to display some
memory range which contains the BMP image.
To get the BMP image there you can use tftp, however your server
(192.168.1.176) seems not to provide the image (/tftpboot/lvds.bmp),
cause it runs always in timeout.
Just my 2?, sorry, I can not help you with the i.mx and lcd setup.

Best regards

Andreas Bie?mann

[1] http://www.vranx.de/mail/tofu.html
[2] http://www.catb.org/esr/faqs/smart-questions.html#urgent


------------------------------

Message: 10
Date: Thu, 28 Mar 2013 15:45:54 +0800
From: Hung-ying Tyan <tyanh at chromium.org>
Subject: [U-Boot] [PATCH v3 1/7] cros: add cros_ec driver
To: U-Boot Mailing List <u-boot at lists.denx.de>
Cc: Vincent Palatin <vpalatin at chromium.org>,    Gabe Black
        <gabeblack at chromium.org>,       Bill Richardson <wfrichar at chromium.org>,
        Randall Spangler <rspangler at chromium.org>,      Sean Paul
        <seanpaul at chromium.org>, Tom Rini <trini at ti.com>,       Louis Yung-Chieh Lo
        <yjlou at chromium.org>
Message-ID: <1364456760-31500-2-git-send-email-tyanh at chromium.org>

This patch adds the cros_ec driver that implements the protocol for
communicating with Google's ChromeOS embedded controller.

Signed-off-by: Bernie Thompson <bhthompson at chromium.org>
Signed-off-by: Bill Richardson <wfrichar at chromium.org>
Signed-off-by: Che-Liang Chiou <clchiou at chromium.org>
Signed-off-by: Doug Anderson <dianders at chromium.org>
Signed-off-by: Gabe Black <gabeblack at chromium.org>
Signed-off-by: Hung-ying Tyan <tyanh at chromium.org>
Signed-off-by: Louis Yung-Chieh Lo <yjlou at chromium.org>
Signed-off-by: Randall Spangler <rspangler at chromium.org>
Signed-off-by: Sean Paul <seanpaul at chromium.org>
Signed-off-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Vincent Palatin <vpalatin at chromium.org>

---
Changes in v3: None
Changes in v2:
- Fixed warnings of exceeding 80 chars in a line.
- Added commit message.
- Dropped the period from commit subject.

 doc/device-tree-bindings/input/cros-ec-keyb.txt |   79 ++
 doc/device-tree-bindings/misc/cros-ec.txt       |   38 +
 doc/device-tree-bindings/spi/exynos-spi.txt     |   55 +
 drivers/misc/Makefile                           |    1 +
 drivers/misc/cros_ec.c                          | 1304 ++++++++++++++++++++
 include/cros_ec.h                               |  449 +++++++
 include/cros_ec_message.h                       |   44 +
 include/ec_commands.h                           | 1440 +++++++++++++++++++++++
 include/fdtdec.h                                |    1 +
 lib/fdtdec.c                                    |    1 +
 10 files changed, 3412 insertions(+)
 create mode 100644 doc/device-tree-bindings/input/cros-ec-keyb.txt
 create mode 100644 doc/device-tree-bindings/misc/cros-ec.txt
 create mode 100644 doc/device-tree-bindings/spi/exynos-spi.txt
 create mode 100644 drivers/misc/cros_ec.c
 create mode 100644 include/cros_ec.h
 create mode 100644 include/cros_ec_message.h
 create mode 100644 include/ec_commands.h

diff --git a/doc/device-tree-bindings/input/cros-ec-keyb.txt b/doc/device-tree-bindings/input/cros-ec-keyb.txt
new file mode 100644
index 0000000..3118276
--- /dev/null
+++ b/doc/device-tree-bindings/input/cros-ec-keyb.txt
@@ -0,0 +1,79 @@
+CROS_EC Keyboard
+
+The CROS_EC (Matrix Keyboard Protocol) allows communcation with a secondary
+micro used for keyboard, and possible other features.
+
+The CROS_EC keyboard uses this protocol to receive key scans and produce input
+in U-Boot.
+
+Required properties :
+- compatible : "google,cros-ec-keyb"
+- google,key-rows : Number of key rows
+- google,key-columns : Number of key columns
+
+Optional properties, in addition to those specified by the shared
+matrix-keyboard bindings:
+
+- linux,fn-keymap: a second keymap, same specification as the
+  matrix-keyboard-controller spec but to be used when the KEY_FN modifier
+  key is pressed.
+- google,repeat-delay-ms : delay in milliseconds before repeat starts
+- google,repeat-rate-ms : delay between each subsequent key press
+- google,ghost-filter : enable ghost filtering for this device
+
+Example, taken from daisy:
+
+cros-ec-keyb {
+       compatible = "google,cros-ec-keyb";
+       google,key-rows = <8>;
+       google,key-columns = <13>;
+       google,ghost-filter;
+       google,repeat-delay-ms = <240>;
+       google,repeat-rate-ms = <30>;
+       /*
+               * Keymap entries take the form of 0xRRCCKKKK where
+               * RR=Row CC=Column KKKK=Key Code
+               * The values below are for a US keyboard layout and
+               * are taken from the Linux driver. Note that the
+               * 102ND key is not used for US keyboards.
+               */
+       linux,keymap = <
+               /* CAPSLCK F1         B          F10     */
+               0x0001003a 0x0002003c 0x00030030 0x00040044
+               /* N       =          R_ALT      ESC     */
+               0x00060031 0x0008000d 0x000a0064 0x01010001
+               /* F4      G          F7         H       */
+               0x0102003e 0x01030022 0x01040041 0x01060023
+               /* '       F9         BKSPACE    L_CTRL  */
+               0x01080028 0x01090043 0x010b000e 0x0200001d
+               /* TAB     F3         T          F6      */
+               0x0201000f 0x0202003d 0x02030014 0x02040040
+               /* ]       Y          102ND      [       */
+               0x0205001b 0x02060015 0x02070056 0x0208001a
+               /* F8      GRAVE      F2         5       */
+               0x02090042 0x03010029 0x0302003c 0x03030006
+               /* F5      6          -          \       */
+               0x0304003f 0x03060007 0x0308000c 0x030b002b
+               /* R_CTRL  A          D          F       */
+               0x04000061 0x0401001e 0x04020020 0x04030021
+               /* S       K          J          ;       */
+               0x0404001f 0x04050025 0x04060024 0x04080027
+               /* L       ENTER      Z          C       */
+               0x04090026 0x040b001c 0x0501002c 0x0502002e
+               /* V       X          ,          M       */
+               0x0503002f 0x0504002d 0x05050033 0x05060032
+               /* L_SHIFT /          .          SPACE   */
+               0x0507002a 0x05080035 0x05090034 0x050B0039
+               /* 1       3          4          2       */
+               0x06010002 0x06020004 0x06030005 0x06040003
+               /* 8       7          0          9       */
+               0x06050009 0x06060008 0x0608000b 0x0609000a
+               /* L_ALT   DOWN       RIGHT      Q       */
+               0x060a0038 0x060b006c 0x060c006a 0x07010010
+               /* E       R          W          I       */
+               0x07020012 0x07030013 0x07040011 0x07050017
+               /* U       R_SHIFT    P          O       */
+               0x07060016 0x07070036 0x07080019 0x07090018
+               /* UP      LEFT    */
+               0x070b0067 0x070c0069>;
+};
diff --git a/doc/device-tree-bindings/misc/cros-ec.txt b/doc/device-tree-bindings/misc/cros-ec.txt
new file mode 100644
index 0000000..07ea7cd
--- /dev/null
+++ b/doc/device-tree-bindings/misc/cros-ec.txt
@@ -0,0 +1,38 @@
+Chrome OS CROS_EC Binding
+======================
+
+The device tree node which describes the operation of the CROS_EC interface
+is as follows:
+
+Required properties :
+- compatible = "google,cros-ec"
+
+Optional properties :
+- spi-max-frequency : Sets the maximum frequency (in Hz) for SPI bus
+   operation
+- i2c-max-frequency : Sets the maximum frequency (in Hz) for I2C bus
+   operation
+- ec-interrupt : Selects the EC interrupt, defined as a GPIO according
+   to the platform
+- optimise-flash-write : Boolean property - if present then flash blocks
+   containing all 0xff will not be written, since we assume that the EC
+   uses that pattern for erased blocks
+
+The CROS_EC node should appear as a subnode of the interrupt that connects it
+to the EC (e.g. i2c, spi, lpc). The reg property (as usual) will indicate
+the unit address on that bus.
+
+
+Example
+=======
+
+       spi at 131b0000 {
+               cros-ec at 0 {
+                       reg = <0>;
+                       compatible = "google,cros-ec";
+                       spi-max-frequency = <5000000>;
+                       ec-interrupt = <&gpio 174 1>;
+                       optimise-flash-write;
+                       status = "disabled";
+               };
+       };
diff --git a/doc/device-tree-bindings/spi/exynos-spi.txt b/doc/device-tree-bindings/spi/exynos-spi.txt
new file mode 100644
index 0000000..21a7beb
--- /dev/null
+++ b/doc/device-tree-bindings/spi/exynos-spi.txt
@@ -0,0 +1,55 @@
+Exynos SPI controllers
+======================
+
+The device node for an SPI controller that is part of an Exynos
+SOC is as described in the ePAPR document with the following
+modifications and additions :
+
+Required properties :
+ - compatible : Should be "samsung,exynos-spi" for SPI controllers
+
+Also #address-cells should be 1 and #size-cells should be 0.
+
+Optional properties:
+ - samsung,periph-id : Peripheral ID number used by U-Boot. This property
+                is needed at least in the interim until an Exynos clock
+                binding is available and full clock infrastruture for
+                Exynos is available in U-Boot.
+
+ - clock-frequency : bus frequency in Hz
+
+Available peripheral IDs, numbered from 0, are:
+
+0      PERIPH_ID_UART0
+1      PERIPH_ID_UART1
+2      PERIPH_ID_UART2
+3      PERIPH_ID_UART3
+4      PERIPH_ID_SDMMC0
+5      PERIPH_ID_SDMMC1
+6      PERIPH_ID_SDMMC2
+7      PERIPH_ID_SDMMC3
+8      PERIPH_ID_SROMC
+9      PERIPH_ID_SPI0
+10     PERIPH_ID_SPI1
+11     PERIPH_ID_SPI2
+12     PERIPH_ID_SPI3
+13     PERIPH_ID_SPI4
+
+
+Example
+=======
+
+spi at 131a0000 {
+       compatible = "samsung,exynos-spi";
+       reg = <0x131a0000 0x30>;
+       samsung,periph-id = <PERIPH_ID_SPI3>;
+       #address-cells = <1>;
+       #size-cells = <0>;
+       clock-frequency = <10000000>;
+
+       /* A device on chip select 0 of this SPI bus */
+       cros-ec at 0 {
+               compatible = "google,matrix-keyboard";
+               reg = <0>;
+       };
+};
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 8cdc3b6..33fe822 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -30,6 +30,7 @@ COBJS-$(CONFIG_DS4510)  += ds4510.o
 COBJS-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
 COBJS-$(CONFIG_GPIO_LED) += gpio_led.o
 COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o
+COBJS-$(CONFIG_CROS_EC) += cros_ec.o
 COBJS-$(CONFIG_NS87308) += ns87308.o
 COBJS-$(CONFIG_PDSP188x) += pdsp188x.o
 COBJS-$(CONFIG_STATUS_LED) += status_led.o
diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
new file mode 100644
index 0000000..6e774d9
--- /dev/null
+++ b/drivers/misc/cros_ec.c
@@ -0,0 +1,1304 @@
+/*
+ * Chromium OS cros_ec driver
+ *
+ * Copyright (c) 2012 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+/*
+ * The Matrix Keyboard Protocol driver handles talking to the keyboard
+ * controller chip. Mostly this is for keyboard functions, but some other
+ * things have slipped in, so we provide generic services to talk to the
+ * KBC.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <i2c.h>
+#include <cros_ec.h>
+#include <fdtdec.h>
+#include <malloc.h>
+#include <spi.h>
+#include <asm/io.h>
+#include <asm-generic/gpio.h>
+
+#ifdef DEBUG_TRACE
+#define debug_trace(fmt, b...) debug(fmt, #b)
+#else
+#define debug_trace(fmt, b...)
+#endif
+
+enum {
+       /* Timeout waiting for a flash erase command to complete */
+       CROS_EC_CMD_TIMEOUT_MS  = 5000,
+       /* Timeout waiting for a synchronous hash to be recomputed */
+       CROS_EC_CMD_HASH_TIMEOUT_MS = 2000,
+};
+
+static struct cros_ec_dev static_dev, *last_dev;
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Note: depends on enum ec_current_image */
+static const char * const ec_current_image_name[] = {"unknown", "RO", "RW"};
+
+void cros_ec_dump_data(const char *name, int cmd, const uint8_t *data, int len)
+{
+#ifdef DEBUG
+       int i;
+
+       printf("%s: ", name);
+       if (cmd != -1)
+               printf("cmd=%#x: ", cmd);
+       for (i = 0; i < len; i++)
+               printf("%02x ", data[i]);
+       printf("\n");
+#endif
+}
+
+/*
+ * Calculate a simple 8-bit checksum of a data block
+ *
+ * @param data Data block to checksum
+ * @param size Size of data block in bytes
+ * @return checksum value (0 to 255)
+ */
+int cros_ec_calc_checksum(const uint8_t *data, int size)
+{
+       int csum, i;
+
+       for (i = csum = 0; i < size; i++)
+               csum += data[i];
+       return csum & 0xff;
+}
+
+static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
+                       const void *dout, int dout_len,
+                       uint8_t **dinp, int din_len)
+{
+       int ret;
+
+       switch (dev->interface) {
+#ifdef CONFIG_CROS_EC_SPI
+       case CROS_EC_IF_SPI:
+               ret = cros_ec_spi_command(dev, cmd, cmd_version,
+                                       (const uint8_t *)dout, dout_len,
+                                       dinp, din_len);
+               break;
+#endif
+#ifdef CONFIG_CROS_EC_I2C
+       case CROS_EC_IF_I2C:
+               ret = cros_ec_i2c_command(dev, cmd, cmd_version,
+                                       (const uint8_t *)dout, dout_len,
+                                       dinp, din_len);
+               break;
+#endif
+#ifdef CONFIG_CROS_EC_LPC
+       case CROS_EC_IF_LPC:
+               ret = cros_ec_lpc_command(dev, cmd, cmd_version,
+                                       (const uint8_t *)dout, dout_len,
+                                       dinp, din_len);
+               break;
+#endif
+       case CROS_EC_IF_NONE:
+       default:
+               ret = -1;
+       }
+
+       return ret;
+}
+
+/**
+ * Send a command to the CROS-EC device and return the reply.
+ *
+ * The device's internal input/output buffers are used.
+ *
+ * @param dev          CROS-EC device
+ * @param cmd          Command to send (EC_CMD_...)
+ * @param cmd_version  Version of command to send (EC_VER_...)
+ * @param dout          Output data (may be NULL If dout_len=0)
+ * @param dout_len      Size of output data in bytes
+ * @param dinp          Response data (may be NULL If din_len=0).
+ *                     If not NULL, it will be updated to point to the data
+ *                     and will always be double word aligned (64-bits)
+ * @param din_len       Maximum size of response in bytes
+ * @return number of bytes in response, or -1 on error
+ */
+static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd,
+               int cmd_version, const void *dout, int dout_len, uint8_t **dinp,
+               int din_len)
+{
+       uint8_t *din;
+       int len;
+
+       if (cmd_version != 0 && !dev->cmd_version_is_supported) {
+               debug("%s: Command version >0 unsupported\n", __func__);
+               return -1;
+       }
+       len = send_command(dev, cmd, cmd_version, dout, dout_len,
+                               &din, din_len);
+
+       /* If the command doesn't complete, wait a while */
+       if (len == -EC_RES_IN_PROGRESS) {
+               struct ec_response_get_comms_status *resp;
+               ulong start;
+
+               /* Wait for command to complete */
+               start = get_timer(0);
+               do {
+                       int ret;
+
+                       mdelay(50);     /* Insert some reasonable delay */
+                       ret = send_command(dev, EC_CMD_GET_COMMS_STATUS, 0,
+                                       NULL, 0,
+                                       (uint8_t **)&resp, sizeof(*resp));
+                       if (ret < 0)
+                               return ret;
+
+                       if (get_timer(start) > CROS_EC_CMD_TIMEOUT_MS) {
+                               debug("%s: Command %#02x timeout\n",
+                                     __func__, cmd);
+                               return -EC_RES_TIMEOUT;
+                       }
+               } while (resp->flags & EC_COMMS_STATUS_PROCESSING);
+
+               /* OK it completed, so read the status response */
+               /* not sure why it was 0 for the last argument */
+               len = send_command(dev, EC_CMD_RESEND_RESPONSE, 0,
+                               NULL, 0, &din, din_len);
+       }
+
+       debug("%s: len=%d, dinp=%p, *dinp=%p\n", __func__, len, dinp, *dinp);
+       if (dinp) {
+               /* If we have any data to return, it must be 64bit-aligned */
+               assert(len <= 0 || !((uintptr_t)din & 7));
+               *dinp = din;
+       }
+
+       return len;
+}
+
+/**
+ * Send a command to the CROS-EC device and return the reply.
+ *
+ * The device's internal input/output buffers are used.
+ *
+ * @param dev          CROS-EC device
+ * @param cmd          Command to send (EC_CMD_...)
+ * @param cmd_version  Version of command to send (EC_VER_...)
+ * @param dout          Output data (may be NULL If dout_len=0)
+ * @param dout_len      Size of output data in bytes
+ * @param din           Response data (may be NULL If din_len=0).
+ *                     It not NULL, it is a place for ec_command() to copy the
+ *      data to.
+ * @param din_len       Maximum size of response in bytes
+ * @return number of bytes in response, or -1 on error
+ */
+static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
+                     const void *dout, int dout_len,
+                     void *din, int din_len)
+{
+       uint8_t *in_buffer;
+       int len;
+
+       assert((din_len == 0) || din);
+       len = ec_command_inptr(dev, cmd, cmd_version, dout, dout_len,
+                       &in_buffer, din_len);
+       if (len > 0) {
+               /*
+                * If we were asked to put it somewhere, do so, otherwise just
+                * disregard the result.
+                */
+               if (din && in_buffer) {
+                       assert(len <= din_len);
+                       memmove(din, in_buffer, len);
+               }
+       }
+       return len;
+}
+
+int cros_ec_scan_keyboard(struct cros_ec_dev *dev, struct mbkp_keyscan *scan)
+{
+       if (ec_command(dev, EC_CMD_CROS_EC_STATE, 0, NULL, 0, scan,
+                      sizeof(scan->data)) < sizeof(scan->data))
+               return -1;
+
+       return 0;
+}
+
+int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen)
+{
+       struct ec_response_get_version *r;
+
+       if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
+                       (uint8_t **)&r, sizeof(*r)) < sizeof(*r))
+               return -1;
+
+       if (maxlen > sizeof(r->version_string_ro))
+               maxlen = sizeof(r->version_string_ro);
+
+       switch (r->current_image) {
+       case EC_IMAGE_RO:
+               memcpy(id, r->version_string_ro, maxlen);
+               break;
+       case EC_IMAGE_RW:
+               memcpy(id, r->version_string_rw, maxlen);
+               break;
+       default:
+               return -1;
+       }
+
+       id[maxlen - 1] = '\0';
+       return 0;
+}
+
+int cros_ec_read_version(struct cros_ec_dev *dev,
+                      struct ec_response_get_version **versionp)
+{
+       if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
+                       (uint8_t **)versionp, sizeof(**versionp))
+                       < sizeof(**versionp))
+               return -1;
+
+       return 0;
+}
+
+int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp)
+{
+       if (ec_command_inptr(dev, EC_CMD_GET_BUILD_INFO, 0, NULL, 0,
+                       (uint8_t **)strp, EC_HOST_PARAM_SIZE) < 0)
+               return -1;
+
+       return 0;
+}
+
+int cros_ec_read_current_image(struct cros_ec_dev *dev,
+               enum ec_current_image *image)
+{
+       struct ec_response_get_version *r;
+
+       if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
+                       (uint8_t **)&r, sizeof(*r)) < sizeof(*r))
+               return -1;
+
+       *image = r->current_image;
+       return 0;
+}
+
+static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev,
+                                 struct ec_response_vboot_hash *hash)
+{
+       struct ec_params_vboot_hash p;
+       ulong start;
+
+       start = get_timer(0);
+       while (hash->status == EC_VBOOT_HASH_STATUS_BUSY) {
+               mdelay(50);     /* Insert some reasonable delay */
+
+               p.cmd = EC_VBOOT_HASH_GET;
+               if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
+                      hash, sizeof(*hash)) < 0)
+                       return -1;
+
+               if (get_timer(start) > CROS_EC_CMD_HASH_TIMEOUT_MS) {
+                       debug("%s: EC_VBOOT_HASH_GET timeout\n", __func__);
+                       return -EC_RES_TIMEOUT;
+               }
+       }
+       return 0;
+}
+
+
+int cros_ec_read_hash(struct cros_ec_dev *dev,
+               struct ec_response_vboot_hash *hash)
+{
+       struct ec_params_vboot_hash p;
+       int rv;
+
+       p.cmd = EC_VBOOT_HASH_GET;
+       if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
+                      hash, sizeof(*hash)) < 0)
+               return -1;
+
+       /* If the EC is busy calculating the hash, fidget until it's done. */
+       rv = cros_ec_wait_on_hash_done(dev, hash);
+       if (rv)
+               return rv;
+
+       /* If the hash is valid, we're done. Otherwise, we have to kick it off
+        * again and wait for it to complete. Note that we explicitly assume
+        * that hashing zero bytes is always wrong, even though that would
+        * produce a valid hash value. */
+       if (hash->status == EC_VBOOT_HASH_STATUS_DONE && hash->size)
+               return 0;
+
+       debug("%s: No valid hash (status=%d size=%d). Compute one...\n",
+             __func__, hash->status, hash->size);
+
+       p.cmd = EC_VBOOT_HASH_RECALC;
+       p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
+       p.nonce_size = 0;
+       p.offset = EC_VBOOT_HASH_OFFSET_RW;
+
+       if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
+                      hash, sizeof(*hash)) < 0)
+               return -1;
+
+       rv = cros_ec_wait_on_hash_done(dev, hash);
+       if (rv)
+               return rv;
+
+       debug("%s: hash done\n", __func__);
+
+       return 0;
+}
+
+static int cros_ec_invalidate_hash(struct cros_ec_dev *dev)
+{
+       struct ec_params_vboot_hash p;
+       struct ec_response_vboot_hash *hash;
+
+       /* We don't have an explict command for the EC to discard its current
+        * hash value, so we'll just tell it to calculate one that we know is
+        * wrong (we claim that hashing zero bytes is always invalid).
+        */
+       p.cmd = EC_VBOOT_HASH_RECALC;
+       p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
+       p.nonce_size = 0;
+       p.offset = 0;
+       p.size = 0;
+
+       debug("%s:\n", __func__);
+
+       if (ec_command_inptr(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
+                      (uint8_t **)&hash, sizeof(*hash)) < 0)
+               return -1;
+
+       /* No need to wait for it to finish */
+       return 0;
+}
+
+int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd,
+               uint8_t flags)
+{
+       struct ec_params_reboot_ec p;
+
+       p.cmd = cmd;
+       p.flags = flags;
+
+       if (ec_command_inptr(dev, EC_CMD_REBOOT_EC, 0, &p, sizeof(p), NULL, 0)
+                       < 0)
+               return -1;
+
+       if (!(flags & EC_REBOOT_FLAG_ON_AP_SHUTDOWN)) {
+               /*
+                * EC reboot will take place immediately so delay to allow it
+                * to complete.  Note that some reboot types (EC_REBOOT_COLD)
+                * will reboot the AP as well, in which case we won't actually
+                * get to this point.
+                */
+               /*
+                * TODO(rspangler at chromium.org): Would be nice if we had a
+                * better way to determine when the reboot is complete.  Could
+                * we poll a memory-mapped LPC value?
+                */
+               udelay(50000);
+       }
+
+       return 0;
+}
+
+int cros_ec_interrupt_pending(struct cros_ec_dev *dev)
+{
+       /* no interrupt support : always poll */
+       if (!fdt_gpio_isvalid(&dev->ec_int))
+               return 1;
+
+       return !gpio_get_value(dev->ec_int.gpio);
+}
+
+int cros_ec_info(struct cros_ec_dev *dev, struct ec_response_cros_ec_info *info)
+{
+       if (ec_command(dev, EC_CMD_CROS_EC_INFO, 0, NULL, 0, info,
+                       sizeof(*info)) < sizeof(*info))
+               return -1;
+
+       return 0;
+}
+
+int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr)
+{
+       struct ec_response_host_event_mask *resp;
+
+       /*
+        * Use the B copy of the event flags, because the main copy is already
+        * used by ACPI/SMI.
+        */
+       if (ec_command_inptr(dev, EC_CMD_HOST_EVENT_GET_B, 0, NULL, 0,
+                      (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp))
+               return -1;
+
+       if (resp->mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_INVALID))
+               return -1;
+
+       *events_ptr = resp->mask;
+       return 0;
+}
+
+int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events)
+{
+       struct ec_params_host_event_mask params;
+
+       params.mask = events;
+
+       /*
+        * Use the B copy of the event flags, so it affects the data returned
+        * by cros_ec_get_host_events().
+        */
+       if (ec_command_inptr(dev, EC_CMD_HOST_EVENT_CLEAR_B, 0,
+                      &params, sizeof(params), NULL, 0) < 0)
+               return -1;
+
+       return 0;
+}
+
+int cros_ec_flash_protect(struct cros_ec_dev *dev,
+                      uint32_t set_mask, uint32_t set_flags,
+                      struct ec_response_flash_protect *resp)
+{
+       struct ec_params_flash_protect params;
+
+       params.mask = set_mask;
+       params.flags = set_flags;
+
+       if (ec_command(dev, EC_CMD_FLASH_PROTECT, EC_VER_FLASH_PROTECT,
+                      &params, sizeof(params),
+                      resp, sizeof(*resp)) < sizeof(*resp))
+               return -1;
+
+       return 0;
+}
+
+static int cros_ec_check_version(struct cros_ec_dev *dev)
+{
+       struct ec_params_hello req;
+       struct ec_response_hello *resp;
+
+#ifdef CONFIG_CROS_EC_LPC
+       /* LPC has its own way of doing this */
+       if (dev->interface == CROS_EC_IF_LPC)
+               return cros_ec_lpc_check_version(dev);
+#endif
+
+       /*
+        * TODO(sjg at chromium.org).
+        * There is a strange oddity here with the EC. We could just ignore
+        * the response, i.e. pass the last two parameters as NULL and 0.
+        * In this case we won't read back very many bytes from the EC.
+        * On the I2C bus the EC gets upset about this and will try to send
+        * the bytes anyway. This means that we will have to wait for that
+        * to complete before continuing with a new EC command.
+        *
+        * This problem is probably unique to the I2C bus.
+        *
+        * So for now, just read all the data anyway.
+        */
+       dev->cmd_version_is_supported = 1;
+       if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
+                      (uint8_t **)&resp, sizeof(*resp)) > 0) {
+               /* It appears to understand new version commands */
+               dev->cmd_version_is_supported = 1;
+       } else {
+               dev->cmd_version_is_supported = 0;
+               if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req,
+                             sizeof(req), (uint8_t **)&resp,
+                             sizeof(*resp)) < 0) {
+                       debug("%s: Failed both old and new command style\n",
+                               __func__);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+int cros_ec_test(struct cros_ec_dev *dev)
+{
+       struct ec_params_hello req;
+       struct ec_response_hello *resp;
+
+       req.in_data = 0x12345678;
+       if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
+                      (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp)) {
+               printf("ec_command_inptr() returned error\n");
+               return -1;
+       }
+       if (resp->out_data != req.in_data + 0x01020304) {
+               printf("Received invalid handshake %x\n", resp->out_data);
+               return -1;
+       }
+
+       return 0;
+}
+
+int cros_ec_flash_offset(struct cros_ec_dev *dev, enum ec_flash_region region,
+                     uint32_t *offset, uint32_t *size)
+{
+       struct ec_params_flash_region_info p;
+       struct ec_response_flash_region_info *r;
+       int ret;
+
+       p.region = region;
+       ret = ec_command_inptr(dev, EC_CMD_FLASH_REGION_INFO,
+                        EC_VER_FLASH_REGION_INFO,
+                        &p, sizeof(p), (uint8_t **)&r, sizeof(*r));
+       if (ret != sizeof(*r))
+               return -1;
+
+       if (offset)
+               *offset = r->offset;
+       if (size)
+               *size = r->size;
+
+       return 0;
+}
+
+int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size)
+{
+       struct ec_params_flash_erase p;
+
+       p.offset = offset;
+       p.size = size;
+       return ec_command_inptr(dev, EC_CMD_FLASH_ERASE, 0, &p, sizeof(p),
+                       NULL, 0);
+}
+
+/**
+ * Write a single block to the flash
+ *
+ * Write a block of data to the EC flash. The size must not exceed the flash
+ * write block size which you can obtain from cros_ec_flash_write_burst_size().
+ *
+ * The offset starts at 0. You can obtain the region information from
+ * cros_ec_flash_offset() to find out where to write for a particular region.
+ *
+ * Attempting to write to the region where the EC is currently running from
+ * will result in an error.
+ *
+ * @param dev          CROS-EC device
+ * @param data         Pointer to data buffer to write
+ * @param offset       Offset within flash to write to.
+ * @param size         Number of bytes to write
+ * @return 0 if ok, -1 on error
+ */
+static int cros_ec_flash_write_block(struct cros_ec_dev *dev,
+               const uint8_t *data, uint32_t offset, uint32_t size)
+{
+       struct ec_params_flash_write p;
+
+       p.offset = offset;
+       p.size = size;
+       assert(data && p.size <= sizeof(p.data));
+       memcpy(p.data, data, p.size);
+
+       return ec_command_inptr(dev, EC_CMD_FLASH_WRITE, 0,
+                         &p, sizeof(p), NULL, 0) >= 0 ? 0 : -1;
+}
+
+/**
+ * Return optimal flash write burst size
+ */
+static int cros_ec_flash_write_burst_size(struct cros_ec_dev *dev)
+{
+       struct ec_params_flash_write p;
+       return sizeof(p.data);
+}
+
+/**
+ * Check if a block of data is erased (all 0xff)
+ *
+ * This function is useful when dealing with flash, for checking whether a
+ * data block is erased and thus does not need to be programmed.
+ *
+ * @param data         Pointer to data to check (must be word-aligned)
+ * @param size         Number of bytes to check (must be word-aligned)
+ * @return 0 if erased, non-zero if any word is not erased
+ */
+static int cros_ec_data_is_erased(const uint32_t *data, int size)
+{
+       assert(!(size & 3));
+       size /= sizeof(uint32_t);
+       for (; size > 0; size -= 4, data++)
+               if (*data != -1U)
+                       return 0;
+
+       return 1;
+}
+
+int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data,
+                    uint32_t offset, uint32_t size)
+{
+       uint32_t burst = cros_ec_flash_write_burst_size(dev);
+       uint32_t end, off;
+       int ret;
+
+       /*
+        * TODO: round up to the nearest multiple of write size.  Can get away
+        * without that on link right now because its write size is 4 bytes.
+        */
+       end = offset + size;
+       for (off = offset; off < end; off += burst, data += burst) {
+               uint32_t todo;
+
+               /* If the data is empty, there is no point in programming it */
+               todo = min(end - off, burst);
+               if (dev->optimise_flash_write &&
+                               cros_ec_data_is_erased((uint32_t *)data, todo))
+                       continue;
+
+               ret = cros_ec_flash_write_block(dev, data, off, todo);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+/**
+ * Read a single block from the flash
+ *
+ * Read a block of data from the EC flash. The size must not exceed the flash
+ * write block size which you can obtain from cros_ec_flash_write_burst_size().
+ *
+ * The offset starts at 0. You can obtain the region information from
+ * cros_ec_flash_offset() to find out where to read for a particular region.
+ *
+ * @param dev          CROS-EC device
+ * @param data         Pointer to data buffer to read into
+ * @param offset       Offset within flash to read from
+ * @param size         Number of bytes to read
+ * @return 0 if ok, -1 on error
+ */
+static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data,
+                                uint32_t offset, uint32_t size)
+{
+       struct ec_params_flash_read p;
+
+       p.offset = offset;
+       p.size = size;
+
+       return ec_command(dev, EC_CMD_FLASH_READ, 0,
+                         &p, sizeof(p), data, size) >= 0 ? 0 : -1;
+}
+
+int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset,
+                   uint32_t size)
+{
+       uint32_t burst = cros_ec_flash_write_burst_size(dev);
+       uint32_t end, off;
+       int ret;
+
+       end = offset + size;
+       for (off = offset; off < end; off += burst, data += burst) {
+               ret = cros_ec_flash_read_block(dev, data, off,
+                                           min(end - off, burst));
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+int cros_ec_flash_update_rw(struct cros_ec_dev *dev,
+                        const uint8_t *image, int image_size)
+{
+       uint32_t rw_offset, rw_size;
+       int ret;
+
+       if (cros_ec_flash_offset(dev, EC_FLASH_REGION_RW, &rw_offset, &rw_size))
+               return -1;
+       if (image_size > rw_size)
+               return -1;
+
+       /* Invalidate the existing hash, just in case the AP reboots
+        * unexpectedly during the update. If that happened, the EC RW firmware
+        * would be invalid, but the EC would still have the original hash.
+        */
+       ret = cros_ec_invalidate_hash(dev);
+       if (ret)
+               return ret;
+
+       /*
+        * Erase the entire RW section, so that the EC doesn't see any garbage
+        * past the new image if it's smaller than the current image.
+        *
+        * TODO: could optimize this to erase just the current image, since
+        * presumably everything past that is 0xff's.  But would still need to
+        * round up to the nearest multiple of erase size.
+        */
+       ret = cros_ec_flash_erase(dev, rw_offset, rw_size);
+       if (ret)
+               return ret;
+
+       /* Write the image */
+       ret = cros_ec_flash_write(dev, image, rw_offset, image_size);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+int cros_ec_read_vbnvcontext(struct cros_ec_dev *dev, uint8_t *block)
+{
+       struct ec_params_vbnvcontext p;
+       int len;
+
+       p.op = EC_VBNV_CONTEXT_OP_READ;
+
+       len = ec_command(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
+                       &p, sizeof(p), block, EC_VBNV_BLOCK_SIZE);
+       if (len < EC_VBNV_BLOCK_SIZE)
+               return -1;
+
+       return 0;
+}
+
+int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block)
+{
+       struct ec_params_vbnvcontext p;
+       int len;
+
+       p.op = EC_VBNV_CONTEXT_OP_WRITE;
+       memcpy(p.block, block, sizeof(p.block));
+
+       len = ec_command_inptr(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
+                       &p, sizeof(p), NULL, 0);
+       if (len < 0)
+               return -1;
+
+       return 0;
+}
+
+int cros_ec_set_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t state)
+{
+       struct ec_params_ldo_set params;
+
+       params.index = index;
+       params.state = state;
+
+       if (ec_command_inptr(dev, EC_CMD_LDO_SET, 0,
+                      &params, sizeof(params),
+                      NULL, 0))
+               return -1;
+
+       return 0;
+}
+
+int cros_ec_get_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t *state)
+{
+       struct ec_params_ldo_get params;
+       struct ec_response_ldo_get *resp;
+
+       params.index = index;
+
+       if (ec_command_inptr(dev, EC_CMD_LDO_GET, 0,
+                      &params, sizeof(params),
+                      (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp))
+               return -1;
+
+       *state = resp->state;
+
+       return 0;
+}
+
+/**
+ * Decode MBKP details from the device tree and allocate a suitable device.
+ *
+ * @param blob         Device tree blob
+ * @param node         Node to decode from
+ * @param devp         Returns a pointer to the new allocated device
+ * @return 0 if ok, -1 on error
+ */
+static int cros_ec_decode_fdt(const void *blob, int node,
+               struct cros_ec_dev **devp)
+{
+       enum fdt_compat_id compat;
+       struct cros_ec_dev *dev;
+       int parent;
+
+       /* See what type of parent we are inside (this is expensive) */
+       parent = fdt_parent_offset(blob, node);
+       if (parent < 0) {
+               debug("%s: Cannot find node parent\n", __func__);
+               return -1;
+       }
+
+       dev = &static_dev;
+       dev->node = node;
+       dev->parent_node = parent;
+
+       compat = fdtdec_lookup(blob, parent);
+       switch (compat) {
+#ifdef CONFIG_CROS_EC_SPI
+       case COMPAT_SAMSUNG_EXYNOS_SPI:
+               dev->interface = CROS_EC_IF_SPI;
+               if (cros_ec_spi_decode_fdt(dev, blob))
+                       return -1;
+               break;
+#endif
+#ifdef CONFIG_CROS_EC_I2C
+       case COMPAT_SAMSUNG_S3C2440_I2C:
+               dev->interface = CROS_EC_IF_I2C;
+               if (cros_ec_i2c_decode_fdt(dev, blob))
+                       return -1;
+               break;
+#endif
+#ifdef CONFIG_CROS_EC_LPC
+       case COMPAT_INTEL_LPC:
+               dev->interface = CROS_EC_IF_LPC;
+               break;
+#endif
+       default:
+               debug("%s: Unknown compat id %d\n", __func__, compat);
+               return -1;
+       }
+
+       fdtdec_decode_gpio(blob, node, "ec-interrupt", &dev->ec_int);
+       dev->optimise_flash_write = fdtdec_get_bool(blob, node,
+                                                   "optimise-flash-write");
+       *devp = dev;
+
+       return 0;
+}
+
+int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp)
+{
+       char id[MSG_BYTES];
+       struct cros_ec_dev *dev;
+       int node = 0;
+
+       *cros_ecp = NULL;
+       do {
+               node = fdtdec_next_compatible(blob, node,
+                                             COMPAT_GOOGLE_CROS_EC);
+               if (node < 0) {
+                       debug("%s: Node not found\n", __func__);
+                       return 0;
+               }
+       } while (!fdtdec_get_is_enabled(blob, node));
+
+       if (cros_ec_decode_fdt(blob, node, &dev)) {
+               debug("%s: Failed to decode device.\n", __func__);
+               return -CROS_EC_ERR_FDT_DECODE;
+       }
+
+       switch (dev->interface) {
+#ifdef CONFIG_CROS_EC_SPI
+       case CROS_EC_IF_SPI:
+               if (cros_ec_spi_init(dev, blob)) {
+                       debug("%s: Could not setup SPI interface\n", __func__);
+                       return -CROS_EC_ERR_DEV_INIT;
+               }
+               break;
+#endif
+#ifdef CONFIG_CROS_EC_I2C
+       case CROS_EC_IF_I2C:
+               if (cros_ec_i2c_init(dev, blob))
+                       return -CROS_EC_ERR_DEV_INIT;
+               break;
+#endif
+#ifdef CONFIG_CROS_EC_LPC
+       case CROS_EC_IF_LPC:
+               if (cros_ec_lpc_init(dev, blob))
+                       return -CROS_EC_ERR_DEV_INIT;
+               break;
+#endif
+       case CROS_EC_IF_NONE:
+       default:
+               return 0;
+       }
+
+       /* we will poll the EC interrupt line */
+       fdtdec_setup_gpio(&dev->ec_int);
+       if (fdt_gpio_isvalid(&dev->ec_int))
+               gpio_direction_input(dev->ec_int.gpio);
+
+       if (cros_ec_check_version(dev)) {
+               debug("%s: Could not detect CROS-EC version\n", __func__);
+               return -CROS_EC_ERR_CHECK_VERSION;
+       }
+
+       if (cros_ec_read_id(dev, id, sizeof(id))) {
+               debug("%s: Could not read KBC ID\n", __func__);
+               return -CROS_EC_ERR_READ_ID;
+       }
+
+       /* Remember this device for use by the cros_ec command */
+       last_dev = *cros_ecp = dev;
+       debug("Google Chrome EC CROS-EC driver ready, id '%s'\n", id);
+
+       return 0;
+}
+
+#ifdef CONFIG_CMD_CROS_EC
+int cros_ec_decode_region(int argc, char * const argv[])
+{
+       if (argc > 0) {
+               if (0 == strcmp(*argv, "rw"))
+                       return EC_FLASH_REGION_RW;
+               else if (0 == strcmp(*argv, "ro"))
+                       return EC_FLASH_REGION_RO;
+
+               debug("%s: Invalid region '%s'\n", __func__, *argv);
+       } else {
+               debug("%s: Missing region parameter\n", __func__);
+       }
+
+       return -1;
+}
+
+/**
+ * Perform a flash read or write command
+ *
+ * @param dev          CROS-EC device to read/write
+ * @param is_write     1 do to a write, 0 to do a read
+ * @param argc         Number of arguments
+ * @param argv         Arguments (2 is region, 3 is address)
+ * @return 0 for ok, 1 for a usage error or -ve for ec command error
+ *     (negative EC_RES_...)
+ */
+static int do_read_write(struct cros_ec_dev *dev, int is_write, int argc,
+                        char * const argv[])
+{
+       uint32_t offset, size = -1U, region_size;
+       unsigned long addr;
+       char *endp;
+       int region;
+       int ret;
+
+       region = cros_ec_decode_region(argc - 2, argv + 2);
+       if (region == -1)
+               return 1;
+       if (argc < 4)
+               return 1;
+       addr = simple_strtoul(argv[3], &endp, 16);
+       if (*argv[3] == 0 || *endp != 0)
+               return 1;
+       if (argc > 4) {
+               size = simple_strtoul(argv[4], &endp, 16);
+               if (*argv[4] == 0 || *endp != 0)
+                       return 1;
+       }
+
+       ret = cros_ec_flash_offset(dev, region, &offset, &region_size);
+       if (ret) {
+               debug("%s: Could not read region info\n", __func__);
+               return ret;
+       }
+       if (size == -1U)
+               size = region_size;
+
+       ret = is_write ?
+               cros_ec_flash_write(dev, (uint8_t *)addr, offset, size) :
+               cros_ec_flash_read(dev, (uint8_t *)addr, offset, size);
+       if (ret) {
+               debug("%s: Could not %s region\n", __func__,
+                     is_write ? "write" : "read");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct cros_ec_dev *dev = last_dev;
+       const char *cmd;
+       int ret = 0;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       cmd = argv[1];
+       if (0 == strcmp("init", cmd)) {
+               ret = cros_ec_init(gd->fdt_blob, &dev);
+               if (ret) {
+                       printf("Could not init cros_ec device (err %d)\n", ret);
+                       return 1;
+               }
+               return 0;
+       }
+
+       /* Just use the last allocated device; there should be only one */
+       if (!last_dev) {
+               printf("No CROS-EC device available\n");
+               return 1;
+       }
+       if (0 == strcmp("id", cmd)) {
+               char id[MSG_BYTES];
+
+               if (cros_ec_read_id(dev, id, sizeof(id))) {
+                       debug("%s: Could not read KBC ID\n", __func__);
+                       return 1;
+               }
+               printf("%s\n", id);
+       } else if (0 == strcmp("info", cmd)) {
+               struct ec_response_cros_ec_info info;
+
+               if (cros_ec_info(dev, &info)) {
+                       debug("%s: Could not read KBC info\n", __func__);
+                       return 1;
+               }
+               printf("rows     = %u\n", info.rows);
+               printf("cols     = %u\n", info.cols);
+               printf("switches = %#x\n", info.switches);
+       } else if (0 == strcmp("curimage", cmd)) {
+               enum ec_current_image image;
+
+               if (cros_ec_read_current_image(dev, &image)) {
+                       debug("%s: Could not read KBC image\n", __func__);
+                       return 1;
+               }
+               printf("%d\n", image);
+       } else if (0 == strcmp("hash", cmd)) {
+               struct ec_response_vboot_hash hash;
+               int i;
+
+               if (cros_ec_read_hash(dev, &hash)) {
+                       debug("%s: Could not read KBC hash\n", __func__);
+                       return 1;
+               }
+
+               if (hash.hash_type == EC_VBOOT_HASH_TYPE_SHA256)
+                       printf("type:    SHA-256\n");
+               else
+                       printf("type:    %d\n", hash.hash_type);
+
+               printf("offset:  0x%08x\n", hash.offset);
+               printf("size:    0x%08x\n", hash.size);
+
+               printf("digest:  ");
+               for (i = 0; i < hash.digest_size; i++)
+                       printf("%02x", hash.hash_digest[i]);
+               printf("\n");
+       } else if (0 == strcmp("reboot", cmd)) {
+               int region;
+               enum ec_reboot_cmd cmd;
+
+               if (argc >= 3 && !strcmp(argv[2], "cold"))
+                       cmd = EC_REBOOT_COLD;
+               else {
+                       region = cros_ec_decode_region(argc - 2, argv + 2);
+                       if (region == EC_FLASH_REGION_RO)
+                               cmd = EC_REBOOT_JUMP_RO;
+                       else if (region == EC_FLASH_REGION_RW)
+                               cmd = EC_REBOOT_JUMP_RW;
+                       else
+                               return CMD_RET_USAGE;
+               }
+
+               if (cros_ec_reboot(dev, cmd, 0)) {
+                       debug("%s: Could not reboot KBC\n", __func__);
+                       return 1;
+               }
+       } else if (0 == strcmp("events", cmd)) {
+               uint32_t events;
+
+               if (cros_ec_get_host_events(dev, &events)) {
+                       debug("%s: Could not read host events\n", __func__);
+                       return 1;
+               }
+               printf("0x%08x\n", events);
+       } else if (0 == strcmp("clrevents", cmd)) {
+               uint32_t events = 0x7fffffff;
+
+               if (argc >= 3)
+                       events = simple_strtol(argv[2], NULL, 0);
+
+               if (cros_ec_clear_host_events(dev, events)) {
+                       debug("%s: Could not clear host events\n", __func__);
+                       return 1;
+               }
+       } else if (0 == strcmp("read", cmd)) {
+               ret = do_read_write(dev, 0, argc, argv);
+               if (ret > 0)
+                       return CMD_RET_USAGE;
+       } else if (0 == strcmp("write", cmd)) {
+               ret = do_read_write(dev, 1, argc, argv);
+               if (ret > 0)
+                       return CMD_RET_USAGE;
+       } else if (0 == strcmp("erase", cmd)) {
+               int region = cros_ec_decode_region(argc - 2, argv + 2);
+               uint32_t offset, size;
+
+               if (region == -1)
+                       return CMD_RET_USAGE;
+               if (cros_ec_flash_offset(dev, region, &offset, &size)) {
+                       debug("%s: Could not read region info\n", __func__);
+                       ret = -1;
+               } else {
+                       ret = cros_ec_flash_erase(dev, offset, size);
+                       if (ret) {
+                               debug("%s: Could not erase region\n",
+                                     __func__);
+                       }
+               }
+       } else if (0 == strcmp("regioninfo", cmd)) {
+               int region = cros_ec_decode_region(argc - 2, argv + 2);
+               uint32_t offset, size;
+
+               if (region == -1)
+                       return CMD_RET_USAGE;
+               ret = cros_ec_flash_offset(dev, region, &offset, &size);
+               if (ret) {
+                       debug("%s: Could not read region info\n", __func__);
+               } else {
+                       printf("Region: %s\n", region == EC_FLASH_REGION_RO ?
+                                       "RO" : "RW");
+                       printf("Offset: %x\n", offset);
+                       printf("Size:   %x\n", size);
+               }
+       } else if (0 == strcmp("vbnvcontext", cmd)) {
+               uint8_t block[EC_VBNV_BLOCK_SIZE];
+               char buf[3];
+               int i, len;
+               unsigned long result;
+
+               if (argc <= 2) {
+                       ret = cros_ec_read_vbnvcontext(dev, block);
+                       if (!ret) {
+                               printf("vbnv_block: ");
+                               for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++)
+                                       printf("%02x", block[i]);
+                               putc('\n');
+                       }
+               } else {
+                       /*
+                        * TODO(clchiou): Move this to a utility function as
+                        * cmd_spi might want to call it.
+                        */
+                       memset(block, 0, EC_VBNV_BLOCK_SIZE);
+                       len = strlen(argv[2]);
+                       buf[2] = '\0';
+                       for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++) {
+                               if (i * 2 >= len)
+                                       break;
+                               buf[0] = argv[2][i * 2];
+                               if (i * 2 + 1 >= len)
+                                       buf[1] = '0';
+                               else
+                                       buf[1] = argv[2][i * 2 + 1];
+                               strict_strtoul(buf, 16, &result);
+                               block[i] = result;
+                       }
+                       ret = cros_ec_write_vbnvcontext(dev, block);
+               }
+               if (ret) {
+                       debug("%s: Could not %s VbNvContext\n", __func__,
+                                       argc <= 2 ?  "read" : "write");
+               }
+       } else if (0 == strcmp("test", cmd)) {
+               int result = cros_ec_test(dev);
+
+               if (result)
+                       printf("Test failed with error %d\n", result);
+               else
+                       puts("Test passed\n");
+       } else if (0 == strcmp("version", cmd)) {
+               struct ec_response_get_version *p;
+               char *build_string;
+
+               ret = cros_ec_read_version(dev, &p);
+               if (!ret) {
+                       /* Print versions */
+                       printf("RO version:    %1.*s\n",
+                              sizeof(p->version_string_ro),
+                              p->version_string_ro);
+                       printf("RW version:    %1.*s\n",
+                              sizeof(p->version_string_rw),
+                              p->version_string_rw);
+                       printf("Firmware copy: %s\n",
+                               (p->current_image <
+                                       ARRAY_SIZE(ec_current_image_name) ?
+                               ec_current_image_name[p->current_image] :
+                               "?"));
+                       ret = cros_ec_read_build_info(dev, &build_string);
+                       if (!ret)
+                               printf("Build info:    %s\n", build_string);
+               }
+       } else if (0 == strcmp("ldo", cmd)) {
+               uint8_t index, state;
+               char *endp;
+
+               if (argc < 3)
+                       return CMD_RET_USAGE;
+               index = simple_strtoul(argv[2], &endp, 10);
+               if (*argv[2] == 0 || *endp != 0)
+                       return CMD_RET_USAGE;
+               if (argc > 3) {
+                       state = simple_strtoul(argv[3], &endp, 10);
+                       if (*argv[3] == 0 || *endp != 0)
+                               return CMD_RET_USAGE;
+                       ret = cros_ec_set_ldo(dev, index, state);
+               } else {
+                       ret = cros_ec_get_ldo(dev, index, &state);
+                       if (!ret) {
+                               printf("LDO%d: %s\n", index,
+                                       state == EC_LDO_STATE_ON ?
+                                       "on" : "off");
+                       }
+               }
+
+               if (ret) {
+                       debug("%s: Could not access LDO%d\n", __func__, index);
+                       return ret;
+               }
+       } else {
+               return CMD_RET_USAGE;
+       }
+
+       if (ret < 0) {
+               printf("Error: CROS-EC command failed (error %d)\n", ret);
+               ret = 1;
+       }
+
+       return ret;
+}
+
+U_BOOT_CMD(
+       crosec, 5,      1,      do_cros_ec,
+       "CROS-EC utility command",
+       "init                Re-init CROS-EC (done on startup automatically)\n"
+       "crosec id                  Read CROS-EC ID\n"
+       "crosec info                Read CROS-EC info\n"
+       "crosec curimage            Read CROS-EC current image\n"
+       "crosec hash                Read CROS-EC hash\n"
+       "crosec reboot [rw | ro | cold]  Reboot CROS-EC\n"
+       "crosec events              Read CROS-EC host events\n"
+       "crosec clrevents [mask]    Clear CROS-EC host events\n"
+       "crosec regioninfo <ro|rw>  Read image info\n"
+       "crosec erase <ro|rw>       Erase EC image\n"
+       "crosec read <ro|rw> <addr> [<size>]   Read EC image\n"
+       "crosec write <ro|rw> <addr> [<size>]  Write EC image\n"
+       "crosec vbnvcontext [hexstring]        Read [write] VbNvContext from EC\n"
+       "crosec ldo <idx> [<state>] Switch/Read LDO state\n"
+       "crosec test                run tests on cros_ec\n"
+       "crosec version             Read CROS-EC version"
+);
+#endif
diff --git a/include/cros_ec.h b/include/cros_ec.h
new file mode 100644
index 0000000..335d5b4
--- /dev/null
+++ b/include/cros_ec.h
@@ -0,0 +1,449 @@
+/*
+ * Chromium OS cros_ec driver
+ *
+ * Copyright (c) 2012 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _CROS_EC_H
+#define _CROS_EC_H
+
+#include <linux/compiler.h>
+#include <ec_commands.h>
+#include <fdtdec.h>
+#include <cros_ec_message.h>
+
+/* Which interface is the device on? */
+enum cros_ec_interface_t {
+       CROS_EC_IF_NONE,
+       CROS_EC_IF_SPI,
+       CROS_EC_IF_I2C,
+       CROS_EC_IF_LPC, /* Intel Low Pin Count interface */
+};
+
+/* Our configuration information */
+struct cros_ec_dev {
+       enum cros_ec_interface_t interface;
+       struct spi_slave *spi;          /* Our SPI slave, if using SPI */
+       int node;                       /* Our node */
+       int parent_node;                /* Our parent node (interface) */
+       unsigned int cs;                /* Our chip select */
+       unsigned int addr;              /* Device address (for I2C) */
+       unsigned int bus_num;           /* Bus number (for I2C) */
+       unsigned int max_frequency;     /* Maximum interface frequency */
+       struct fdt_gpio_state ec_int;   /* GPIO used as EC interrupt line */
+       int cmd_version_is_supported;   /* Device supports command versions */
+       int optimise_flash_write;       /* Don't write erased flash blocks */
+
+       /*
+        * These two buffers will always be dword-aligned and include enough
+        * space for up to 7 word-alignment bytes also, so we can ensure that
+        * the body of the message is always dword-aligned (64-bit).
+        *
+        * We use this alignment to keep ARM and x86 happy. Probably word
+        * alignment would be OK, there might be a small performance advantage
+        * to using dword.
+        */
+       uint8_t din[ALIGN(MSG_BYTES + sizeof(int64_t), sizeof(int64_t))]
+               __aligned(sizeof(int64_t));
+       uint8_t dout[ALIGN(MSG_BYTES + sizeof(int64_t), sizeof(int64_t))]
+               __aligned(sizeof(int64_t));
+};
+
+/*
+ * Hard-code the number of columns we happen to know we have right now.  It
+ * would be more correct to call cros_ec_info() at startup and determine the
+ * actual number of keyboard cols from there.
+ */
+#define CROS_EC_KEYSCAN_COLS 13
+
+/* Information returned by a key scan */
+struct mbkp_keyscan {
+       uint8_t data[CROS_EC_KEYSCAN_COLS];
+};
+
+/**
+ * Read the ID of the CROS-EC device
+ *
+ * The ID is a string identifying the CROS-EC device.
+ *
+ * @param dev          CROS-EC device
+ * @param id           Place to put the ID
+ * @param maxlen       Maximum length of the ID field
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen);
+
+/**
+ * Read a keyboard scan from the CROS-EC device
+ *
+ * Send a message requesting a keyboard scan and return the result
+ *
+ * @param dev          CROS-EC device
+ * @param scan         Place to put the scan results
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_scan_keyboard(struct cros_ec_dev *dev, struct mbkp_keyscan *scan);
+
+/**
+ * Read which image is currently running on the CROS-EC device.
+ *
+ * @param dev          CROS-EC device
+ * @param image                Destination for image identifier
+ * @return 0 if ok, <0 on error
+ */
+int cros_ec_read_current_image(struct cros_ec_dev *dev,
+               enum ec_current_image *image);
+
+/**
+ * Read the hash of the CROS-EC device firmware.
+ *
+ * @param dev          CROS-EC device
+ * @param hash         Destination for hash information
+ * @return 0 if ok, <0 on error
+ */
+int cros_ec_read_hash(struct cros_ec_dev *dev,
+               struct ec_response_vboot_hash *hash);
+
+/**
+ * Send a reboot command to the CROS-EC device.
+ *
+ * Note that some reboot commands (such as EC_REBOOT_COLD) also reboot the AP.
+ *
+ * @param dev          CROS-EC device
+ * @param cmd          Reboot command
+ * @param flags         Flags for reboot command (EC_REBOOT_FLAG_*)
+ * @return 0 if ok, <0 on error
+ */
+int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd,
+               uint8_t flags);
+
+/**
+ * Check if the CROS-EC device has an interrupt pending.
+ *
+ * Read the status of the external interrupt connected to the CROS-EC device.
+ * If no external interrupt is configured, this always returns 1.
+ *
+ * @param dev          CROS-EC device
+ * @return 0 if no interrupt is pending
+ */
+int cros_ec_interrupt_pending(struct cros_ec_dev *dev);
+
+enum {
+       CROS_EC_OK,
+       CROS_EC_ERR = 1,
+       CROS_EC_ERR_FDT_DECODE,
+       CROS_EC_ERR_CHECK_VERSION,
+       CROS_EC_ERR_READ_ID,
+       CROS_EC_ERR_DEV_INIT,
+};
+
+/**
+ * Set up the Chromium OS matrix keyboard protocol
+ *
+ * @param blob         Device tree blob containing setup information
+ * @param cros_ecp        Returns pointer to the cros_ec device, or NULL if none
+ * @return 0 if we got an cros_ec device and all is well (or no cros_ec is
+ *     expected), -ve if we should have an cros_ec device but failed to find
+ *     one, or init failed (-CROS_EC_ERR_...).
+ */
+int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp);
+
+/**
+ * Read information about the keyboard matrix
+ *
+ * @param dev          CROS-EC device
+ * @param info         Place to put the info structure
+ */
+int cros_ec_info(struct cros_ec_dev *dev,
+               struct ec_response_cros_ec_info *info);
+
+/**
+ * Read the host event flags
+ *
+ * @param dev          CROS-EC device
+ * @param events_ptr   Destination for event flags.  Not changed on error.
+ * @return 0 if ok, <0 on error
+ */
+int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr);
+
+/**
+ * Clear the specified host event flags
+ *
+ * @param dev          CROS-EC device
+ * @param events       Event flags to clear
+ * @return 0 if ok, <0 on error
+ */
+int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events);
+
+/**
+ * Get/set flash protection
+ *
+ * @param dev          CROS-EC device
+ * @param set_mask     Mask of flags to set; if 0, just retrieves existing
+ *                      protection state without changing it.
+ * @param set_flags    New flag values; only bits in set_mask are applied;
+ *                      ignored if set_mask=0.
+ * @param prot          Destination for updated protection state from EC.
+ * @return 0 if ok, <0 on error
+ */
+int cros_ec_flash_protect(struct cros_ec_dev *dev,
+                      uint32_t set_mask, uint32_t set_flags,
+                      struct ec_response_flash_protect *resp);
+
+
+/**
+ * Run internal tests on the cros_ec interface.
+ *
+ * @param dev          CROS-EC device
+ * @return 0 if ok, <0 if the test failed
+ */
+int cros_ec_test(struct cros_ec_dev *dev);
+
+/**
+ * Update the EC RW copy.
+ *
+ * @param dev          CROS-EC device
+ * @param image                the content to write
+ * @param imafge_size  content length
+ * @return 0 if ok, <0 if the test failed
+ */
+int cros_ec_flash_update_rw(struct cros_ec_dev *dev,
+                        const uint8_t  *image, int image_size);
+
+/**
+ * Return a pointer to the board's CROS-EC device
+ *
+ * This should be implemented by board files.
+ *
+ * @return pointer to CROS-EC device, or NULL if none is available
+ */
+struct cros_ec_dev *board_get_cros_ec_dev(void);
+
+
+/* Internal interfaces */
+int cros_ec_i2c_init(struct cros_ec_dev *dev, const void *blob);
+int cros_ec_spi_init(struct cros_ec_dev *dev, const void *blob);
+int cros_ec_lpc_init(struct cros_ec_dev *dev, const void *blob);
+
+/**
+ * Read information from the fdt for the i2c cros_ec interface
+ *
+ * @param dev          CROS-EC device
+ * @param blob         Device tree blob
+ * @return 0 if ok, -1 if we failed to read all required information
+ */
+int cros_ec_i2c_decode_fdt(struct cros_ec_dev *dev, const void *blob);
+
+/**
+ * Read information from the fdt for the spi cros_ec interface
+ *
+ * @param dev          CROS-EC device
+ * @param blob         Device tree blob
+ * @return 0 if ok, -1 if we failed to read all required information
+ */
+int cros_ec_spi_decode_fdt(struct cros_ec_dev *dev, const void *blob);
+
+/**
+ * Check whether the LPC interface supports new-style commands.
+ *
+ * LPC has its own way of doing this, which involves checking LPC values
+ * visible to the host. Do this, and update dev->cmd_version_is_supported
+ * accordingly.
+ *
+ * @param dev          CROS-EC device to check
+ */
+int cros_ec_lpc_check_version(struct cros_ec_dev *dev);
+
+/**
+ * Send a command to an I2C CROS-EC device and return the reply.
+ *
+ * This rather complicated function deals with sending both old-style and
+ * new-style commands. The old ones have just a command byte and arguments.
+ * The new ones have version, command, arg-len, [args], chksum so are 3 bytes
+ * longer.
+ *
+ * The device's internal input/output buffers are used.
+ *
+ * @param dev          CROS-EC device
+ * @param cmd          Command to send (EC_CMD_...)
+ * @param cmd_version  Version of command to send (EC_VER_...)
+ * @param dout          Output data (may be NULL If dout_len=0)
+ * @param dout_len      Size of output data in bytes
+ * @param dinp          Returns pointer to response data
+ * @param din_len       Maximum size of response in bytes
+ * @return number of bytes in response, or -1 on error
+ */
+int cros_ec_i2c_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
+                    const uint8_t *dout, int dout_len,
+                    uint8_t **dinp, int din_len);
+
+/**
+ * Send a command to a LPC CROS-EC device and return the reply.
+ *
+ * The device's internal input/output buffers are used.
+ *
+ * @param dev          CROS-EC device
+ * @param cmd          Command to send (EC_CMD_...)
+ * @param cmd_version  Version of command to send (EC_VER_...)
+ * @param dout          Output data (may be NULL If dout_len=0)
+ * @param dout_len      Size of output data in bytes
+ * @param dinp          Returns pointer to response data
+ * @param din_len       Maximum size of response in bytes
+ * @return number of bytes in response, or -1 on error
+ */
+int cros_ec_lpc_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
+                    const uint8_t *dout, int dout_len,
+                    uint8_t **dinp, int din_len);
+
+int cros_ec_spi_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
+                    const uint8_t *dout, int dout_len,
+                    uint8_t **dinp, int din_len);
+
+/**
+ * Dump a block of data for a command.
+ *
+ * @param name Name for data (e.g. 'in', 'out')
+ * @param cmd  Command number associated with data, or -1 for none
+ * @param data Data block to dump
+ * @param len  Length of data block to dump
+ */
+void cros_ec_dump_data(const char *name, int cmd, const uint8_t *data, int len);
+
+/**
+ * Calculate a simple 8-bit checksum of a data block
+ *
+ * @param data Data block to checksum
+ * @param size Size of data block in bytes
+ * @return checksum value (0 to 255)
+ */
+int cros_ec_calc_checksum(const uint8_t *data, int size);
+
+/**
+ * Decode a flash region parameter
+ *
+ * @param argc Number of params remaining
+ * @param argv List of remaining parameters
+ * @return flash region (EC_FLASH_REGION_...) or -1 on error
+ */
+int cros_ec_decode_region(int argc, char * const argv[]);
+
+int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset,
+               uint32_t size);
+
+/**
+ * Read data from the flash
+ *
+ * Read an arbitrary amount of data from the EC flash, by repeatedly reading
+ * small blocks.
+ *
+ * The offset starts at 0. You can obtain the region information from
+ * cros_ec_flash_offset() to find out where to read for a particular region.
+ *
+ * @param dev          CROS-EC device
+ * @param data         Pointer to data buffer to read into
+ * @param offset       Offset within flash to read from
+ * @param size         Number of bytes to read
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset,
+                   uint32_t size);
+
+/**
+ * Write data to the flash
+ *
+ * Write an arbitrary amount of data to the EC flash, by repeatedly writing
+ * small blocks.
+ *
+ * The offset starts at 0. You can obtain the region information from
+ * cros_ec_flash_offset() to find out where to write for a particular region.
+ *
+ * Attempting to write to the region where the EC is currently running from
+ * will result in an error.
+ *
+ * @param dev          CROS-EC device
+ * @param data         Pointer to data buffer to write
+ * @param offset       Offset within flash to write to.
+ * @param size         Number of bytes to write
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data,
+                    uint32_t offset, uint32_t size);
+
+/**
+ * Obtain position and size of a flash region
+ *
+ * @param dev          CROS-EC device
+ * @param region       Flash region to query
+ * @param offset       Returns offset of flash region in EC flash
+ * @param size         Returns size of flash region
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_flash_offset(struct cros_ec_dev *dev, enum ec_flash_region region,
+                     uint32_t *offset, uint32_t *size);
+
+/**
+ * Read/write VbNvContext from/to a CROS-EC device.
+ *
+ * @param dev          CROS-EC device
+ * @param block                Buffer of VbNvContext to be read/write
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_read_vbnvcontext(struct cros_ec_dev *dev, uint8_t *block);
+int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block);
+
+/**
+ * Read the version information for the EC images
+ *
+ * @param dev          CROS-EC device
+ * @param versionp     This is set to point to the version information
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_read_version(struct cros_ec_dev *dev,
+                      struct ec_response_get_version **versionp);
+
+/**
+ * Read the build information for the EC
+ *
+ * @param dev          CROS-EC device
+ * @param versionp     This is set to point to the build string
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp);
+
+/**
+ * Switch on/off a LDO / FET.
+ *
+ * @param dev          CROS-EC device
+ * @param index                index of the LDO/FET to switch
+ * @param state                new state of the LDO/FET : EC_LDO_STATE_ON|OFF
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_set_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t state);
+
+/**
+ * Read back a LDO / FET current state.
+ *
+ * @param dev          CROS-EC device
+ * @param index                index of the LDO/FET to switch
+ * @param state                current state of the LDO/FET : EC_LDO_STATE_ON|OFF
+ * @return 0 if ok, -1 on error
+ */
+int cros_ec_get_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t *state);
+#endif
diff --git a/include/cros_ec_message.h b/include/cros_ec_message.h
new file mode 100644
index 0000000..a2421c7
--- /dev/null
+++ b/include/cros_ec_message.h
@@ -0,0 +1,44 @@
+/*
+ * Chromium OS Matrix Keyboard Message Protocol definitions
+ *
+ * Copyright (c) 2012 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _CROS_MESSAGE_H
+#define _CROS_MESSAGE_H
+
+/*
+ * Command interface between EC and AP, for LPC, I2C and SPI interfaces.
+ *
+ * This is copied from the Chromium OS Open Source Embedded Controller code.
+ */
+enum {
+       /* The header byte, which follows the preamble */
+       MSG_HEADER      = 0xec,
+
+       MSG_HEADER_BYTES        = 3,
+       MSG_TRAILER_BYTES       = 2,
+       MSG_PROTO_BYTES         = MSG_HEADER_BYTES + MSG_TRAILER_BYTES,
+
+       /* Max length of messages */
+       MSG_BYTES               = EC_HOST_PARAM_SIZE + MSG_PROTO_BYTES,
+};
+
+#endif
diff --git a/include/ec_commands.h b/include/ec_commands.h
new file mode 100644
index 0000000..12811cc
--- /dev/null
+++ b/include/ec_commands.h
@@ -0,0 +1,1440 @@
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Host communication command constants for Chrome EC */
+
+#ifndef __CROS_EC_COMMANDS_H
+#define __CROS_EC_COMMANDS_H
+
+/*
+ * Protocol overview
+ *
+ * request:  CMD [ P0 P1 P2 ... Pn S ]
+ * response: ERR [ P0 P1 P2 ... Pn S ]
+ *
+ * where the bytes are defined as follow :
+ *      - CMD is the command code. (defined by EC_CMD_ constants)
+ *      - ERR is the error code. (defined by EC_RES_ constants)
+ *      - Px is the optional payload.
+ *        it is not sent if the error code is not success.
+ *        (defined by ec_params_ and ec_response_ structures)
+ *      - S is the checksum which is the sum of all payload bytes.
+ *
+ * On LPC, CMD and ERR are sent/received at EC_LPC_ADDR_KERNEL|USER_CMD
+ * and the payloads are sent/received at EC_LPC_ADDR_KERNEL|USER_PARAM.
+ * On I2C, all bytes are sent serially in the same message.
+ */
+
+/* Current version of this protocol */
+#define EC_PROTO_VERSION          0x00000002
+
+/* Command version mask */
+#define EC_VER_MASK(version) (1UL << (version))
+
+/* I/O addresses for ACPI commands */
+#define EC_LPC_ADDR_ACPI_DATA  0x62
+#define EC_LPC_ADDR_ACPI_CMD   0x66
+
+/* I/O addresses for host command */
+#define EC_LPC_ADDR_HOST_DATA  0x200
+#define EC_LPC_ADDR_HOST_CMD   0x204
+
+/* I/O addresses for host command args and params */
+#define EC_LPC_ADDR_HOST_ARGS  0x800
+#define EC_LPC_ADDR_HOST_PARAM 0x804
+#define EC_HOST_PARAM_SIZE     0x0fc  /* Size of param area in bytes */
+
+/* I/O addresses for host command params, old interface */
+#define EC_LPC_ADDR_OLD_PARAM  0x880
+#define EC_OLD_PARAM_SIZE      0x080  /* Size of param area in bytes */
+
+/* EC command register bit functions */
+#define EC_LPC_CMDR_DATA       (1 << 0)  /* Data ready for host to read */
+#define EC_LPC_CMDR_PENDING    (1 << 1)  /* Write pending to EC */
+#define EC_LPC_CMDR_BUSY       (1 << 2)  /* EC is busy processing a command */
+#define EC_LPC_CMDR_CMD                (1 << 3)  /* Last host write was a command */
+#define EC_LPC_CMDR_ACPI_BRST  (1 << 4)  /* Burst mode (not used) */
+#define EC_LPC_CMDR_SCI                (1 << 5)  /* SCI event is pending */
+#define EC_LPC_CMDR_SMI                (1 << 6)  /* SMI event is pending */
+
+#define EC_LPC_ADDR_MEMMAP       0x900
+#define EC_MEMMAP_SIZE         255 /* ACPI IO buffer max is 255 bytes */
+#define EC_MEMMAP_TEXT_MAX     8   /* Size of a string in the memory map */
+
+/* The offset address of each type of data in mapped memory. */
+#define EC_MEMMAP_TEMP_SENSOR      0x00 /* Temp sensors */
+#define EC_MEMMAP_FAN              0x10 /* Fan speeds */
+#define EC_MEMMAP_TEMP_SENSOR_B    0x18 /* Temp sensors (second set) */
+#define EC_MEMMAP_ID               0x20 /* 'E' 'C' */
+#define EC_MEMMAP_ID_VERSION       0x22 /* Version of data in 0x20 - 0x2f */
+#define EC_MEMMAP_THERMAL_VERSION  0x23 /* Version of data in 0x00 - 0x1f */
+#define EC_MEMMAP_BATTERY_VERSION  0x24 /* Version of data in 0x40 - 0x7f */
+#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
+#define EC_MEMMAP_EVENTS_VERSION   0x26 /* Version of data in 0x34 - 0x3f */
+#define EC_MEMMAP_HOST_CMD_FLAGS   0x27 /* Host command interface flags */
+#define EC_MEMMAP_SWITCHES         0x30
+#define EC_MEMMAP_HOST_EVENTS      0x34
+#define EC_MEMMAP_BATT_VOLT        0x40 /* Battery Present Voltage */
+#define EC_MEMMAP_BATT_RATE        0x44 /* Battery Present Rate */
+#define EC_MEMMAP_BATT_CAP         0x48 /* Battery Remaining Capacity */
+#define EC_MEMMAP_BATT_FLAG        0x4c /* Battery State, defined below */
+#define EC_MEMMAP_BATT_DCAP        0x50 /* Battery Design Capacity */
+#define EC_MEMMAP_BATT_DVLT        0x54 /* Battery Design Voltage */
+#define EC_MEMMAP_BATT_LFCC        0x58 /* Battery Last Full Charge Capacity */
+#define EC_MEMMAP_BATT_CCNT        0x5c /* Battery Cycle Count */
+#define EC_MEMMAP_BATT_MFGR        0x60 /* Battery Manufacturer String */
+#define EC_MEMMAP_BATT_MODEL       0x68 /* Battery Model Number String */
+#define EC_MEMMAP_BATT_SERIAL      0x70 /* Battery Serial Number String */
+#define EC_MEMMAP_BATT_TYPE        0x78 /* Battery Type String */
+
+/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
+#define EC_TEMP_SENSOR_ENTRIES     16
+/*
+ * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
+ *
+ * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
+ */
+#define EC_TEMP_SENSOR_B_ENTRIES      8
+#define EC_TEMP_SENSOR_NOT_PRESENT    0xff
+#define EC_TEMP_SENSOR_ERROR          0xfe
+#define EC_TEMP_SENSOR_NOT_POWERED    0xfd
+#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
+/*
+ * The offset of temperature value stored in mapped memory.  This allows
+ * reporting a temperature range of 200K to 454K = -73C to 181C.
+ */
+#define EC_TEMP_SENSOR_OFFSET      200
+
+#define EC_FAN_SPEED_ENTRIES       4       /* Number of fans at EC_MEMMAP_FAN */
+#define EC_FAN_SPEED_NOT_PRESENT   0xffff  /* Entry not present */
+#define EC_FAN_SPEED_STALLED       0xfffe  /* Fan stalled */
+
+/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
+#define EC_BATT_FLAG_AC_PRESENT   0x01
+#define EC_BATT_FLAG_BATT_PRESENT 0x02
+#define EC_BATT_FLAG_DISCHARGING  0x04
+#define EC_BATT_FLAG_CHARGING     0x08
+#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
+
+/* Switch flags at EC_MEMMAP_SWITCHES */
+#define EC_SWITCH_LID_OPEN               0x01
+#define EC_SWITCH_POWER_BUTTON_PRESSED   0x02
+#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
+/* Recovery requested via keyboard */
+#define EC_SWITCH_KEYBOARD_RECOVERY      0x08
+/* Recovery requested via dedicated signal (from servo board) */
+#define EC_SWITCH_DEDICATED_RECOVERY     0x10
+/* Was fake developer mode switch; now unused.  Remove in next refactor. */
+#define EC_SWITCH_IGNORE0                0x20
+
+/* Host command interface flags */
+/* Host command interface supports LPC args (LPC interface only) */
+#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED  0x01
+
+/* Wireless switch flags */
+#define EC_WIRELESS_SWITCH_WLAN      0x01
+#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02
+
+/*
+ * This header file is used in coreboot both in C and ACPI code.  The ACPI code
+ * is pre-processed to handle constants but the ASL compiler is unable to
+ * handle actual C code so keep it separate.
+ */
+#ifndef __ACPI__
+
+/*
+ * Define __packed if someone hasn't beat us to it.  Linux kernel style
+ * checking prefers __packed over __attribute__((packed)).
+ */
+#ifndef __packed
+#define __packed __attribute__((packed))
+#endif
+
+/* LPC command status byte masks */
+/* EC has written a byte in the data register and host hasn't read it yet */
+#define EC_LPC_STATUS_TO_HOST     0x01
+/* Host has written a command/data byte and the EC hasn't read it yet */
+#define EC_LPC_STATUS_FROM_HOST   0x02
+/* EC is processing a command */
+#define EC_LPC_STATUS_PROCESSING  0x04
+/* Last write to EC was a command, not data */
+#define EC_LPC_STATUS_LAST_CMD    0x08
+/* EC is in burst mode.  Unsupported by Chrome EC, so this bit is never set */
+#define EC_LPC_STATUS_BURST_MODE  0x10
+/* SCI event is pending (requesting SCI query) */
+#define EC_LPC_STATUS_SCI_PENDING 0x20
+/* SMI event is pending (requesting SMI query) */
+#define EC_LPC_STATUS_SMI_PENDING 0x40
+/* (reserved) */
+#define EC_LPC_STATUS_RESERVED    0x80
+
+/*
+ * EC is busy.  This covers both the EC processing a command, and the host has
+ * written a new command but the EC hasn't picked it up yet.
+ */
+#define EC_LPC_STATUS_BUSY_MASK \
+       (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
+
+/* Host command response codes */
+enum ec_status {
+       EC_RES_SUCCESS = 0,
+       EC_RES_INVALID_COMMAND = 1,
+       EC_RES_ERROR = 2,
+       EC_RES_INVALID_PARAM = 3,
+       EC_RES_ACCESS_DENIED = 4,
+       EC_RES_INVALID_RESPONSE = 5,
+       EC_RES_INVALID_VERSION = 6,
+       EC_RES_INVALID_CHECKSUM = 7,
+       EC_RES_IN_PROGRESS = 8,         /* Accepted, command in progress */
+       EC_RES_UNAVAILABLE = 9,         /* No response available */
+       EC_RES_TIMEOUT = 10,            /* We got a timeout */
+       EC_RES_OVERFLOW = 11,           /* Table / data overflow */
+};
+
+/*
+ * Host event codes.  Note these are 1-based, not 0-based, because ACPI query
+ * EC command uses code 0 to mean "no event pending".  We explicitly specify
+ * each value in the enum listing so they won't change if we delete/insert an
+ * item or rearrange the list (it needs to be stable across platforms, not
+ * just within a single compiled instance).
+ */
+enum host_event_code {
+       EC_HOST_EVENT_LID_CLOSED = 1,
+       EC_HOST_EVENT_LID_OPEN = 2,
+       EC_HOST_EVENT_POWER_BUTTON = 3,
+       EC_HOST_EVENT_AC_CONNECTED = 4,
+       EC_HOST_EVENT_AC_DISCONNECTED = 5,
+       EC_HOST_EVENT_BATTERY_LOW = 6,
+       EC_HOST_EVENT_BATTERY_CRITICAL = 7,
+       EC_HOST_EVENT_BATTERY = 8,
+       EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
+       EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
+       EC_HOST_EVENT_THERMAL = 11,
+       EC_HOST_EVENT_USB_CHARGER = 12,
+       EC_HOST_EVENT_KEY_PRESSED = 13,
+       /*
+        * EC has finished initializing the host interface.  The host can check
+        * for this event following sending a EC_CMD_REBOOT_EC command to
+        * determine when the EC is ready to accept subsequent commands.
+        */
+       EC_HOST_EVENT_INTERFACE_READY = 14,
+       /* Keyboard recovery combo has been pressed */
+       EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
+
+       /* Shutdown due to thermal overload */
+       EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
+       /* Shutdown due to battery level too low */
+       EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
+
+       /*
+        * The high bit of the event mask is not used as a host event code.  If
+        * it reads back as set, then the entire event mask should be
+        * considered invalid by the host.  This can happen when reading the
+        * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
+        * not initialized on the EC, or improperly configured on the host.
+        */
+       EC_HOST_EVENT_INVALID = 32
+};
+/* Host event mask */
+#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
+
+/* Arguments at EC_LPC_ADDR_HOST_ARGS */
+struct ec_lpc_host_args {
+       uint8_t flags;
+       uint8_t command_version;
+       uint8_t data_size;
+       /*
+        * Checksum; sum of command + flags + command_version + data_size +
+        * all params/response data bytes.
+        */
+       uint8_t checksum;
+} __packed;
+
+/* Flags for ec_lpc_host_args.flags */
+/*
+ * Args are from host.  Data area at EC_LPC_ADDR_HOST_PARAM contains command
+ * params.
+ *
+ * If EC gets a command and this flag is not set, this is an old-style command.
+ * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
+ * unknown length.  EC must respond with an old-style response (that is,
+ * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
+ */
+#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
+/*
+ * Args are from EC.  Data area at EC_LPC_ADDR_HOST_PARAM contains response.
+ *
+ * If EC responds to a command and this flag is not set, this is an old-style
+ * response.  Command version is 0 and response data from EC is at
+ * EC_LPC_ADDR_OLD_PARAM with unknown length.
+ */
+#define EC_HOST_ARGS_FLAG_TO_HOST   0x02
+
+/*
+ * Notes on commands:
+ *
+ * Each command is an 8-byte command value.  Commands which take params or
+ * return response data specify structs for that data.  If no struct is
+ * specified, the command does not input or output data, respectively.
+ * Parameter/response length is implicit in the structs.  Some underlying
+ * communication protocols (I2C, SPI) may add length or checksum headers, but
+ * those are implementation-dependent and not defined here.
+ */
+
+/*****************************************************************************/
+/* General / test commands */
+
+/*
+ * Get protocol version, used to deal with non-backward compatible protocol
+ * changes.
+ */
+#define EC_CMD_PROTO_VERSION 0x00
+
+struct ec_response_proto_version {
+       uint32_t version;
+} __packed;
+
+/*
+ * Hello.  This is a simple command to test the EC is responsive to
+ * commands.
+ */
+#define EC_CMD_HELLO 0x01
+
+struct ec_params_hello {
+       uint32_t in_data;  /* Pass anything here */
+} __packed;
+
+struct ec_response_hello {
+       uint32_t out_data;  /* Output will be in_data + 0x01020304 */
+} __packed;
+
+/* Get version number */
+#define EC_CMD_GET_VERSION 0x02
+
+enum ec_current_image {
+       EC_IMAGE_UNKNOWN = 0,
+       EC_IMAGE_RO,
+       EC_IMAGE_RW
+};
+
+struct ec_response_get_version {
+       /* Null-terminated version strings for RO, RW */
+       char version_string_ro[32];
+       char version_string_rw[32];
+       char reserved[32];       /* Was previously RW-B string */
+       uint32_t current_image;  /* One of ec_current_image */
+} __packed;
+
+/* Read test */
+#define EC_CMD_READ_TEST 0x03
+
+struct ec_params_read_test {
+       uint32_t offset;   /* Starting value for read buffer */
+       uint32_t size;     /* Size to read in bytes */
+} __packed;
+
+struct ec_response_read_test {
+       uint32_t data[32];
+} __packed;
+
+/*
+ * Get build information
+ *
+ * Response is null-terminated string.
+ */
+#define EC_CMD_GET_BUILD_INFO 0x04
+
+/* Get chip info */
+#define EC_CMD_GET_CHIP_INFO 0x05
+
+struct ec_response_get_chip_info {
+       /* Null-terminated strings */
+       char vendor[32];
+       char name[32];
+       char revision[32];  /* Mask version */
+} __packed;
+
+/* Get board HW version */
+#define EC_CMD_GET_BOARD_VERSION 0x06
+
+struct ec_response_board_version {
+       uint16_t board_version;  /* A monotonously incrementing number. */
+} __packed;
+
+/*
+ * Read memory-mapped data.
+ *
+ * This is an alternate interface to memory-mapped data for bus protocols
+ * which don't support direct-mapped memory - I2C, SPI, etc.
+ *
+ * Response is params.size bytes of data.
+ */
+#define EC_CMD_READ_MEMMAP 0x07
+
+struct ec_params_read_memmap {
+       uint8_t offset;   /* Offset in memmap (EC_MEMMAP_*) */
+       uint8_t size;     /* Size to read in bytes */
+} __packed;
+
+/* Read versions supported for a command */
+#define EC_CMD_GET_CMD_VERSIONS 0x08
+
+struct ec_params_get_cmd_versions {
+       uint8_t cmd;      /* Command to check */
+} __packed;
+
+struct ec_response_get_cmd_versions {
+       /*
+        * Mask of supported versions; use EC_VER_MASK() to compare with a
+        * desired version.
+        */
+       uint32_t version_mask;
+} __packed;
+
+/*
+ * Check EC communcations status (busy). This is needed on i2c/spi but not
+ * on lpc since it has its own out-of-band busy indicator.
+ *
+ * lpc must read the status from the command register. Attempting this on
+ * lpc will overwrite the args/parameter space and corrupt its data.
+ */
+#define EC_CMD_GET_COMMS_STATUS                0x09
+
+/* Avoid using ec_status which is for return values */
+enum ec_comms_status {
+       EC_COMMS_STATUS_PROCESSING      = 1 << 0,       /* Processing cmd */
+};
+
+struct ec_response_get_comms_status {
+       uint32_t flags;         /* Mask of enum ec_comms_status */
+} __packed;
+
+
+/*****************************************************************************/
+/* Flash commands */
+
+/* Get flash info */
+#define EC_CMD_FLASH_INFO 0x10
+
+struct ec_response_flash_info {
+       /* Usable flash size, in bytes */
+       uint32_t flash_size;
+       /*
+        * Write block size.  Write offset and size must be a multiple
+        * of this.
+        */
+       uint32_t write_block_size;
+       /*
+        * Erase block size.  Erase offset and size must be a multiple
+        * of this.
+        */
+       uint32_t erase_block_size;
+       /*
+        * Protection block size.  Protection offset and size must be a
+        * multiple of this.
+        */
+       uint32_t protect_block_size;
+} __packed;
+
+/*
+ * Read flash
+ *
+ * Response is params.size bytes of data.
+ */
+#define EC_CMD_FLASH_READ 0x11
+
+struct ec_params_flash_read {
+       uint32_t offset;   /* Byte offset to read */
+       uint32_t size;     /* Size to read in bytes */
+} __packed;
+
+/* Write flash */
+#define EC_CMD_FLASH_WRITE 0x12
+
+struct ec_params_flash_write {
+       uint32_t offset;   /* Byte offset to write */
+       uint32_t size;     /* Size to write in bytes */
+       /*
+        * Data to write.  Could really use EC_PARAM_SIZE - 8, but tidiest to
+        * use a power of 2 so writes stay aligned.
+        */
+       uint8_t data[64];
+} __packed;
+
+/* Erase flash */
+#define EC_CMD_FLASH_ERASE 0x13
+
+struct ec_params_flash_erase {
+       uint32_t offset;   /* Byte offset to erase */
+       uint32_t size;     /* Size to erase in bytes */
+} __packed;
+
+/*
+ * Get/set flash protection.
+ *
+ * If mask!=0, sets/clear the requested bits of flags.  Depending on the
+ * firmware write protect GPIO, not all flags will take effect immediately;
+ * some flags require a subsequent hard reset to take effect.  Check the
+ * returned flags bits to see what actually happened.
+ *
+ * If mask=0, simply returns the current flags state.
+ */
+#define EC_CMD_FLASH_PROTECT 0x15
+#define EC_VER_FLASH_PROTECT 1  /* Command version 1 */
+
+/* Flags for flash protection */
+/* RO flash code protected when the EC boots */
+#define EC_FLASH_PROTECT_RO_AT_BOOT         (1 << 0)
+/*
+ * RO flash code protected now.  If this bit is set, at-boot status cannot
+ * be changed.
+ */
+#define EC_FLASH_PROTECT_RO_NOW             (1 << 1)
+/* Entire flash code protected now, until reboot. */
+#define EC_FLASH_PROTECT_ALL_NOW            (1 << 2)
+/* Flash write protect GPIO is asserted now */
+#define EC_FLASH_PROTECT_GPIO_ASSERTED      (1 << 3)
+/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
+#define EC_FLASH_PROTECT_ERROR_STUCK        (1 << 4)
+/*
+ * Error - flash protection is in inconsistent state.  At least one bank of
+ * flash which should be protected is not protected.  Usually fixed by
+ * re-requesting the desired flags, or by a hard reset if that fails.
+ */
+#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
+/* Entile flash code protected when the EC boots */
+#define EC_FLASH_PROTECT_ALL_AT_BOOT        (1 << 6)
+
+struct ec_params_flash_protect {
+       uint32_t mask;   /* Bits in flags to apply */
+       uint32_t flags;  /* New flags to apply */
+} __packed;
+
+struct ec_response_flash_protect {
+       /* Current value of flash protect flags */
+       uint32_t flags;
+       /*
+        * Flags which are valid on this platform.  This allows the caller
+        * to distinguish between flags which aren't set vs. flags which can't
+        * be set on this platform.
+        */
+       uint32_t valid_flags;
+       /* Flags which can be changed given the current protection state */
+       uint32_t writable_flags;
+} __packed;
+
+/*
+ * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
+ * write protect.  These commands may be reused with version > 0.
+ */
+
+/* Get the region offset/size */
+#define EC_CMD_FLASH_REGION_INFO 0x16
+#define EC_VER_FLASH_REGION_INFO 1
+
+enum ec_flash_region {
+       /* Region which holds read-only EC image */
+       EC_FLASH_REGION_RO,
+       /* Region which holds rewritable EC image */
+       EC_FLASH_REGION_RW,
+       /*
+        * Region which should be write-protected in the factory (a superset of
+        * EC_FLASH_REGION_RO)
+        */
+       EC_FLASH_REGION_WP_RO,
+};
+
+struct ec_params_flash_region_info {
+       uint32_t region;  /* enum ec_flash_region */
+} __packed;
+
+struct ec_response_flash_region_info {
+       uint32_t offset;
+       uint32_t size;
+} __packed;
+
+/* Read/write VbNvContext */
+#define EC_CMD_VBNV_CONTEXT 0x17
+#define EC_VER_VBNV_CONTEXT 1
+#define EC_VBNV_BLOCK_SIZE 16
+
+enum ec_vbnvcontext_op {
+       EC_VBNV_CONTEXT_OP_READ,
+       EC_VBNV_CONTEXT_OP_WRITE,
+};
+
+struct ec_params_vbnvcontext {
+       uint32_t op;
+       uint8_t block[EC_VBNV_BLOCK_SIZE];
+} __packed;
+
+struct ec_response_vbnvcontext {
+       uint8_t block[EC_VBNV_BLOCK_SIZE];
+} __packed;
+
+/*****************************************************************************/
+/* PWM commands */
+
+/* Get fan target RPM */
+#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
+
+struct ec_response_pwm_get_fan_rpm {
+       uint32_t rpm;
+} __packed;
+
+/* Set target fan RPM */
+#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
+
+struct ec_params_pwm_set_fan_target_rpm {
+       uint32_t rpm;
+} __packed;
+
+/* Get keyboard backlight */
+#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
+
+struct ec_response_pwm_get_keyboard_backlight {
+       uint8_t percent;
+       uint8_t enabled;
+} __packed;
+
+/* Set keyboard backlight */
+#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
+
+struct ec_params_pwm_set_keyboard_backlight {
+       uint8_t percent;
+} __packed;
+
+/* Set target fan PWM duty cycle */
+#define EC_CMD_PWM_SET_FAN_DUTY 0x24
+
+struct ec_params_pwm_set_fan_duty {
+       uint32_t percent;
+} __packed;
+
+/*****************************************************************************/
+/*
+ * Lightbar commands. This looks worse than it is. Since we only use one HOST
+ * command to say "talk to the lightbar", we put the "and tell it to do X" part
+ * into a subcommand. We'll make separate structs for subcommands with
+ * different input args, so that we know how much to expect.
+ */
+#define EC_CMD_LIGHTBAR_CMD 0x28
+
+struct rgb_s {
+       uint8_t r, g, b;
+};
+
+#define LB_BATTERY_LEVELS 4
+/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
+ * host command, but the alignment is the same regardless. Keep it that way.
+ */
+struct lightbar_params {
+       /* Timing */
+       int google_ramp_up;
+       int google_ramp_down;
+       int s3s0_ramp_up;
+       int s0_tick_delay[2];                   /* AC=0/1 */
+       int s0a_tick_delay[2];                  /* AC=0/1 */
+       int s0s3_ramp_down;
+       int s3_sleep_for;
+       int s3_ramp_up;
+       int s3_ramp_down;
+
+       /* Oscillation */
+       uint8_t new_s0;
+       uint8_t osc_min[2];                     /* AC=0/1 */
+       uint8_t osc_max[2];                     /* AC=0/1 */
+       uint8_t w_ofs[2];                       /* AC=0/1 */
+
+       /* Brightness limits based on the backlight and AC. */
+       uint8_t bright_bl_off_fixed[2];         /* AC=0/1 */
+       uint8_t bright_bl_on_min[2];            /* AC=0/1 */
+       uint8_t bright_bl_on_max[2];            /* AC=0/1 */
+
+       /* Battery level thresholds */
+       uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
+
+       /* Map [AC][battery_level] to color index */
+       uint8_t s0_idx[2][LB_BATTERY_LEVELS];   /* AP is running */
+       uint8_t s3_idx[2][LB_BATTERY_LEVELS];   /* AP is sleeping */
+
+       /* Color palette */
+       struct rgb_s color[8];                  /* 0-3 are Google colors */
+} __packed;
+
+struct ec_params_lightbar {
+       uint8_t cmd;                  /* Command (see enum lightbar_command) */
+       union {
+               struct {
+                       /* no args */
+               } dump, off, on, init, get_seq, get_params;
+
+               struct num {
+                       uint8_t num;
+               } brightness, seq, demo;
+
+               struct reg {
+                       uint8_t ctrl, reg, value;
+               } reg;
+
+               struct rgb {
+                       uint8_t led, red, green, blue;
+               } rgb;
+
+               struct lightbar_params set_params;
+       };
+} __packed;
+
+struct ec_response_lightbar {
+       union {
+               struct dump {
+                       struct {
+                               uint8_t reg;
+                               uint8_t ic0;
+                               uint8_t ic1;
+                       } vals[23];
+               } dump;
+
+               struct get_seq {
+                       uint8_t num;
+               } get_seq;
+
+               struct lightbar_params get_params;
+
+               struct {
+                       /* no return params */
+               } off, on, init, brightness, seq, reg, rgb, demo, set_params;
+       };
+} __packed;
+
+/* Lightbar commands */
+enum lightbar_command {
+       LIGHTBAR_CMD_DUMP = 0,
+       LIGHTBAR_CMD_OFF = 1,
+       LIGHTBAR_CMD_ON = 2,
+       LIGHTBAR_CMD_INIT = 3,
+       LIGHTBAR_CMD_BRIGHTNESS = 4,
+       LIGHTBAR_CMD_SEQ = 5,
+       LIGHTBAR_CMD_REG = 6,
+       LIGHTBAR_CMD_RGB = 7,
+       LIGHTBAR_CMD_GET_SEQ = 8,
+       LIGHTBAR_CMD_DEMO = 9,
+       LIGHTBAR_CMD_GET_PARAMS = 10,
+       LIGHTBAR_CMD_SET_PARAMS = 11,
+       LIGHTBAR_NUM_CMDS
+};
+
+/*****************************************************************************/
+/* Verified boot commands */
+
+/*
+ * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
+ * reused for other purposes with version > 0.
+ */
+
+/* Verified boot hash command */
+#define EC_CMD_VBOOT_HASH 0x2A
+
+struct ec_params_vboot_hash {
+       uint8_t cmd;             /* enum ec_vboot_hash_cmd */
+       uint8_t hash_type;       /* enum ec_vboot_hash_type */
+       uint8_t nonce_size;      /* Nonce size; may be 0 */
+       uint8_t reserved0;       /* Reserved; set 0 */
+       uint32_t offset;         /* Offset in flash to hash */
+       uint32_t size;           /* Number of bytes to hash */
+       uint8_t nonce_data[64];  /* Nonce data; ignored if nonce_size=0 */
+} __packed;
+
+struct ec_response_vboot_hash {
+       uint8_t status;          /* enum ec_vboot_hash_status */
+       uint8_t hash_type;       /* enum ec_vboot_hash_type */
+       uint8_t digest_size;     /* Size of hash digest in bytes */
+       uint8_t reserved0;       /* Ignore; will be 0 */
+       uint32_t offset;         /* Offset in flash which was hashed */
+       uint32_t size;           /* Number of bytes hashed */
+       uint8_t hash_digest[64]; /* Hash digest data */
+} __packed;
+
+enum ec_vboot_hash_cmd {
+       EC_VBOOT_HASH_GET = 0,       /* Get current hash status */
+       EC_VBOOT_HASH_ABORT = 1,     /* Abort calculating current hash */
+       EC_VBOOT_HASH_START = 2,     /* Start computing a new hash */
+       EC_VBOOT_HASH_RECALC = 3,    /* Synchronously compute a new hash */
+};
+
+enum ec_vboot_hash_type {
+       EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
+};
+
+enum ec_vboot_hash_status {
+       EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
+       EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
+       EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
+};
+
+/*
+ * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
+ * If one of these is specified, the EC will automatically update offset and
+ * size to the correct values for the specified image (RO or RW).
+ */
+#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
+#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
+
+/*****************************************************************************/
+/* USB charging control commands */
+
+/* Set USB port charging mode */
+#define EC_CMD_USB_CHARGE_SET_MODE 0x30
+
+struct ec_params_usb_charge_set_mode {
+       uint8_t usb_port_id;
+       uint8_t mode;
+} __packed;
+
+/*****************************************************************************/
+/* Persistent storage for host */
+
+/* Maximum bytes that can be read/written in a single command */
+#define EC_PSTORE_SIZE_MAX 64
+
+/* Get persistent storage info */
+#define EC_CMD_PSTORE_INFO 0x40
+
+struct ec_response_pstore_info {
+       /* Persistent storage size, in bytes */
+       uint32_t pstore_size;
+       /* Access size; read/write offset and size must be a multiple of this */
+       uint32_t access_size;
+} __packed;
+
+/*
+ * Read persistent storage
+ *
+ * Response is params.size bytes of data.
+ */
+#define EC_CMD_PSTORE_READ 0x41
+
+struct ec_params_pstore_read {
+       uint32_t offset;   /* Byte offset to read */
+       uint32_t size;     /* Size to read in bytes */
+} __packed;
+
+/* Write persistent storage */
+#define EC_CMD_PSTORE_WRITE 0x42
+
+struct ec_params_pstore_write {
+       uint32_t offset;   /* Byte offset to write */
+       uint32_t size;     /* Size to write in bytes */
+       uint8_t data[EC_PSTORE_SIZE_MAX];
+} __packed;
+
+/*****************************************************************************/
+/* Real-time clock */
+
+/* RTC params and response structures */
+struct ec_params_rtc {
+       uint32_t time;
+} __packed;
+
+struct ec_response_rtc {
+       uint32_t time;
+} __packed;
+
+/* These use ec_response_rtc */
+#define EC_CMD_RTC_GET_VALUE 0x44
+#define EC_CMD_RTC_GET_ALARM 0x45
+
+/* These all use ec_params_rtc */
+#define EC_CMD_RTC_SET_VALUE 0x46
+#define EC_CMD_RTC_SET_ALARM 0x47
+
+/*****************************************************************************/
+/* Port80 log access */
+
+/* Get last port80 code from previous boot */
+#define EC_CMD_PORT80_LAST_BOOT 0x48
+
+struct ec_response_port80_last_boot {
+       uint16_t code;
+} __packed;
+
+/*****************************************************************************/
+/* Thermal engine commands */
+
+/* Set thershold value */
+#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
+
+struct ec_params_thermal_set_threshold {
+       uint8_t sensor_type;
+       uint8_t threshold_id;
+       uint16_t value;
+} __packed;
+
+/* Get threshold value */
+#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
+
+struct ec_params_thermal_get_threshold {
+       uint8_t sensor_type;
+       uint8_t threshold_id;
+} __packed;
+
+struct ec_response_thermal_get_threshold {
+       uint16_t value;
+} __packed;
+
+/* Toggle automatic fan control */
+#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
+
+/* Get TMP006 calibration data */
+#define EC_CMD_TMP006_GET_CALIBRATION 0x53
+
+struct ec_params_tmp006_get_calibration {
+       uint8_t index;
+} __packed;
+
+struct ec_response_tmp006_get_calibration {
+       float s0;
+       float b0;
+       float b1;
+       float b2;
+} __packed;
+
+/* Set TMP006 calibration data */
+#define EC_CMD_TMP006_SET_CALIBRATION 0x54
+
+struct ec_params_tmp006_set_calibration {
+       uint8_t index;
+       uint8_t reserved[3];  /* Reserved; set 0 */
+       float s0;
+       float b0;
+       float b1;
+       float b2;
+} __packed;
+
+/*****************************************************************************/
+/* CROS_EC - Matrix KeyBoard Protocol */
+
+/*
+ * Read key state
+ *
+ * Returns raw data for keyboard cols; see ec_response_cros_ec_info.cols for
+ * expected response size.
+ */
+#define EC_CMD_CROS_EC_STATE 0x60
+
+/* Provide information about the matrix : number of rows and columns */
+#define EC_CMD_CROS_EC_INFO 0x61
+
+struct ec_response_cros_ec_info {
+       uint32_t rows;
+       uint32_t cols;
+       uint8_t switches;
+} __packed;
+
+/* Simulate key press */
+#define EC_CMD_CROS_EC_SIMULATE_KEY 0x62
+
+struct ec_params_cros_ec_simulate_key {
+       uint8_t col;
+       uint8_t row;
+       uint8_t pressed;
+} __packed;
+
+/* Configure keyboard scanning */
+#define EC_CMD_CROS_EC_SET_CONFIG 0x64
+#define EC_CMD_CROS_EC_GET_CONFIG 0x65
+
+/* flags */
+enum cros_ec_config_flags {
+       EC_CROS_EC_FLAGS_ENABLE = 1,    /* Enable keyboard scanning */
+};
+
+enum cros_ec_config_valid {
+       EC_CROS_EC_VALID_SCAN_PERIOD            = 1 << 0,
+       EC_CROS_EC_VALID_POLL_TIMEOUT           = 1 << 1,
+       EC_CROS_EC_VALID_MIN_POST_SCAN_DELAY    = 1 << 3,
+       EC_CROS_EC_VALID_OUTPUT_SETTLE          = 1 << 4,
+       EC_CROS_EC_VALID_DEBOUNCE_DOWN          = 1 << 5,
+       EC_CROS_EC_VALID_DEBOUNCE_UP            = 1 << 6,
+       EC_CROS_EC_VALID_FIFO_MAX_DEPTH         = 1 << 7,
+};
+
+/* Configuration for our key scanning algorithm */
+struct ec_cros_ec_config {
+       uint32_t valid_mask;            /* valid fields */
+       uint8_t flags;          /* some flags (enum cros_ec_config_flags) */
+       uint8_t valid_flags;            /* which flags are valid */
+       uint16_t scan_period_us;        /* period between start of scans */
+       /* revert to interrupt mode after no activity for this long */
+       uint32_t poll_timeout_us;
+       /*
+        * minimum post-scan relax time. Once we finish a scan we check
+        * the time until we are due to start the next one. If this time is
+        * shorter this field, we use this instead.
+        */
+       uint16_t min_post_scan_delay_us;
+       /* delay between setting up output and waiting for it to settle */
+       uint16_t output_settle_us;
+       uint16_t debounce_down_us;      /* time for debounce on key down */
+       uint16_t debounce_up_us;        /* time for debounce on key up */
+       /* maximum depth to allow for fifo (0 = no keyscan output) */
+       uint8_t fifo_max_depth;
+} __packed;
+
+struct ec_params_cros_ec_set_config {
+       struct ec_cros_ec_config config;
+} __packed;
+
+struct ec_response_cros_ec_get_config {
+       struct ec_cros_ec_config config;
+} __packed;
+
+/* Run the key scan emulation */
+#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
+
+enum ec_keyscan_seq_cmd {
+       EC_KEYSCAN_SEQ_STATUS = 0,      /* Get status information */
+       EC_KEYSCAN_SEQ_CLEAR = 1,       /* Clear sequence */
+       EC_KEYSCAN_SEQ_ADD = 2,         /* Add item to sequence */
+       EC_KEYSCAN_SEQ_START = 3,       /* Start running sequence */
+       EC_KEYSCAN_SEQ_COLLECT = 4,     /* Collect sequence summary data */
+};
+
+enum ec_collect_flags {
+       /*
+        * Indicates this scan was processed by the EC. Due to timing, some
+        * scans may be skipped.
+        */
+       EC_KEYSCAN_SEQ_FLAG_DONE        = 1 << 0,
+};
+
+struct ec_collect_item {
+       uint8_t flags;          /* some flags (enum ec_collect_flags) */
+};
+
+struct ec_params_keyscan_seq_ctrl {
+       uint8_t cmd;    /* Command to send (enum ec_keyscan_seq_cmd) */
+       union {
+               struct {
+                       uint8_t active;         /* still active */
+                       uint8_t num_items;      /* number of items */
+                       /* Current item being presented */
+                       uint8_t cur_item;
+               } status;
+               struct {
+                       /*
+                        * Absolute time for this scan, measured from the
+                        * start of the sequence.
+                        */
+                       uint32_t time_us;
+                       uint8_t scan[0];        /* keyscan data */
+               } add;
+               struct {
+                       uint8_t start_item;     /* First item to return */
+                       uint8_t num_items;      /* Number of items to return */
+               } collect;
+       };
+} __packed;
+
+struct ec_result_keyscan_seq_ctrl {
+       union {
+               struct {
+                       uint8_t num_items;      /* Number of items */
+                       /* Data for each item */
+                       struct ec_collect_item item[0];
+               } collect;
+       };
+} __packed;
+
+/*****************************************************************************/
+/* Temperature sensor commands */
+
+/* Read temperature sensor info */
+#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
+
+struct ec_params_temp_sensor_get_info {
+       uint8_t id;
+} __packed;
+
+struct ec_response_temp_sensor_get_info {
+       char sensor_name[32];
+       uint8_t sensor_type;
+} __packed;
+
+/*****************************************************************************/
+
+/*
+ * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
+ * commands accidentally sent to the wrong interface.  See the ACPI section
+ * below.
+ */
+
+/*****************************************************************************/
+/* Host event commands */
+
+/*
+ * Host event mask params and response structures, shared by all of the host
+ * event commands below.
+ */
+struct ec_params_host_event_mask {
+       uint32_t mask;
+} __packed;
+
+struct ec_response_host_event_mask {
+       uint32_t mask;
+} __packed;
+
+/* These all use ec_response_host_event_mask */
+#define EC_CMD_HOST_EVENT_GET_B         0x87
+#define EC_CMD_HOST_EVENT_GET_SMI_MASK  0x88
+#define EC_CMD_HOST_EVENT_GET_SCI_MASK  0x89
+#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
+
+/* These all use ec_params_host_event_mask */
+#define EC_CMD_HOST_EVENT_SET_SMI_MASK  0x8a
+#define EC_CMD_HOST_EVENT_SET_SCI_MASK  0x8b
+#define EC_CMD_HOST_EVENT_CLEAR         0x8c
+#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
+#define EC_CMD_HOST_EVENT_CLEAR_B       0x8f
+
+/*****************************************************************************/
+/* Switch commands */
+
+/* Enable/disable LCD backlight */
+#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
+
+struct ec_params_switch_enable_backlight {
+       uint8_t enabled;
+} __packed;
+
+/* Enable/disable WLAN/Bluetooth */
+#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
+
+struct ec_params_switch_enable_wireless {
+       uint8_t enabled;
+} __packed;
+
+/*****************************************************************************/
+/* GPIO commands. Only available on EC if write protect has been disabled. */
+
+/* Set GPIO output value */
+#define EC_CMD_GPIO_SET 0x92
+
+struct ec_params_gpio_set {
+       char name[32];
+       uint8_t val;
+} __packed;
+
+/* Get GPIO value */
+#define EC_CMD_GPIO_GET 0x93
+
+struct ec_params_gpio_get {
+       char name[32];
+} __packed;
+struct ec_response_gpio_get {
+       uint8_t val;
+} __packed;
+
+/*****************************************************************************/
+/* I2C commands. Only available when flash write protect is unlocked. */
+
+/* Read I2C bus */
+#define EC_CMD_I2C_READ 0x94
+
+struct ec_params_i2c_read {
+       uint16_t addr;
+       uint8_t read_size; /* Either 8 or 16. */
+       uint8_t port;
+       uint8_t offset;
+} __packed;
+struct ec_response_i2c_read {
+       uint16_t data;
+} __packed;
+
+/* Write I2C bus */
+#define EC_CMD_I2C_WRITE 0x95
+
+struct ec_params_i2c_write {
+       uint16_t data;
+       uint16_t addr;
+       uint8_t write_size; /* Either 8 or 16. */
+       uint8_t port;
+       uint8_t offset;
+} __packed;
+
+/*****************************************************************************/
+/* Charge state commands. Only available when flash write protect unlocked. */
+
+/* Force charge state machine to stop in idle mode */
+#define EC_CMD_CHARGE_FORCE_IDLE 0x96
+
+struct ec_params_force_idle {
+       uint8_t enabled;
+} __packed;
+
+/*****************************************************************************/
+/* Console commands. Only available when flash write protect is unlocked. */
+
+/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
+#define EC_CMD_CONSOLE_SNAPSHOT 0x97
+
+/*
+ * Read next chunk of data from saved snapshot.
+ *
+ * Response is null-terminated string.  Empty string, if there is no more
+ * remaining output.
+ */
+#define EC_CMD_CONSOLE_READ 0x98
+
+/*****************************************************************************/
+
+/*
+ * Cut off battery power output if the battery supports.
+ *
+ * For unsupported battery, just don't implement this command and lets EC
+ * return EC_RES_INVALID_COMMAND.
+ */
+#define EC_CMD_BATTERY_CUT_OFF 0x99
+
+/*****************************************************************************/
+/* USB port mux control. */
+
+/*
+ * Switch USB mux or return to automatic switching.
+ */
+#define EC_CMD_USB_MUX 0x9a
+
+struct ec_params_usb_mux {
+       uint8_t mux;
+} __packed;
+
+/*****************************************************************************/
+/* LDOs / FETs control. */
+
+enum ec_ldo_state {
+       EC_LDO_STATE_OFF = 0,   /* the LDO / FET is shut down */
+       EC_LDO_STATE_ON = 1,    /* the LDO / FET is ON / providing power */
+};
+
+/*
+ * Switch on/off a LDO.
+ */
+#define EC_CMD_LDO_SET 0x9b
+
+struct ec_params_ldo_set {
+       uint8_t index;
+       uint8_t state;
+} __packed;
+
+/*
+ * Get LDO state.
+ */
+#define EC_CMD_LDO_GET 0x9c
+
+struct ec_params_ldo_get {
+       uint8_t index;
+} __packed;
+
+struct ec_response_ldo_get {
+       uint8_t state;
+} __packed;
+
+/*****************************************************************************/
+/* Temporary debug commands. TODO: remove this crosbug.com/p/13849 */
+
+/*
+ * Dump charge state machine context.
+ *
+ * Response is a binary dump of charge state machine context.
+ */
+#define EC_CMD_CHARGE_DUMP 0xa0
+
+/*
+ * Set maximum battery charging current.
+ */
+#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
+
+struct ec_params_current_limit {
+       uint32_t limit;
+} __packed;
+
+/*****************************************************************************/
+/* Smart battery pass-through */
+
+/* Get / Set 16-bit smart battery registers */
+#define EC_CMD_SB_READ_WORD   0xb0
+#define EC_CMD_SB_WRITE_WORD  0xb1
+
+/* Get / Set string smart battery parameters
+ * formatted as SMBUS "block".
+ */
+#define EC_CMD_SB_READ_BLOCK  0xb2
+#define EC_CMD_SB_WRITE_BLOCK 0xb3
+
+struct ec_params_sb_rd {
+       uint8_t reg;
+} __packed;
+
+struct ec_response_sb_rd_word {
+       uint16_t value;
+} __packed;
+
+struct ec_params_sb_wr_word {
+       uint8_t reg;
+       uint16_t value;
+} __packed;
+
+struct ec_response_sb_rd_block {
+       uint8_t data[32];
+} __packed;
+
+struct ec_params_sb_wr_block {
+       uint8_t reg;
+       uint16_t data[32];
+} __packed;
+
+/*****************************************************************************/
+/* System commands */
+
+/*
+ * TODO: this is a confusing name, since it doesn't necessarily reboot the EC.
+ * Rename to "set image" or something similar.
+ */
+#define EC_CMD_REBOOT_EC 0xd2
+
+/* Command */
+enum ec_reboot_cmd {
+       EC_REBOOT_CANCEL = 0,        /* Cancel a pending reboot */
+       EC_REBOOT_JUMP_RO = 1,       /* Jump to RO without rebooting */
+       EC_REBOOT_JUMP_RW = 2,       /* Jump to RW without rebooting */
+       /* (command 3 was jump to RW-B) */
+       EC_REBOOT_COLD = 4,          /* Cold-reboot */
+       EC_REBOOT_DISABLE_JUMP = 5,  /* Disable jump until next reboot */
+       EC_REBOOT_HIBERNATE = 6      /* Hibernate EC */
+};
+
+/* Flags for ec_params_reboot_ec.reboot_flags */
+#define EC_REBOOT_FLAG_RESERVED0      (1 << 0)  /* Was recovery request */
+#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1)  /* Reboot after AP shutdown */
+
+struct ec_params_reboot_ec {
+       uint8_t cmd;           /* enum ec_reboot_cmd */
+       uint8_t flags;         /* See EC_REBOOT_FLAG_* */
+} __packed;
+
+/*
+ * Get information on last EC panic.
+ *
+ * Returns variable-length platform-dependent panic information.  See panic.h
+ * for details.
+ */
+#define EC_CMD_GET_PANIC_INFO 0xd3
+
+/*****************************************************************************/
+/*
+ * ACPI commands
+ *
+ * These are valid ONLY on the ACPI command/data port.
+ */
+
+/*
+ * ACPI Read Embedded Controller
+ *
+ * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
+ *
+ * Use the following sequence:
+ *
+ *    - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
+ *    - Wait for EC_LPC_CMDR_PENDING bit to clear
+ *    - Write address to EC_LPC_ADDR_ACPI_DATA
+ *    - Wait for EC_LPC_CMDR_DATA bit to set
+ *    - Read value from EC_LPC_ADDR_ACPI_DATA
+ */
+#define EC_CMD_ACPI_READ 0x80
+
+/*
+ * ACPI Write Embedded Controller
+ *
+ * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
+ *
+ * Use the following sequence:
+ *
+ *    - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
+ *    - Wait for EC_LPC_CMDR_PENDING bit to clear
+ *    - Write address to EC_LPC_ADDR_ACPI_DATA
+ *    - Wait for EC_LPC_CMDR_PENDING bit to clear
+ *    - Write value to EC_LPC_ADDR_ACPI_DATA
+ */
+#define EC_CMD_ACPI_WRITE 0x81
+
+/*
+ * ACPI Query Embedded Controller
+ *
+ * This clears the lowest-order bit in the currently pending host events, and
+ * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
+ * event 0x80000000 = 32), or 0 if no event was pending.
+ */
+#define EC_CMD_ACPI_QUERY_EVENT 0x84
+
+/* Valid addresses in ACPI memory space, for read/write commands */
+/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
+#define EC_ACPI_MEM_VERSION            0x00
+/*
+ * Test location; writing value here updates test compliment byte to (0xff -
+ * value).
+ */
+#define EC_ACPI_MEM_TEST               0x01
+/* Test compliment; writes here are ignored. */
+#define EC_ACPI_MEM_TEST_COMPLIMENT    0x02
+/* Keyboard backlight brightness percent (0 - 100) */
+#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
+
+/* Current version of ACPI memory address space */
+#define EC_ACPI_MEM_VERSION_CURRENT 1
+
+
+/*****************************************************************************/
+/*
+ * Special commands
+ *
+ * These do not follow the normal rules for commands.  See each command for
+ * details.
+ */
+
+/*
+ * Reboot NOW
+ *
+ * This command will work even when the EC LPC interface is busy, because the
+ * reboot command is processed at interrupt level.  Note that when the EC
+ * reboots, the host will reboot too, so there is no response to this command.
+ *
+ * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
+ */
+#define EC_CMD_REBOOT 0xd1  /* Think "die" */
+
+/*
+ * Resend last response (not supported on LPC).
+ *
+ * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
+ * there was no previous command, or the previous command's response was too
+ * big to save.
+ */
+#define EC_CMD_RESEND_RESPONSE 0xdb
+
+/*
+ * This header byte on a command indicate version 0. Any header byte less
+ * than this means that we are talking to an old EC which doesn't support
+ * versioning. In that case, we assume version 0.
+ *
+ * Header bytes greater than this indicate a later version. For example,
+ * EC_CMD_VERSION0 + 1 means we are using version 1.
+ *
+ * The old EC interface must not use commands 0dc or higher.
+ */
+#define EC_CMD_VERSION0 0xdc
+
+#endif  /* !__ACPI__ */
+
+#endif  /* __CROS_EC_COMMANDS_H */
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 51ff266..0f4bbaa 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -78,6 +78,7 @@ enum fdt_compat_id {
        COMPAT_SAMSUNG_EXYNOS5_SOUND,   /* Exynos Sound */
        COMPAT_WOLFSON_WM8994_CODEC,    /* Wolfson WM8994 Sound Codec */
        COMPAT_SAMSUNG_EXYNOS_SPI,      /* Exynos SPI */
+       COMPAT_GOOGLE_CROS_EC,          /* Google CROS_EC Protocol */
        COMPAT_SAMSUNG_EXYNOS_EHCI,     /* Exynos EHCI controller */
        COMPAT_SAMSUNG_EXYNOS_USB_PHY,  /* Exynos phy controller for usb2.0 */
        COMPAT_MAXIM_MAX77686_PMIC,     /* MAX77686 PMIC */
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 856f90c..24cd6f9 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -53,6 +53,7 @@ static const char * const compat_names[COMPAT_COUNT] = {
        COMPAT(SAMSUNG_EXYNOS5_SOUND, "samsung,exynos-sound"),
        COMPAT(WOLFSON_WM8994_CODEC, "wolfson,wm8994-codec"),
        COMPAT(SAMSUNG_EXYNOS_SPI, "samsung,exynos-spi"),
+       COMPAT(GOOGLE_CROS_EC, "google,cros-ec"),
        COMPAT(SAMSUNG_EXYNOS_EHCI, "samsung,exynos-ehci"),
        COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"),
        COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686_pmic"),
--
1.8.1.3



------------------------------

Message: 11
Date: Thu, 28 Mar 2013 09:58:57 -0300
From: Fabio Estevam <festevam at gmail.com>
Subject: Re: [U-Boot] Splash Screen Enable in
        (u-boot-2013.01.01.tar.bz2) U-boot source code.
To: nandakumar.ramaswamy at pricoltech.com
Cc: u-boot at lists.denx.de
Message-ID:
        <CAOMZO5Cc9oM1Ewz69MjszUpN0ioiDDMed7pDDrA_LDdrBaY3ZA at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Tue, Mar 26, 2013 at 3:16 AM,  <nandakumar.ramaswamy at pricoltech.com> wrote:
>
> Hello Jens,
>
> Thanks for your quick response.
>
> Actually I tried with U-Boot latest release (u-boot-2013.01.01.tar.bz2) also.But I am not able to see the SPLASH SCREEN.
> So, please share the SPLASH SCREEN image enable procedure for latest U-boot (u-boot-2013.01.01.tar.bz2) source code for i.mx53loco.

If you connect the CLAA WVGA panel to mx53loco, the penguin logo and
U-boot version will be displayed by default.

LVDS panel has not been added yet, and that should be a simple task.
Please refer to the mx53ard board in FSL U-boot:
http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/tree/board/freescale/mx53_ard/mx53_ard.c?h=imx_v2009.08

Basically you need to pass the LVDS display timings, setup the LVDS
clocks and register the LVDS panel with the correct color format.

And please post your patches to the list once you add the LVDS support :-)

Regards,

Fabio Estevam


------------------------------

Message: 12
Date: Thu, 28 Mar 2013 10:03:43 -0300
From: Fabio Estevam <festevam at gmail.com>
Subject: Re: [U-Boot] Splash Screen Enable in
        (u-boot-2013.01.01.tar.bz2) U-boot source code.
To: nandakumar.ramaswamy at pricoltech.com
Cc: u-boot at lists.denx.de
Message-ID:
        <CAOMZO5B=jMSZqHnXbo7d3R6ZSKoJGUU7XOc6ta0W5haxw7mSTQ at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Thu, Mar 28, 2013 at 8:49 AM,  <nandakumar.ramaswamy at pricoltech.com> wrote:
>
> Hello,
>
> 1) Please share me, if any one used mx53loco - LVDS settings for hannstar (mcimx-lvds1) display as per the below,
>
> setenv bootargs_base 'setenv bootargs console=ttymxc0,115200 console=tty1 video=mxcdi1fb:RGB666,TOSHIBA-XGA di1_primary ldb=single,di=1,ch1_map=SPWG'
>
> 2) And I have modified the below files and codes for splash screen support for mx53loco as per the mx6qsabrelite.c. Please correct me, if I wrong.
>
> File Name: mx53loco.h
>
> Included:
> #define CONFIG_SPLASH_SCREEN

This is already part of include/configs/mx53loco.h

Please post your changes in the format of a patch so that we can
understand exactly what you are changing.

Also, please make sure that the backlight is turned on.

On my previous email the mx53ard code I pointed you to uses PWM to
drive the backlight, you could simply use a GPIO instead.


------------------------------

Message: 13
Date: Thu, 28 Mar 2013 14:38:23 +0100
From: Albert ARIBAUD <albert.u.boot at aribaud.net>
Subject: [U-Boot] Merge conflict on Tegra SPI between u-boot/master
        and u-boot-arm/master
To: U-Boot <u-boot at lists.denx.de>
Cc: Tom Rini <trini at ti.com>, Tom Warren <twarren.nvidia at gmail.com>
Message-ID: <20130328143823.7cb30d58 at lilith>
Content-Type: text/plain; charset=US-ASCII

Hello all,

While preparing for an ARM PR, specifically a merge between commit
417c55803118eb8e350d5ab8ba6583fb39f4e2e3 (current u-boot/master ToT)
and commit d53e340edf65ff253d3a7b06ebe60501045892e3 (current Tot for
u-boot-arm/master), I hit the following merge conflicts:

CONFLICT (content): Merge conflict in lib/fdtdec.c
CONFLICT (content): Merge conflict in include/fdtdec.h
CONFLICT (content): Merge conflict in drivers/spi/tegra20_sflash.c

While the first two, related to FDT, are simple (colliding additions to
the same enum from both branches) and can be manually resolved, the
third one, drivers/spi/tegra20_sflash.c, is not, and can not, at least,
not by me, as I am not a specialist on Tegra SPI.

Tom (Warren), can you advise on how to best solve this?

Amicalement,
--
Albert.


------------------------------

Message: 14
Date: Thu, 28 Mar 2013 14:41:45 +0100
From: Anatolij Gustschin <agust at denx.de>
Subject: Re: [U-Boot] Splash Screen Enable in
        (u-boot-2013.01.01.tar.bz2) U-boot source code.
To: nandakumar.ramaswamy at pricoltech.com
Cc: u-boot at lists.denx.de
Message-ID: <20130328144145.69c8f532 at crub>
Content-Type: text/plain; charset=US-ASCII

Hello,

On Thu, 28 Mar 2013 17:19:15 +0530 (IST)
nandakumar.ramaswamy at pricoltech.com wrote:

>
> Hello,
>
> 1) Please share me, if any one used mx53loco - LVDS settings for
> hannstar (mcimx-lvds1) display as per the below,

I've never used mx53loco board, also I never used a hannstar
display. The proper support for it is missing in U-Boot.

Also please restrict the line length in the email text to max. 72
characters and do not top post. Thanks!

> setenv bootargs_base 'setenv bootargs console=ttymxc0,115200 console=tty1 video=mxcdi1fb:RGB666,TOSHIBA-XGA di1_primary ldb=single,di=1,ch1_map=SPWG'
>
> 2) And I have modified the below files and codes for splash screen
> support for mx53loco as per the mx6qsabrelite.c. Please correct me,
> if I wrong.

Did you set "panel" environment variable to "Hannstar-XGA"
and saved the environment ? You are adding a check for it in the
board code, you also have to set this variable and save it to
the environment, then you have to reset the board so the new
setting will take effect.

> File Name: mx53loco.h
>
> Included:
> #define CONFIG_SPLASH_SCREEN
> #define CONFIG_SPLASH_SCREEN_ALIGN
> #define CONFIG_SPLASH_SCREEN_LVDS

Why do you add CONFIG_SPLASH_SCREEN_LVDS here ?
This configuration option is not available anywhere,
at least in mainline U-Boot code.

> #define CONFIG_CMD_BMP
>
> File Name: mx53loco_video.c
>
> Include:
> static struct fb_videomode const mcimx_lvds1 = {
>  .name        = "Hannstar-XGA",
>  .refresh    = 60,
>  .xres        = 1024,
>  .yres        = 768,
>  .pixclock    = 15385,
>  .left_margin    = 220,
>  .right_margin    = 40,
>  .upper_margin    = 21,
>  .lower_margin    = 7,
>  .hsync_len    = 60,
>  .vsync_len    = 10,
>  .sync        = 4,
> };
>
> int board_video_skip(void)
> {
>  int ret;
>  char const *e = getenv("panel");
>
>  printf("Display Panel Name: %s\n", e);
>
>  if (e) {
>  if (strcmp(e, "seiko") == 0) {
>  ret = ipuv3_fb_init(&seiko_wvga, 0, IPU_PIX_FMT_RGB24);
>  if (ret)
>  printf("Seiko cannot be configured: %d\n", ret);
>  return ret;
>  }
>  else if (strcmp(e, "Hannstar-XGA") == 0) {
>  ret = ipuv3_fb_init(&mcimx_lvds1, 0, IPU_PIX_FMT_LVDS666);
>  if (ret)
>  printf("MCIMX_LVDS1 cannot be configured: %d\n", ret);
>  return ret;
>  }
>  }
>
>  /*
>  * 'panel' env variable not found or has different value than 'seiko'
>  *  Defaulting to claa lcd.
>  */
>  ret = ipuv3_fb_init(&claa_wvga, 0, IPU_PIX_FMT_RGB565);
>  if (ret)
>  printf("CLAA cannot be configured: %d\n", ret);
>  return ret;
> }
>
> And I tried the below command. But not get the correct output
> (SPLASH Image) through U-Boot.

Your extensions are not enough, I'm afraid. You probably also have
to configure the pin mux for LVDS interface, enable the backlight
of the display, configure the backlight intensity, etc. I'm not
familiar with mx53loco, I cannot guide you what is all needed
to make video support over LVDS working. Please read the schematics
of the board and mx53 manual and make sure you understand what
is needed to configure LVDS interface and backlight properly.
Then add appropriate code.

> MX53LOCO U-Boot > tftp 100000 /tftpboot/lvds.bmp
> Using FEC device
> TFTP from server 192.168.1.176; our IP address is 192.168.1.189
> Filename '/tftpboot/lvds.bmp'.
> Load address: 0x100000
> Loading: T T T T T
>
> Please give your suggestion and solution ASAP.

> Note: I am trying to display from SD-card.

Why are you trying to load the bmp file from network then?
Do you have a working tftp server for this purpose?

If you have the bmp files on the SD-card, then you have
to use appropriate commands to load files from the card,
like "mmc rescan", "fatload mmc 0:0 <addr> <filename.bmp>"
or similar. Only after the file has been successfully loaded
to the address <addr>, you can use "bmp display <addr>"
command.

Thanks,

Anatolij


------------------------------

Message: 15
Date: Thu, 28 Mar 2013 10:14:16 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: Re: [U-Boot] [PATCH 1/9 v2] Exynos: Change get_timer() to
        work correctly
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364480056-15819-1-git-send-email-akshay.s at samsung.com>

Thanks for your comments.
Please find the reply corresponding to comments below.

>Dear Akshay,
>
>On 28/02/13 19:59, Akshay Saraswat wrote:
>> At present get_timer() does not return sane values. It should count up
>> smoothly in milliscond intervals.
>>
>> diff --git a/arch/arm/cpu/armv7/s5p-common/pwm.c b/arch/arm/cpu/armv7/s5p-common/pwm.c
>> index 44d7bc3..3147f59 100644
>> --- a/arch/arm/cpu/armv7/s5p-common/pwm.c
>> +++ b/arch/arm/cpu/armv7/s5p-common/pwm.c
>> @@ -174,6 +174,12 @@ int pwm_init(int pwm_id, int div, int invert)
>>
>>      /* set count value */
>>      offset = pwm_id * 3;
>> +
>> +    /*
>> +     * TODO(sjg): Use this as a countdown timer for now. We count down
>> +     * from the maximum value to 0, then reset.
>> +     */
>> +    timer_rate_hz = -1;
>
>is it workaround?

Yes, this is a part of workaround to get appropriate ticks.

>
>>      writel(timer_rate_hz, &pwm->tcntb0 + offset);
>>
>>      val = readl(&pwm->tcon) & ~(0xf << TCON_OFFSET(pwm_id));
>> diff --git a/arch/arm/cpu/armv7/s5p-common/timer.c b/arch/arm/cpu/armv7/s5p-common/timer.c
>> index e78c716..c48a297 100644
>> --- a/arch/arm/cpu/armv7/s5p-common/timer.c
>> +++ b/arch/arm/cpu/armv7/s5p-common/timer.c
>> @@ -39,13 +39,33 @@ static inline struct s5p_timer *s5p_get_base_timer(void)
>>      return (struct s5p_timer *)samsung_get_base_timer();
>>  }
>>
>> +/**
>> + * Read the countdown timer.
>> + *
>> + * This operates at 1MHz and counts downwards. It will wrap about every
>> + * hour (2^32 microseconds).
>> + *
>> + * @return current value of timer
>> + */
>> +static unsigned long timer_get_us_down(void)
>> +{
>> +    struct s5p_timer *const timer = s5p_get_base_timer();
>> +
>> +    return readl(&timer->tcnto4);
>> +}
>> +
>>  int timer_init(void)
>>  {
>>      /* PWM Timer 4 */
>> -    pwm_init(4, MUX_DIV_2, 0);
>> +    pwm_init(4, MUX_DIV_4, 0);
>
>There are special reason to change the div value?
>Please let me know.

We wish to count down at 1MHz, providing a resolution of 1us.
This becomes possible with MUX_DIV_4 for timer 4, since,
exynos 5250 manual says that for 4-bit divider settings at
1/4 (PCLK = 66 MHz ), we get 66637.07 seconds interval.

>
>>  /* delay x useconds */
>>  void __udelay(unsigned long usec)
>>  {
>> -    struct s5p_timer *const timer = s5p_get_base_timer();
>> -    unsigned long tmo, tmp, count_value;
>> -
>> -    count_value = readl(&timer->tcntb4);
>> -
>> -    if (usec >= 1000) {
>> -            /*
>> -             * if "big" number, spread normalization
>> -             * to seconds
>> -             * 1. start to normalize for usec to ticks per sec
>> -             * 2. find number of "ticks" to wait to achieve target
>> -             * 3. finish normalize.
>> -             */
>> -            tmo = usec / 1000;
>> -            tmo *= (CONFIG_SYS_HZ * count_value);
>> -            tmo /= 1000;
>> -    } else {
>> -            /* else small number, don't kill it prior to HZ multiply */
>> -            tmo = usec * CONFIG_SYS_HZ * count_value;
>> -            tmo /= (1000 * 1000);
>> -    }
>> -
>> -    /* get current timestamp */
>> -    tmp = get_current_tick();
>> -
>> -    /* if setting this fordward will roll time stamp */
>> -    /* reset "advancing" timestamp to 0, set lastinc value */
>> -    /* else, set advancing stamp wake up time */
>> -    if ((tmo + tmp + 1) < tmp)
>> -            reset_timer_masked();
>> -    else
>> -            tmo += tmp;
>> -
>> -    /* loop till event */
>> -    while (get_current_tick() < tmo)
>> -            ;       /* nop */
>> +    unsigned long count_value;
>> +
>> +    count_value = timer_get_us_down();
>> +    while ((int)(count_value - timer_get_us_down()) < (int)usec)
>
>why convert to int?

To avoid side effects of compiler optimizations.

>
>> +            ;
>>  }
>>
>>  void reset_timer_masked(void)
>> @@ -109,30 +109,6 @@ void reset_timer_masked(void)
>>      gd->arch.tbl = 0;
>>  }
>>
>> -unsigned long get_timer_masked(void)
>> -{
>> -    struct s5p_timer *const timer = s5p_get_base_timer();
>> -    unsigned long count_value = readl(&timer->tcntb4);
>> -
>> -    return get_current_tick() / count_value;
>> -}
>>   * This function is derived from PowerPC code (read timebase as long long).
>>   * On ARM it just returns the timer value.
>>
>
>Thanks,
>Minkyu Kang.


Regards,
Akshay Saraswat


------------------------------

Message: 16
Date: Thu, 28 Mar 2013 06:58:21 -0700
From: Eric Nelson <eric.nelson at boundarydevices.com>
Subject: Re: [U-Boot] [PATCH v2] mx6: Fix get_board_rev() for the mx6
        solo    case
To: Fabio Estevam <fabio.estevam at freescale.com>
Cc: u-boot at lists.denx.de, dirk.behme at de.bosch.com
Message-ID: <51544C7D.9090904 at boundarydevices.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 03/27/2013 10:36 AM, Fabio Estevam wrote:
> When booting a Freescale kernel 3.0.35 on a Wandboard solo, the get_board_rev()
> returns 0x62xxx, which is not a value understood by the VPU
> (Video Processing Unit) library in the kernel and causes the video playback to
> fail.
>
> The expected values for get_board_rev are:
> 0x63xxx: For mx6quad/dual
> 0x61xxx: For mx6dual-lite/solo
>
> So adjust get_board_rev() accordingly and make it as weak function, so that we
> do not need to define it in every mx6 board file.
>
> Signed-off-by: Fabio Estevam <fabio.estevam at freescale.com>
> ---
> Changes since v1:
> - Avoid extra call to get_cpu_rev()
>
>   arch/arm/cpu/armv7/mx6/soc.c                  |   12 ++++++++++++
>   board/boundary/nitrogen6x/nitrogen6x.c        |    5 -----
>   board/freescale/mx6qsabrelite/mx6qsabrelite.c |    5 -----
>   board/freescale/mx6qsabresd/mx6qsabresd.c     |    5 -----
>   board/wandboard/wandboard.c                   |    5 -----
>   5 files changed, 12 insertions(+), 20 deletions(-)
>

Acked-by: Eric Nelson <eric.nelson at boundarydevices.com>




------------------------------

Message: 17
Date: Thu, 28 Mar 2013 10:20:38 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: Re: [U-Boot] [PATCH 3/9 v2] Exynos: pwm: Fix two bugs in the
        exynos pwm configuration code
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364480438-16344-1-git-send-email-akshay.s at samsung.com>

Hi Minkyu,

Thanks for your comments.

>Dear Akshay,
>
>On 28/02/13 19:59, Akshay Saraswat wrote:
>> First, the "div" value was being used incorrectly to compute the frequency of
>> the PWM timer. The value passed in is a constant which reflects the value
>> that would be found in a configuration register, 0 to 4. That should
>> correspond to a scaling factor of 1, 2, 4, 8, or 16, 1 << div, but div + 1 was
>> being used instead.
>>
>> @@ -167,20 +167,24 @@ int pwm_init(int pwm_id, int div, int invert)
>>      val |= (div & 0xf) << MUX_DIV_SHIFT(pwm_id);
>>      writel(val, &pwm->tcfg1);
>>
>> -    timer_rate_hz = get_pwm_clk() / ((prescaler + 1) *
>> -                    (div + 1));
>> +    if (pwm_id == 4) {
>> +            /*
>> +             * TODO(sjg): Use this as a countdown timer for now. We count
>> +             * down from the maximum value to 0, then reset.
>> +             */
>> +            ticks_per_period = -1UL;
>> +    } else {
>> +            const unsigned long pwm_hz = 1000;
>> +            unsigned long timer_rate_hz = get_pwm_clk() /
>> +                    ((prescaler + 1) * (1 << div));
>
>good catch. thanks.
>
>>
>> -    timer_rate_hz = timer_rate_hz / CONFIG_SYS_HZ;
>> +            ticks_per_period = timer_rate_hz / pwm_hz;
>
>why don't you use CONFIG_SYS_HZ?
>pwm_hz seems to constant.

CONFIG_SYS_HZ may change with boards and as per needs.
But requirement here is for a constant value 1000
for all calculations which should remain 1000 only.
That's why using pwm_hz and not CONFIG_SYS_HZ.

>
>> +    }
>>
>>      /* set count value */
>>      offset = pwm_id * 3;
>>
>> -    /*
>> -     * TODO(sjg): Use this as a countdown timer for now. We count down
>> -     * from the maximum value to 0, then reset.
>> -     */
>> -    timer_rate_hz = -1;
>> -    writel(timer_rate_hz, &pwm->tcntb0 + offset);
>> +    writel(ticks_per_period, &pwm->tcntb0 + offset);
>>
>>      val = readl(&pwm->tcon) & ~(0xf << TCON_OFFSET(pwm_id));
>>      if (invert && (pwm_id < 4))
>>
>
>Thanks,
>Minkyu Kang.
>

Regards,
Akshay Saraswat


------------------------------

Message: 18
Date: Thu, 28 Mar 2013 10:29:14 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: Re: [U-Boot] [PATCH 4/9 v2] Exynos: Avoid a divide by zero by
        specifying a non-zero period for pwm 4
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364480954-17195-1-git-send-email-akshay.s at samsung.com>

Minkyu,

Thanks for comments.
Please find my reply below the comment.

>On 28/02/13 19:59, Akshay Saraswat wrote:
>> The pwm_config function in the exynos pwm driver divides by its period
>> period parameter. A function was calling pwm_config with a 0ns period and a
>> 0ns duty cycle. That doesn't actually make any sense physically, and results
>> in a divide by zero in the driver. This change changes the paremters to be a
>
>typo.
>paremters -> parameter
>
>> 100000ns period and duty cycle.
>>
>> Test with command "sf probe 1:0; time sf read 40008000 0 1000".
>> Try with different numbers of bytes and see that sane values are obtained
>> Build and boot U-boot with this patch, backlight works properly.
>>
>> Signed-off-by: Gabe Black <gabeblack at google.com>
>> Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
>> Acked-by: Simon Glass <sjg at chromium.org>
>> ---
>> Changes since v1:
>>         - Added "Acked-by: Simon Glass".
>>
>>  arch/arm/cpu/armv7/s5p-common/timer.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/cpu/armv7/s5p-common/timer.c b/arch/arm/cpu/armv7/s5p-common/timer.c
>> index de61405..6a0fa58 100644
>> --- a/arch/arm/cpu/armv7/s5p-common/timer.c
>> +++ b/arch/arm/cpu/armv7/s5p-common/timer.c
>> @@ -58,7 +58,7 @@ int timer_init(void)
>>  {
>>      /* PWM Timer 4 */
>>      pwm_init(4, MUX_DIV_4, 0);
>> -    pwm_config(4, 0, 0);
>> +    pwm_config(4, 100000, 100000);
>
>0 is a numerator.
>I think.. it doesn't matter.

In file pwm.c line 98 we are doing:
 frequency = NS_IN_SEC / period_ns;

what we are passing in this call are the values of duty_ns and period_ns.
So, there are places where divide by zero may occur.
I think we should keep it to be on a safer side.

>
>>      pwm_enable(4);
>>
>>      /* Use this as the current monotonic time in us */
>>
>
>Thanks,
>Minkyu Kang.
>

Regards,
Akshay Saraswat


------------------------------

Message: 19
Date: Thu, 28 Mar 2013 10:32:14 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 00/11 v3] Fix and Re-organise PWM Timer
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-1-git-send-email-akshay.s at samsung.com>

This patch set tries to fix few bugs in timer and re-organises PWM
clock code.

Changes since v2:
        - Patch-1: New patch.
        - Patch-2: None.
        - Patch-3: None.
        - Patch-4: None.
        - Patch-5: Fixed typo paremters in commit message.
        - Patch-6: None.
        - Patch-7: Added "Acked-by: Simon Glass".
        - Patch-8:
                 Fixed typo peripherial to peripheral.
                - Made exynos5_get_periph_rate static.
                - Added an empty line.
                - Replaced "enum periph_id" with "int" in function arguments.
                - Removed "#include <asm/arch/periph.h>" from clk.h.
                - Added "Acked-by: Simon Glass".
        - Patch-9: None.
        - Patch-10:
                - Replaced "exynos5_get_pwm_clk" with "clock_get_periph_rate" in get_pwm_clk
                  instead of replacing everywhere.
                - Added "Acked-by: Simon Glass".
        - Patch-11: New patch.

Changes since v1:
        - Patch-1: Added "Acked-by: Simon Glass".
        - Patch-2: Added "Acked-by: Simon Glass".
        - Patch-3: Added "Acked-by: Simon Glass".
        - Patch-4: Added "Acked-by: Simon Glass".
        - Patch-5: Added "Acked-by: Simon Glass".
        - Patch-6: None.
        - Patch-7: Fixed few nits.
        - Patch-8: Added "Acked-by: Simon Glass".
        - Patch-9: Restored get_pwm_clk call in case of non-exynos5 cpu.

Akshay Saraswat (11):
  Exynos5: config: enable time command
  Exynos: Change get_timer() to work correctly
  Exynos: Add timer_get_us function
  Exynos: pwm: Fix two bugs in the exynos pwm      configuration code
  Exynos: Avoid a divide by zero by specifying a non-zero      period
    for pwm 4
  Exynos: Tidy up the pwm_config function in the exynos      pwm driver
  Exynos: Add peripherial id for pwm
  Exynos: clock: Add generic api to get the clk freq
  Exynos: clock: Correct pwm source clk selection
  Exynos: pwm: Use generic api to get pwm clk freq
  Exynos: pwm: Remove dead code of function exynos5_get_pwm_clk

 arch/arm/cpu/armv7/exynos/clock.c         | 167 ++++++++++++++++++++++++++----
 arch/arm/cpu/armv7/s5p-common/pwm.c       |  42 ++++----
 arch/arm/cpu/armv7/s5p-common/timer.c     | 117 ++++++++++-----------
 arch/arm/include/asm/arch-exynos/clk.h    |  15 +++
 arch/arm/include/asm/arch-exynos/periph.h |   5 +
 board/samsung/smdk5250/setup.h            |   2 +-
 include/configs/exynos5250-dt.h           |   3 +
 7 files changed, 244 insertions(+), 107 deletions(-)

--
1.8.0



------------------------------

Message: 20
Date: Thu, 28 Mar 2013 10:32:15 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 01/11 v3] Exynos5: config: enable time
        command
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-2-git-send-email-akshay.s at samsung.com>

This patch enables time command.

Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
---
Chnages since v2:
        - New patch.

 include/configs/exynos5250-dt.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/configs/exynos5250-dt.h b/include/configs/exynos5250-dt.h
index 2b9d6ac..b13aade 100644
--- a/include/configs/exynos5250-dt.h
+++ b/include/configs/exynos5250-dt.h
@@ -325,4 +325,7 @@
 #define LCD_BPP                        LCD_COLOR16
 #endif

+/* Enable Time Command */
+#define CONFIG_CMD_TIME
+
 #endif /* __CONFIG_H */
--
1.8.0



------------------------------

Message: 21
Date: Thu, 28 Mar 2013 10:32:16 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 02/11 v3] Exynos: Change get_timer() to work
        correctly
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-3-git-send-email-akshay.s at samsung.com>

From: Simon Glass <sjg at chromium.org>

At present get_timer() does not return sane values. It should count up
smoothly in milliscond intervals.

We can change the PWM to count down at 1MHz, providing a resolution
of 1us and a range of about an hour between required get_timer() calls.

Test with command "sf probe 1:0; time sf read 40008000 0 1000".
Try with different numbers of bytes and see that sane values are obtained

Signed-off-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
Changes since v2:
        - None.

Changes since v1:
        - Added "Acked-by: Simon Glass".

 arch/arm/cpu/armv7/s5p-common/pwm.c   |   6 ++
 arch/arm/cpu/armv7/s5p-common/timer.c | 100 +++++++++++++---------------------
 2 files changed, 44 insertions(+), 62 deletions(-)

diff --git a/arch/arm/cpu/armv7/s5p-common/pwm.c b/arch/arm/cpu/armv7/s5p-common/pwm.c
index 44d7bc3..3147f59 100644
--- a/arch/arm/cpu/armv7/s5p-common/pwm.c
+++ b/arch/arm/cpu/armv7/s5p-common/pwm.c
@@ -174,6 +174,12 @@ int pwm_init(int pwm_id, int div, int invert)

        /* set count value */
        offset = pwm_id * 3;
+
+       /*
+        * TODO(sjg): Use this as a countdown timer for now. We count down
+        * from the maximum value to 0, then reset.
+        */
+       timer_rate_hz = -1;
        writel(timer_rate_hz, &pwm->tcntb0 + offset);

        val = readl(&pwm->tcon) & ~(0xf << TCON_OFFSET(pwm_id));
diff --git a/arch/arm/cpu/armv7/s5p-common/timer.c b/arch/arm/cpu/armv7/s5p-common/timer.c
index e78c716..c48a297 100644
--- a/arch/arm/cpu/armv7/s5p-common/timer.c
+++ b/arch/arm/cpu/armv7/s5p-common/timer.c
@@ -39,13 +39,33 @@ static inline struct s5p_timer *s5p_get_base_timer(void)
        return (struct s5p_timer *)samsung_get_base_timer();
 }

+/**
+ * Read the countdown timer.
+ *
+ * This operates at 1MHz and counts downwards. It will wrap about every
+ * hour (2^32 microseconds).
+ *
+ * @return current value of timer
+ */
+static unsigned long timer_get_us_down(void)
+{
+       struct s5p_timer *const timer = s5p_get_base_timer();
+
+       return readl(&timer->tcnto4);
+}
+
 int timer_init(void)
 {
        /* PWM Timer 4 */
-       pwm_init(4, MUX_DIV_2, 0);
+       pwm_init(4, MUX_DIV_4, 0);
        pwm_config(4, 0, 0);
        pwm_enable(4);

+       /* Use this as the current monotonic time in us */
+       gd->arch.timer_reset_value = 0;
+
+       /* Use this as the last timer value we saw */
+       gd->arch.lastinc = timer_get_us_down();
        reset_timer_masked();

        return 0;
@@ -56,48 +76,28 @@ int timer_init(void)
  */
 unsigned long get_timer(unsigned long base)
 {
-       return get_timer_masked() - base;
+       ulong now = timer_get_us_down();
+
+       /*
+        * Increment the time by the amount elapsed since the last read.
+        * The timer may have wrapped around, but it makes no difference to
+        * our arithmetic here.
+        */
+       gd->arch.timer_reset_value += gd->arch.lastinc - now;
+       gd->arch.lastinc = now;
+
+       /* Divide by 1000 to convert from us to ms */
+       return gd->arch.timer_reset_value / 1000 - base;
 }

 /* delay x useconds */
 void __udelay(unsigned long usec)
 {
-       struct s5p_timer *const timer = s5p_get_base_timer();
-       unsigned long tmo, tmp, count_value;
-
-       count_value = readl(&timer->tcntb4);
-
-       if (usec >= 1000) {
-               /*
-                * if "big" number, spread normalization
-                * to seconds
-                * 1. start to normalize for usec to ticks per sec
-                * 2. find number of "ticks" to wait to achieve target
-                * 3. finish normalize.
-                */
-               tmo = usec / 1000;
-               tmo *= (CONFIG_SYS_HZ * count_value);
-               tmo /= 1000;
-       } else {
-               /* else small number, don't kill it prior to HZ multiply */
-               tmo = usec * CONFIG_SYS_HZ * count_value;
-               tmo /= (1000 * 1000);
-       }
-
-       /* get current timestamp */
-       tmp = get_current_tick();
-
-       /* if setting this fordward will roll time stamp */
-       /* reset "advancing" timestamp to 0, set lastinc value */
-       /* else, set advancing stamp wake up time */
-       if ((tmo + tmp + 1) < tmp)
-               reset_timer_masked();
-       else
-               tmo += tmp;
-
-       /* loop till event */
-       while (get_current_tick() < tmo)
-               ;       /* nop */
+       unsigned long count_value;
+
+       count_value = timer_get_us_down();
+       while ((int)(count_value - timer_get_us_down()) < (int)usec)
+               ;
 }

 void reset_timer_masked(void)
@@ -109,30 +109,6 @@ void reset_timer_masked(void)
        gd->arch.tbl = 0;
 }

-unsigned long get_timer_masked(void)
-{
-       struct s5p_timer *const timer = s5p_get_base_timer();
-       unsigned long count_value = readl(&timer->tcntb4);
-
-       return get_current_tick() / count_value;
-}
-
-unsigned long get_current_tick(void)
-{
-       struct s5p_timer *const timer = s5p_get_base_timer();
-       unsigned long now = readl(&timer->tcnto4);
-       unsigned long count_value = readl(&timer->tcntb4);
-
-       if (gd->arch.lastinc >= now)
-               gd->arch.tbl += gd->arch.lastinc - now;
-       else
-               gd->arch.tbl += gd->arch.lastinc + count_value - now;
-
-       gd->arch.lastinc = now;
-
-       return gd->arch.tbl;
-}
-
 /*
  * This function is derived from PowerPC code (read timebase as long long).
  * On ARM it just returns the timer value.
--
1.8.0



------------------------------

Message: 22
Date: Thu, 28 Mar 2013 10:32:17 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 03/11 v3] Exynos: Add timer_get_us function
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-4-git-send-email-akshay.s at samsung.com>

From: Che-Liang Chiou <clchiou at chromium.org>

timer_get_us returns the time in microseconds since a certain reference
point of history.  However, it does not guarantee to return an accurate
time after a long period; instead, it wraps around (that is, the
reference point is reset to some other point of history) after some
periods. The frequency of wrapping around is about an hour (or 2^32
microseconds).

Test with command "sf probe 1:0; time sf read 40008000 0 1000".
Try with different numbers of bytes and see that sane values are obtained

Signed-off-by: Che-Liang Chiou <clchiou at chromium.org>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
Changes since v2:
        - None.

Changes since v1:
        - Added "Acked-by: Simon Glass".

 arch/arm/cpu/armv7/s5p-common/timer.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm/cpu/armv7/s5p-common/timer.c b/arch/arm/cpu/armv7/s5p-common/timer.c
index c48a297..de61405 100644
--- a/arch/arm/cpu/armv7/s5p-common/timer.c
+++ b/arch/arm/cpu/armv7/s5p-common/timer.c
@@ -90,6 +90,21 @@ unsigned long get_timer(unsigned long base)
        return gd->arch.timer_reset_value / 1000 - base;
 }

+unsigned long timer_get_us(void)
+{
+       static unsigned long base_time_us;
+
+       struct s5p_timer *const timer =
+               (struct s5p_timer *)samsung_get_base_timer();
+       unsigned long now_downward_us = readl(&timer->tcnto4);
+
+       if (!base_time_us)
+               base_time_us = now_downward_us;
+
+       /* Note that this timer counts downward. */
+       return base_time_us - now_downward_us;
+}
+
 /* delay x useconds */
 void __udelay(unsigned long usec)
 {
--
1.8.0



------------------------------

Message: 23
Date: Thu, 28 Mar 2013 10:32:18 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 04/11 v3] Exynos: pwm: Fix two bugs in the
        exynos pwm configuration code
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-5-git-send-email-akshay.s at samsung.com>

From: Gabe Black <gabeblack at google.com>

First, the "div" value was being used incorrectly to compute the frequency of
the PWM timer. The value passed in is a constant which reflects the value
that would be found in a configuration register, 0 to 4. That should
correspond to a scaling factor of 1, 2, 4, 8, or 16, 1 << div, but div + 1 was
being used instead.

Second, the reset value of the timers were being calculated to give an overall
frequency, thrown out, and set to a maximum value. This was done so that PWM 4
could be used as the system clock by counting down from a high value, but it
was applied indiscriminantly. It should at most be applied only to PWM 4.

This change also takes the opportunity to tidy up the pwm_init function.

Test with command "sf probe 1:0; time sf read 40008000 0 1000".
Try with different numbers of bytes and see that sane values are obtained
Build and boot U-boot with this patch, backlight works properly.

Signed-off-by: Gabe Black <gabeblack at google.com>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
Changes since v2:
        - None.

Changes since v1:
        - Added "Acked-by: Simon Glass".

 arch/arm/cpu/armv7/s5p-common/pwm.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/arch/arm/cpu/armv7/s5p-common/pwm.c b/arch/arm/cpu/armv7/s5p-common/pwm.c
index 3147f59..02156d1 100644
--- a/arch/arm/cpu/armv7/s5p-common/pwm.c
+++ b/arch/arm/cpu/armv7/s5p-common/pwm.c
@@ -143,7 +143,7 @@ int pwm_init(int pwm_id, int div, int invert)
        u32 val;
        const struct s5p_timer *pwm =
                        (struct s5p_timer *)samsung_get_base_timer();
-       unsigned long timer_rate_hz;
+       unsigned long ticks_per_period;
        unsigned int offset, prescaler;

        /*
@@ -167,20 +167,24 @@ int pwm_init(int pwm_id, int div, int invert)
        val |= (div & 0xf) << MUX_DIV_SHIFT(pwm_id);
        writel(val, &pwm->tcfg1);

-       timer_rate_hz = get_pwm_clk() / ((prescaler + 1) *
-                       (div + 1));
+       if (pwm_id == 4) {
+               /*
+                * TODO(sjg): Use this as a countdown timer for now. We count
+                * down from the maximum value to 0, then reset.
+                */
+               ticks_per_period = -1UL;
+       } else {
+               const unsigned long pwm_hz = 1000;
+               unsigned long timer_rate_hz = get_pwm_clk() /
+                       ((prescaler + 1) * (1 << div));

-       timer_rate_hz = timer_rate_hz / CONFIG_SYS_HZ;
+               ticks_per_period = timer_rate_hz / pwm_hz;
+       }

        /* set count value */
        offset = pwm_id * 3;

-       /*
-        * TODO(sjg): Use this as a countdown timer for now. We count down
-        * from the maximum value to 0, then reset.
-        */
-       timer_rate_hz = -1;
-       writel(timer_rate_hz, &pwm->tcntb0 + offset);
+       writel(ticks_per_period, &pwm->tcntb0 + offset);

        val = readl(&pwm->tcon) & ~(0xf << TCON_OFFSET(pwm_id));
        if (invert && (pwm_id < 4))
--
1.8.0



------------------------------

Message: 24
Date: Thu, 28 Mar 2013 10:32:19 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 05/11 v3] Exynos: Avoid a divide by zero by
        specifying a non-zero period for pwm 4
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-6-git-send-email-akshay.s at samsung.com>

From: Gabe Black <gabeblack at google.com>

The pwm_config function in the exynos pwm driver divides by its period
period parameter. A function was calling pwm_config with a 0ns period and a
0ns duty cycle. That doesn't actually make any sense physically, and results
in a divide by zero in the driver. This change changes the parameters to be a
100000ns period and duty cycle.

Test with command "sf probe 1:0; time sf read 40008000 0 1000".
Try with different numbers of bytes and see that sane values are obtained
Build and boot U-boot with this patch, backlight works properly.

Signed-off-by: Gabe Black <gabeblack at google.com>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
Changes since v2:
        - Fixed typo paremters in commit message.

Changes since v1:
        - Added "Acked-by: Simon Glass".

 arch/arm/cpu/armv7/s5p-common/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/cpu/armv7/s5p-common/timer.c b/arch/arm/cpu/armv7/s5p-common/timer.c
index de61405..6a0fa58 100644
--- a/arch/arm/cpu/armv7/s5p-common/timer.c
+++ b/arch/arm/cpu/armv7/s5p-common/timer.c
@@ -58,7 +58,7 @@ int timer_init(void)
 {
        /* PWM Timer 4 */
        pwm_init(4, MUX_DIV_4, 0);
-       pwm_config(4, 0, 0);
+       pwm_config(4, 100000, 100000);
        pwm_enable(4);

        /* Use this as the current monotonic time in us */
--
1.8.0



------------------------------

Message: 25
Date: Thu, 28 Mar 2013 10:32:21 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 08/11 v3] Exynos: clock: Add generic api to
        get the clk freq
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-8-git-send-email-akshay.s at samsung.com>

From: Padmavathi Venna <padma.v at samsung.com>

Add generic api to get the frequency of the required peripherial. This
API gets the source clock frequency and returns the required frequency
by dividing with first and second dividers based on the requirement.

Test with command "sf probe 1:0; time sf read 40008000 0 1000".
Try with different numbers of bytes and see that sane values are obtained
Build and boot U-boot with this patch, backlight works properly.

Signed-off-by: Padmavathi Venna <padma.v at samsung.com>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
Changes since v2:
        - Fixed typo peripherial to peripheral.
        - Made exynos5_get_periph_rate static.
        - Added an empty line.
        - Replaced "enum periph_id" with "int" in function arguments.
        - Removed "#include <asm/arch/periph.h>" from clk.h.
        - Added "Acked-by: Simon Glass".

Changes since v1:
        - Fixed few nits.

 arch/arm/cpu/armv7/exynos/clock.c      | 144 +++++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-exynos/clk.h |  15 ++++
 2 files changed, 159 insertions(+)

diff --git a/arch/arm/cpu/armv7/exynos/clock.c b/arch/arm/cpu/armv7/exynos/clock.c
index 956427c..5860c8f 100644
--- a/arch/arm/cpu/armv7/exynos/clock.c
+++ b/arch/arm/cpu/armv7/exynos/clock.c
@@ -27,6 +27,49 @@
 #include <asm/arch/clk.h>
 #include <asm/arch/periph.h>

+/* *
+ * This structure is to store the src bit, div bit and prediv bit
+ * positions of the peripheral clocks of the src and div registers
+ */
+struct clk_bit_info {
+       int8_t src_bit;
+       int8_t div_bit;
+       int8_t prediv_bit;
+};
+
+/* src_bit div_bit prediv_bit */
+static struct clk_bit_info clk_bit_info[PERIPH_ID_COUNT] = {
+       {0,     0,      -1},
+       {4,     4,      -1},
+       {8,     8,      -1},
+       {12,    12,     -1},
+       {0,     0,      8},
+       {4,     16,     24},
+       {8,     0,      8},
+       {12,    16,     24},
+       {-1,    -1,     -1},
+       {16,    0,      8},
+       {20,    16,     24},
+       {24,    0,      8},
+       {0,     0,      4},
+       {4,     12,     16},
+       {-1,    -1,     -1},
+       {-1,    -1,     -1},
+       {-1,    24,     0},
+       {-1,    24,     0},
+       {-1,    24,     0},
+       {-1,    24,     0},
+       {-1,    24,     0},
+       {-1,    24,     0},
+       {-1,    24,     0},
+       {-1,    24,     0},
+       {24,    0,      -1},
+       {24,    0,      -1},
+       {24,    0,      -1},
+       {24,    0,      -1},
+       {24,    0,      -1},
+};
+
 /* Epll Clock division values to achive different frequency output */
 static struct set_epll_con_val exynos5_epll_div[] = {
        { 192000000, 0, 48, 3, 1, 0 },
@@ -201,6 +244,107 @@ static unsigned long exynos5_get_pll_clk(int pllreg)
        return fout;
 }

+static unsigned long exynos5_get_periph_rate(int peripheral)
+{
+       struct clk_bit_info *bit_info = &clk_bit_info[peripheral];
+       unsigned long sclk, sub_clk;
+       unsigned int src, div, sub_div;
+       struct exynos5_clock *clk =
+                       (struct exynos5_clock *)samsung_get_base_clock();
+
+       switch (peripheral) {
+       case PERIPH_ID_UART0:
+       case PERIPH_ID_UART1:
+       case PERIPH_ID_UART2:
+       case PERIPH_ID_UART3:
+               src = readl(&clk->src_peric0);
+               div = readl(&clk->div_peric0);
+               break;
+       case PERIPH_ID_PWM0:
+       case PERIPH_ID_PWM1:
+       case PERIPH_ID_PWM2:
+       case PERIPH_ID_PWM3:
+       case PERIPH_ID_PWM4:
+               src = readl(&clk->src_peric0);
+               div = readl(&clk->div_peric3);
+               break;
+       case PERIPH_ID_SPI0:
+       case PERIPH_ID_SPI1:
+               src = readl(&clk->src_peric1);
+               div = readl(&clk->div_peric1);
+               break;
+       case PERIPH_ID_SPI2:
+               src = readl(&clk->src_peric1);
+               div = readl(&clk->div_peric2);
+               break;
+       case PERIPH_ID_SPI3:
+       case PERIPH_ID_SPI4:
+               src = readl(&clk->sclk_src_isp);
+               div = readl(&clk->sclk_div_isp);
+               break;
+       case PERIPH_ID_SDMMC0:
+       case PERIPH_ID_SDMMC1:
+       case PERIPH_ID_SDMMC2:
+       case PERIPH_ID_SDMMC3:
+               src = readl(&clk->src_fsys);
+               div = readl(&clk->div_fsys1);
+               break;
+       case PERIPH_ID_I2C0:
+       case PERIPH_ID_I2C1:
+       case PERIPH_ID_I2C2:
+       case PERIPH_ID_I2C3:
+       case PERIPH_ID_I2C4:
+       case PERIPH_ID_I2C5:
+       case PERIPH_ID_I2C6:
+       case PERIPH_ID_I2C7:
+               sclk = exynos5_get_pll_clk(MPLL);
+               sub_div = ((readl(&clk->div_top1) >> bit_info->div_bit)
+                                                               & 0x7) + 1;
+               div = ((readl(&clk->div_top0) >> bit_info->prediv_bit)
+                                                               & 0x7) + 1;
+               return (sclk / sub_div) / div;
+       default:
+               debug("%s: invalid peripheral %d", __func__, peripheral);
+               return -1;
+       };
+
+       src = (src >> bit_info->src_bit) & 0xf;
+
+       switch (src) {
+       case EXYNOS_SRC_MPLL:
+               sclk = exynos5_get_pll_clk(MPLL);
+               break;
+       case EXYNOS_SRC_EPLL:
+               sclk = exynos5_get_pll_clk(EPLL);
+               break;
+       case EXYNOS_SRC_VPLL:
+               sclk = exynos5_get_pll_clk(VPLL);
+               break;
+       default:
+               return 0;
+       }
+
+       /* Ratio clock division for this peripheral */
+       sub_div = (div >> bit_info->div_bit) & 0xf;
+       sub_clk = sclk / (sub_div + 1);
+
+       /* Pre-ratio clock division for SDMMC0 and 2 */
+       if (peripheral == PERIPH_ID_SDMMC0 || peripheral == PERIPH_ID_SDMMC2) {
+               div = (div >> bit_info->prediv_bit) & 0xff;
+               return sub_clk / (div + 1);
+       }
+
+       return sub_clk;
+}
+
+unsigned long clock_get_periph_rate(int peripheral)
+{
+       if (cpu_is_exynos5())
+               return exynos5_get_periph_rate(peripheral);
+       else
+               return 0;
+}
+
 /* exynos4: return ARM clock frequency */
 static unsigned long exynos4_get_arm_clk(void)
 {
diff --git a/arch/arm/include/asm/arch-exynos/clk.h b/arch/arm/include/asm/arch-exynos/clk.h
index 1935b0b..73f8063 100644
--- a/arch/arm/include/asm/arch-exynos/clk.h
+++ b/arch/arm/include/asm/arch-exynos/clk.h
@@ -29,6 +29,12 @@
 #define VPLL   4
 #define BPLL   5

+enum pll_src_bit {
+       EXYNOS_SRC_MPLL = 6,
+       EXYNOS_SRC_EPLL,
+       EXYNOS_SRC_VPLL,
+};
+
 unsigned long get_pll_clk(int pllreg);
 unsigned long get_arm_clk(void);
 unsigned long get_i2c_clk(void);
@@ -44,4 +50,13 @@ int set_i2s_clk_prescaler(unsigned int src_frq, unsigned int dst_frq);
 int set_epll_clk(unsigned long rate);
 int set_spi_clk(int periph_id, unsigned int rate);

+/**
+ * get the clk frequency of the required peripheral
+ *
+ * @param peripheral   Peripheral id
+ *
+ * @return frequency of the peripheral clk
+ */
+unsigned long clock_get_periph_rate(int peripheral);
+
 #endif
--
1.8.0



------------------------------

Message: 26
Date: Thu, 28 Mar 2013 10:32:22 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 09/11 v3] Exynos: clock: Correct pwm source
        clk     selection
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-9-git-send-email-akshay.s at samsung.com>

From: Padmavathi Venna <padma.v at samsung.com>

MPLL is selected as the source clk of pwm by default

Test with command "sf probe 1:0; time sf read 40008000 0 1000".
Try with different numbers of bytes and see that sane values are obtained
Build and boot U-boot with this patch, backlight works properly.

Signed-off-by: Padmavathi Venna <padma.v at samsung.com>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
Changes since v2:
        - None.

Changes since v1:
        - Added "Acked-by: Simon Glass".

 board/samsung/smdk5250/setup.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/samsung/smdk5250/setup.h b/board/samsung/smdk5250/setup.h
index a159601..34d8bc3 100644
--- a/board/samsung/smdk5250/setup.h
+++ b/board/samsung/smdk5250/setup.h
@@ -343,7 +343,7 @@
 #define TOP2_VAL               0x0110000

 /* CLK_SRC_PERIC0 */
-#define PWM_SEL                0
+#define PWM_SEL                6
 #define UART3_SEL      6
 #define UART2_SEL      6
 #define UART1_SEL      6
--
1.8.0



------------------------------

Message: 27
Date: Thu, 28 Mar 2013 10:32:24 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 11/11 v3] Exynos: pwm: Remove dead code of
        function exynos5_get_pwm_clk
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-11-git-send-email-akshay.s at samsung.com>

As we shall now be using clock_get_periph_rate function.
We find no reason for keeping code in function exynos5_get_pwm_clk.
Hence, removing it.

Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
---
Changes since v2:
        - New patch.

 arch/arm/cpu/armv7/exynos/clock.c | 21 ---------------------
 1 file changed, 21 deletions(-)

diff --git a/arch/arm/cpu/armv7/exynos/clock.c b/arch/arm/cpu/armv7/exynos/clock.c
index 1e54e47..223660a 100644
--- a/arch/arm/cpu/armv7/exynos/clock.c
+++ b/arch/arm/cpu/armv7/exynos/clock.c
@@ -468,27 +468,6 @@ static unsigned long exynos4x12_get_pwm_clk(void)
        return pclk;
 }

-/* exynos5: return pwm clock frequency */
-static unsigned long exynos5_get_pwm_clk(void)
-{
-       struct exynos5_clock *clk =
-               (struct exynos5_clock *)samsung_get_base_clock();
-       unsigned long pclk, sclk;
-       unsigned int ratio;
-
-       /*
-        * CLK_DIV_PERIC3
-        * PWM_RATIO [3:0]
-        */
-       ratio = readl(&clk->div_peric3);
-       ratio = ratio & 0xf;
-       sclk = get_pll_clk(MPLL);
-
-       pclk = sclk / (ratio + 1);
-
-       return pclk;
-}
-
 /* exynos4: return uart clock frequency */
 static unsigned long exynos4_get_uart_clk(int dev_index)
 {
--
1.8.0



------------------------------

Message: 28
Date: Thu, 28 Mar 2013 10:32:23 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 10/11 v3] Exynos: pwm: Use generic api to get
        pwm     clk freq
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-10-git-send-email-akshay.s at samsung.com>

From: Padmavathi Venna <padma.v at samsung.com>

Use generic api to get the pwm clock frequency

Test with command "sf probe 1:0; time sf read 40008000 0 1000".
Try with different numbers of bytes and see that sane values are obtained
Build and boot U-boot with this patch, backlight works properly.

Signed-off-by: Padmavathi Venna <padma.v at samsung.com>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
Changes since v2:
        - Replaced "exynos5_get_pwm_clk" with "clock_get_periph_rate" in get_pwm_clk
          instead of replacing everywhere.
        - Added "Acked-by: Simon Glass".

Changes since v1:
        - Restored get_pwm_clk call in case of non-exynos5 cpu.

 arch/arm/cpu/armv7/exynos/clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/cpu/armv7/exynos/clock.c b/arch/arm/cpu/armv7/exynos/clock.c
index 5860c8f..1e54e47 100644
--- a/arch/arm/cpu/armv7/exynos/clock.c
+++ b/arch/arm/cpu/armv7/exynos/clock.c
@@ -1354,7 +1354,7 @@ unsigned long get_i2c_clk(void)
 unsigned long get_pwm_clk(void)
 {
        if (cpu_is_exynos5())
-               return exynos5_get_pwm_clk();
+               return clock_get_periph_rate(PERIPH_ID_PWM0);
        else {
                if (proid_is_exynos4412())
                        return exynos4x12_get_pwm_clk();
--
1.8.0



------------------------------

Message: 29
Date: Thu, 28 Mar 2013 10:32:20 -0400
From: Akshay Saraswat <akshay.s at samsung.com>
Subject: [U-Boot] [PATCH 06/11 v3] Exynos: Tidy up the pwm_config
        function in the exynos pwm driver
To: u-boot at lists.denx.de, mk7.kang at samsung.com
Cc: prashanth.g at samsung.com
Message-ID: <1364481144-17495-7-git-send-email-akshay.s at samsung.com>

From: Gabe Black <gabeblack at google.com>

Some small fixes in the exynos pwm driver:

1. NS_IN_HZ is non-sensical since these are not compatible units. This
constant actually describes the number of nanoseconds in a second. Renamed it
to NS_IN_SEC. Also dropped the unnecessary parenthesis.
2. The variable "period" is not used to hold a period, it's used to hold a
frequency. Renamed it to "frequency".
3. tcmp is an unsigned value, so (tcmp < 0) will never be true and the if
which checks that condition will never execute. Also, there should be no
problem if the pwm never switches, so there's no reason to subtract one from
tcmp and therefore no reason to compare it against zero. Removed both ifs. If
they weren't removed, tcmp should be a signed value.
4. Add a check for a 0 period.

Test with command "sf probe 1:0; time sf read 40008000 0 1000".
Try with different numbers of bytes and see that sane values are obtained
Build and boot U-boot with this patch, backlight works properly.

Signed-off-by: Gabe Black <gabeblack at google.com>
Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
Acked-by: Simon Glass <sjg at chromium.org>
---
Changes since v2:
        - None.

Changes since v1:
        - Added "Acked-by: Simon Glass".

 arch/arm/cpu/armv7/s5p-common/pwm.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/arch/arm/cpu/armv7/s5p-common/pwm.c b/arch/arm/cpu/armv7/s5p-common/pwm.c
index 02156d1..6f401b8 100644
--- a/arch/arm/cpu/armv7/s5p-common/pwm.c
+++ b/arch/arm/cpu/armv7/s5p-common/pwm.c
@@ -70,7 +70,7 @@ static unsigned long pwm_calc_tin(int pwm_id, unsigned long freq)
        return tin_parent_rate / 16;
 }

-#define NS_IN_HZ (1000000000UL)
+#define NS_IN_SEC 1000000000UL

 int pwm_config(int pwm_id, int duty_ns, int period_ns)
 {
@@ -79,7 +79,7 @@ int pwm_config(int pwm_id, int duty_ns, int period_ns)
        unsigned int offset;
        unsigned long tin_rate;
        unsigned long tin_ns;
-       unsigned long period;
+       unsigned long frequency;
        unsigned long tcon;
        unsigned long tcnt;
        unsigned long tcmp;
@@ -89,34 +89,24 @@ int pwm_config(int pwm_id, int duty_ns, int period_ns)
         * fact that anything faster than 1GHz is easily representable
         * by 32bits.
         */
-       if (period_ns > NS_IN_HZ || duty_ns > NS_IN_HZ)
+       if (period_ns > NS_IN_SEC || duty_ns > NS_IN_SEC || period_ns == 0)
                return -ERANGE;

        if (duty_ns > period_ns)
                return -EINVAL;

-       period = NS_IN_HZ / period_ns;
+       frequency = NS_IN_SEC / period_ns;

        /* Check to see if we are changing the clock rate of the PWM */
-       tin_rate = pwm_calc_tin(pwm_id, period);
+       tin_rate = pwm_calc_tin(pwm_id, frequency);

-       tin_ns = NS_IN_HZ / tin_rate;
+       tin_ns = NS_IN_SEC / tin_rate;
        tcnt = period_ns / tin_ns;

        /* Note, counters count down */
        tcmp = duty_ns / tin_ns;
        tcmp = tcnt - tcmp;

-       /*
-        * the pwm hw only checks the compare register after a decrement,
-        * so the pin never toggles if tcmp = tcnt
-        */
-       if (tcmp == tcnt)
-               tcmp--;
-
-       if (tcmp < 0)
-               tcmp = 0;
-
        /* Update the PWM register block. */
        offset = pwm_id * 3;
        if (pwm_id < 4) {
--
1.8.0



------------------------------

Message: 30
Date: Thu, 28 Mar 2013 10:21:36 -0400
From: Tom Rini <trini at ti.com>
Subject: Re: [U-Boot] [RFC/PATCH 0/4] BCH8 support for OMAP3
To: Andreas Bie??mann <andreas.devel at googlemail.com>
Cc: Scott Wood <scottwood at freescale.com>,       U-Boot Mailing List
        <u-boot at lists.denx.de>
Message-ID: <20130328142136.GC5711 at bill-the-cat>
Content-Type: text/plain; charset="us-ascii"

On Thu, Mar 28, 2013 at 11:49:54AM +0100, Andreas Bie??mann wrote:

> On 11/23/2012 04:14 PM, Andreas Bie??mann wrote:
> > This RFC series implements BCH8 for OMAP3 as provided by linux kernel in commit
> > 0e618ef0a6a33cf7ef96c2c824402088dd8ef48c.
> > This series is heavily influenced by Ilyas series 'NAND support for AM33XX'
> > thus could share some code.
>
> Any comments on that series? I would appreciate to get the BCH8 support
> in for at least the tricorder board.

OK, so, some comments:
- We should pull the gpmc structs out of arch-*/cpu.h and into
  <asm/omap_gpmc.h> which also means merging
  <asm/arch-am33xx/omap_gpmc.h> and <asm/arch-omap3/omap_gpmc.h> but I
  suspect that's easy.
- In terms of 'nandecc' command, I don't like breaking existing
  setup/scripts, so my first thought is "nandecc hw" -> 1bit, "nandecc
  sw" -> sw (both just like today), "nandecc hw bch8" -> bch8 and
  "nandecc hw hamming" -> 1bit, which leaves room down the line for
  someone else to add nandecc hw bch4 -> bch4 (which is possible and I
  know exists in custom solutions somewhere).

> > I have managed to load kernel from an ubifs written by the kernel driver, but is
> > far away from tested thoroughly.
>
> We used that patchset for a while in-house and could not find obvious
> issues. However we need to hack the SPL a bit to get the bigger
> footprint into SRAM with 2013.01.

What exactly did you do?  We _should_ already be taking up all of SRAM
with a few kb saved off for stack.  We might be able to get away with
less stack, but we'd need to check that a bit with the .su files.

> > Cause my NAND device 'NAND device: Manufacturer ID: 0x2c, Chip ID: 0xbc (Micron
> > NAND 512MiB 1,8V 16-bit)' does support 1bit ECC for first sector if erase is
> > less than 1000, the rest requires 4bit ECC. Therefore the SPL needs to support
> > BCH, the impact is about 9k for the SPL.
>
> So my question here is if this series would be accepted for the upcoming
> release. I could work on it next week full time, so if I get a go for
> this release I would do so.

The RFC was well in time, so yes, I'm agreeable given the scope of the
changes.

--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130328/b2caa293/attachment-0001.pgp>

------------------------------

Message: 31
Date: Thu, 28 Mar 2013 15:26:26 +0100
From: Marek Vasut <marex at denx.de>
Subject: Re: [U-Boot] [PATCH 1/7] USB: Some cleanup prior to USB 3.0
        interface addition
To: Vivek Gautam <gautam.vivek at samsung.com>
Cc: patches at linaro.org, u-boot at lists.denx.de,
        rajeshwari.s at samsung.com,       vikas.sajjan at samsung.com
Message-ID: <201303281526.26874.marex at denx.de>
Content-Type: Text/Plain;  charset="us-ascii"

Dear Vivek Gautam,

> Some cleanup in usb framework, nothing much on feature side.
>
> Signed-off-by: Vikas C Sajjan <vikas.sajjan at samsung.com>
> Signed-off-by: Vivek Gautam <gautam.vivek at samsung.com>
> ---
>  common/usb.c         |   18 ++++++++++--------
>  common/usb_storage.c |   30 ++++++++++++++++--------------
>  include/usb_defs.h   |    2 +-
>  3 files changed, 27 insertions(+), 23 deletions(-)
>
> diff --git a/common/usb.c b/common/usb.c
> index 6fc0fc1..40c1547 100644
> --- a/common/usb.c
> +++ b/common/usb.c
> @@ -360,6 +360,7 @@ static int usb_parse_config(struct usb_device *dev,
>       int index, ifno, epno, curr_if_num;
>       int i;
>       u16 ep_wMaxPacketSize;
> +     struct usb_interface *if_desc = NULL;
>
>       ifno = -1;
>       epno = -1;
> @@ -387,23 +388,24 @@ static int usb_parse_config(struct usb_device *dev,
>                            &buffer[index])->bInterfaceNumber != curr_if_num) {
>                               /* this is a new interface, copy new desc */
>                               ifno = dev->config.no_of_if;
> +                             if_desc = &dev->config.if_desc[ifno];
>                               dev->config.no_of_if++;
> -                             memcpy(&dev->config.if_desc[ifno],
> -                                     &buffer[index], buffer[index]);
> -                             dev->config.if_desc[ifno].no_of_ep = 0;
> -                             dev->config.if_desc[ifno].num_altsetting = 1;
> +                             memcpy(if_desc, &buffer[index], buffer[index]);
> +                             if_desc->no_of_ep = 0;
> +                             if_desc->num_altsetting = 1;
>                               curr_if_num =
> -                                  dev-
>config.if_desc[ifno].desc.bInterfaceNumber;
> +                                  if_desc->desc.bInterfaceNumber;
>                       } else {
>                               /* found alternate setting for the interface */
> -                             dev->config.if_desc[ifno].num_altsetting++;
> +                             if_desc->num_altsetting++;

This will crash as if_desc is set in the if() branch above and it will be NULL
in the else{} branch.

>                       }
>                       break;
>               case USB_DT_ENDPOINT:
>                       epno = dev->config.if_desc[ifno].no_of_ep;
> +                     if_desc = &dev->config.if_desc[ifno];
>                       /* found an endpoint */
> -                     dev->config.if_desc[ifno].no_of_ep++;
> -                     memcpy(&dev->config.if_desc[ifno].ep_desc[epno],
> +                     if_desc->no_of_ep++;
> +                     memcpy(&if_desc->ep_desc[epno],
>                               &buffer[index], buffer[index]);
>                       ep_wMaxPacketSize = get_unaligned(&dev->config.\
>                                                       if_desc[ifno].\
> diff --git a/common/usb_storage.c b/common/usb_storage.c
> index fb322b4..475c218 100644
> --- a/common/usb_storage.c
> +++ b/common/usb_storage.c
> @@ -278,10 +278,10 @@ int usb_stor_scan(int mode)
>                            lun++) {
>                               usb_dev_desc[usb_max_devs].lun = lun;
>                               if (usb_stor_get_info(dev, &usb_stor[start],
> -
&usb_dev_desc[usb_max_devs]) == 1) {
> -                             usb_max_devs++;
> -             }
> +                                 &usb_dev_desc[usb_max_devs]) == 1)
> +                                     usb_max_devs++;
>                       }
> +


What is this change here doing?

>               }
>               /* if storage device */
>               if (usb_max_devs == USB_MAX_STOR_DEV) {

[..]

Best regards,
Marek Vasut


------------------------------

Message: 32
Date: Thu, 28 Mar 2013 15:28:03 +0100
From: Marek Vasut <marex at denx.de>
Subject: Re: [U-Boot] [PATCH 2/7] usb: hub: Conditionally power on
        usb's   root-hub ports
To: Vivek Gautam <gautam.vivek at samsung.com>
Cc: patches at linaro.org, u-boot at lists.denx.de,
        rajeshwari.s at samsung.com,       vikas.sajjan at samsung.com
Message-ID: <201303281528.03266.marex at denx.de>
Content-Type: Text/Plain;  charset="us-ascii"

Dear Vivek Gautam,

> Power on root hubs' ports only when they are not yet powered on.
> Its seen with USB 3.0 ports that they are powered on after
> a H/W reset, as also reflected in XHCI spec (sec 4.3):
> "After a Chip Hardware Reset, HCRST, or commanded to the
> PLS = RxDetect state, all Root Hub ports shall be in Disconnected
> state, i.e. the port is powered on (PP = 1)"
>
> Signed-off-by: Amar <amarendra.xt at samsung.com>
> Signed-off-by: Vivek Gautam <gautam.vivek at samsung.com>

Just wondering if we shouldn't power-cycle all the ports instead -- aka. turn
them off and then turn all of them on again.

Best regards,
Marek Vasut


------------------------------

Message: 33
Date: Thu, 28 Mar 2013 15:28:31 +0100
From: Marek Vasut <marex at denx.de>
Subject: Re: [U-Boot] [PATCH 3/7] usb: Update device class in usb
        device's        descriptor
To: Vivek Gautam <gautam.vivek at samsung.com>
Cc: patches at linaro.org, u-boot at lists.denx.de,
        rajeshwari.s at samsung.com,       vikas.sajjan at samsung.com
Message-ID: <201303281528.32150.marex at denx.de>
Content-Type: Text/Plain;  charset="us-ascii"

Dear Vivek Gautam,

> Fetch the device class into usb device's dwcriptors,
> so that the host controller's driver can use this info
> to differentiate between HUB and DEVICE.
>
> Signed-off-by: Amar <amarendra.xt at samsung.com>

Is this a full name? Otherwise this patch is OK.

> ---
>  common/usb.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/common/usb.c b/common/usb.c
> index 40c1547..39fcedd 100644
> --- a/common/usb.c
> +++ b/common/usb.c
> @@ -888,6 +888,11 @@ int usb_new_device(struct usb_device *dev)
>
>       dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0;
>
> +     /* Fetch the device class, driver can use this info
> +      * to differentiate between HUB and DEVICE.
> +      */
> +     dev->descriptor.bDeviceClass = desc->bDeviceClass;
> +
>       /* find the port number we're at */
>       if (parent) {
>               int j;

Best regards,
Marek Vasut


------------------------------

Message: 34
Date: Thu, 28 Mar 2013 15:32:12 +0100
From: Marek Vasut <marex at denx.de>
Subject: Re: [U-Boot] [PATCH 5/7] usb: hub: Increase device
        enumeration     timeout for broken drives
To: Vivek Gautam <gautam.vivek at samsung.com>
Cc: patches at linaro.org, u-boot at lists.denx.de,
        rajeshwari.s at samsung.com,       vikas.sajjan at samsung.com
Message-ID: <201303281532.12603.marex at denx.de>
Content-Type: Text/Plain;  charset="us-ascii"

Dear Vivek Gautam,

> Few broken usb mass storage devices can take some time to set
> Current Connect Status (CCS) and Connect Status Change (CSC) in
> Port status register after an attach.
> So increasing some timeout when both CCS and CSC bits are not set.
>
> Signed-off-by: Amar <amarendra.xt at samsung.com>
> Signed-off-by: Vivek Gautam <gautam.vivek at samsung.com>

Can we not postpone checking of these CCS and CSC bits for such broken devices?
This'd at least allow the "good" devices to be detected quickly and while these
are handled, this would give some time for the "bad" ones to do their job too.

Best regards,
Marek Vasut


------------------------------

Message: 35
Date: Thu, 28 Mar 2013 15:35:20 +0100
From: Marek Vasut <marex at denx.de>
Subject: Re: [U-Boot] [PATCH 6/7] USB: SS: Add support for Super Speed
        USB     interface
To: Vivek Gautam <gautam.vivek at samsung.com>
Cc: patches at linaro.org, u-boot at lists.denx.de,
        rajeshwari.s at samsung.com,       vikas.sajjan at samsung.com
Message-ID: <201303281535.20404.marex at denx.de>
Content-Type: Text/Plain;  charset="us-ascii"

Dear Vivek Gautam,

> This adds usb framework support for super-speed usb, which will
> further facilitate to add stack support for xHCI.
>
> Signed-off-by: Vikas C Sajjan <vikas.sajjan at samsung.com>
> Signed-off-by: Vivek Gautam <gautam.vivek at samsung.com>

[...]

> --- a/include/usb.h
> +++ b/include/usb.h
> @@ -67,6 +67,16 @@ struct devrequest {
>       unsigned short  length;
>  } __attribute__ ((packed));
>
> +struct usb_ep_desc {
> +     struct usb_endpoint_descriptor          ep_desc;
> +     /*
> +      * Super Speed Device will have Super Speed Endpoint
> +      * Companion Descriptor  (section 9.6.7 of usb 3.0 spec)
> +      * Revision 1.0 June 6th 2011
> +      */
> +     struct usb_ss_ep_comp_descriptor        ss_ep_comp;
> +};
> +
>  /* Interface */
>  struct usb_interface {
>       struct usb_interface_descriptor desc;
> @@ -75,7 +85,7 @@ struct usb_interface {
>       unsigned char   num_altsetting;
>       unsigned char   act_altsetting;
>
> -     struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
> +     struct usb_ep_desc ep_desc[USB_MAXENDPOINTS];

Do we really need this struct usb_ep_desc? Can we not just store the
usb_ss_ep_comp_descriptor here as well?

>  } __attribute__ ((packed));
>
>  /* Configuration information.. */
> diff --git a/include/usb_defs.h b/include/usb_defs.h
> index 0c78d9d..e2aaef3 100644
> --- a/include/usb_defs.h
> +++ b/include/usb_defs.h
> @@ -203,6 +203,8 @@
>  #define USB_PORT_FEAT_POWER          8
>  #define USB_PORT_FEAT_LOWSPEED       9
>  #define USB_PORT_FEAT_HIGHSPEED      10
> +#define USB_PORT_FEAT_FULLSPEED      11
> +#define USB_PORT_FEAT_SUPERSPEED     12
>  #define USB_PORT_FEAT_C_CONNECTION   16
>  #define USB_PORT_FEAT_C_ENABLE       17
>  #define USB_PORT_FEAT_C_SUSPEND      18
> @@ -218,8 +220,20 @@
>  #define USB_PORT_STAT_POWER         0x0100
>  #define USB_PORT_STAT_LOW_SPEED     0x0200
>  #define USB_PORT_STAT_HIGH_SPEED    0x0400   /* support for EHCI */
> +#define USB_PORT_STAT_FULL_SPEED    0x0800
> +#define USB_PORT_STAT_SUPER_SPEED   0x1000   /* support for XHCI */
>  #define USB_PORT_STAT_SPEED  \
> -     (USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED)
> +     (USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED | \
> +     USB_PORT_STAT_FULL_SPEED | USB_PORT_STAT_SUPER_SPEED)
> +
> +/*
> + * Additions to wPortStatus bit field from USB 3.0
> + * See USB 3.0 spec Table 10-10
> + */
> +#define USB_PORT_STAT_LINK_STATE     0x01e0
> +#define USB_SS_PORT_STAT_POWER               0x0200
> +#define USB_SS_PORT_STAT_SPEED               0x1c00
> +#define USB_PORT_STAT_SPEED_5GBPS    0x0000
>
>  /* wPortChange bits */
>  #define USB_PORT_STAT_C_CONNECTION  0x0001
> @@ -228,6 +242,14 @@
>  #define USB_PORT_STAT_C_OVERCURRENT 0x0008
>  #define USB_PORT_STAT_C_RESET       0x0010
>
> +/*
> + * Addition to wPortChange bit fields form USB 3.0
> + * See USB 3.0 spec Table 10-11
> + */
> +#define USB_PORT_STAT_C_BH_RESET     0x0020
> +#define USB_PORT_STAT_C_LINK_STATE   0x0040
> +#define USB_PORT_STAT_C_CONFIG_ERROR 0x0080
> +
>  /* wHubCharacteristics (masks) */
>  #define HUB_CHAR_LPSM               0x0003
>  #define HUB_CHAR_COMPOUND           0x0004


------------------------------

Message: 36
Date: Thu, 28 Mar 2013 15:37:57 +0100 (CET)
From: Beno?t Th?baudeau <benoit.thebaudeau at advansee.com>
Subject: Re: [U-Boot] [PATCH v9 01/30] mtd: nand: Introduce
        CONFIG_SYS_NAND_BUSWIDTH_16BIT
To: Albert ARIBAUD <albert.u.boot at aribaud.net>
Cc: Scott Wood <scottwood at freescale.com>, u-boot at lists.denx.de, Fabio
        Estevam <fabio.estevam at freescale.com>
Message-ID:
        <1939467076.972790.1364481477333.JavaMail.root at advansee.com>
Content-Type: text/plain; charset=utf-8

Hi Albert,

On Thursday, March 28, 2013 10:55:29 AM, Albert ARIBAUD wrote:
> Hi Beno?t,
>
> On Wed,  6 Mar 2013 19:59:07 +0100, Beno?t Th?baudeau
> <benoit.thebaudeau at advansee.com> wrote:
>
> > From: Fabio Estevam <fabio.estevam at freescale.com>
> >
> > Introduce CONFIG_SYS_NAND_BUSWIDTH_16BIT option so that other NAND
> > controller
> > drivers could use it when a 16-bit NAND is deployed.
> >
> > drivers/mtd/nand/ndfc has CONFIG_SYS_NDFC_16BIT, so just rename it, so that
> > other NAND drivers could reuse the same symbol.
> >
> > Signed-off-by: Fabio Estevam <fabio.estevam at freescale.com>
> > Reviewed-by: Beno?t Th?baudeau <benoit.thebaudeau at advansee.com>
>
> Sorry, I may have got the info before but I seem not to find it back:
> is this series available somewhere as a branch that I could pull in
> easily for testing?

Yes, in your inbox on March 6, 2013 8:22 PM. ;)

Best regards,
Beno?t


------------------------------

Message: 37
Date: Thu, 28 Mar 2013 11:52:52 -0300
From: Otavio Salvador <otavio at ossystems.com.br>
Subject: Re: [U-Boot] [PATCH 0/5] FSL SECURE BOOT: Add support for
        next level image validation
To: Ruchika Gupta <ruchika.gupta at freescale.com>
Cc: U-Boot Mailing List <u-boot at lists.denx.de>, Andy Fleming
        <afleming at freescale.com>
Message-ID:
        <CAP9ODKpHGA-yUkvofgQqJkpcGfGw7yNk9GH5Z8bgZNJ4EkPB4w at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Mar 28, 2013 at 7:46 AM, Ruchika Gupta
<ruchika.gupta at freescale.com> wrote:
> The patch set adds support for next level image validation (linux,
> rootfs, dtb) in secure boot scenarios.

It seems to focus in PowerPC, do you know if same code could be ported to ARM?

--
Otavio Salvador                             O.S. Systems
E-mail: otavio at ossystems.com.br  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br


------------------------------

Message: 38
Date: Thu, 28 Mar 2013 08:59:05 -0600
From: Stephen Warren <swarren at wwwdotorg.org>
Subject: Re: [U-Boot] [PATCH V2] ARM: bcm2835: fix get_timer() to
        return ms
To: Albert ARIBAUD <albert.u.boot at aribaud.net>
Cc: u-boot at lists.denx.de
Message-ID: <51545AB9.5050309 at wwwdotorg.org>
Content-Type: text/plain; charset=ISO-8859-1

On 03/28/2013 05:15 AM, Albert ARIBAUD wrote:
> Hi Stephen,
>
> On Wed, 27 Mar 2013 22:43:23 -0600, Stephen Warren
> <swarren at wwwdotorg.org> wrote:
>
>> Apparently, CONFIG_SYS_HZ must be 1000. Change this, and fix the timer
>> driver to conform to this.
>>
>> Have the timer implementation export a custom API get_timer_us() for use
>> by the BCM2835 MMC API, which needs us resolution for a HW workaround.
>>
>> Signed-off-by: Stephen Warren <swarren at wwwdotorg.org>
>> ---
>> v2: Export custom API get_timer_us() to allow the MMC driver to maintain
>>     its current workaround implementation.
>> ---
>
> This patch and "mmc: bcm2835: fix delays in bug workaround" cannot be
> both applied together. Can you do a V2 for the delays fix patch too?

This patch replaces the two previous separate patches. Only this one
needs to be applied.



------------------------------

Message: 39
Date: Thu, 28 Mar 2013 08:08:47 -0700
From: Tom Warren <twarren.nvidia at gmail.com>
Subject: Re: [U-Boot] Merge conflict on Tegra SPI between
        u-boot/master and       u-boot-arm/master
To: Albert ARIBAUD <albert.u.boot at aribaud.net>
Cc: Tom Rini <trini at ti.com>, U-Boot <u-boot at lists.denx.de>
Message-ID:
        <CA+m5__JN+V-o1shbFTrtnzRqk4U5Qb6qDdbrGV78js9JTqbHOg at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Albert,


On Thu, Mar 28, 2013 at 6:38 AM, Albert ARIBAUD
<albert.u.boot at aribaud.net>wrote:

> Hello all,
>
> While preparing for an ARM PR, specifically a merge between commit
> 417c55803118eb8e350d5ab8ba6583fb39f4e2e3 (current u-boot/master ToT)
> and commit d53e340edf65ff253d3a7b06ebe60501045892e3 (current Tot for
> u-boot-arm/master), I hit the following merge conflicts:
>
> CONFLICT (content): Merge conflict in lib/fdtdec.c
> CONFLICT (content): Merge conflict in include/fdtdec.h
> CONFLICT (content): Merge conflict in drivers/spi/tegra20_sflash.c
>
> While the first two, related to FDT, are simple (colliding additions to
> the same enum from both branches) and can be manually resolved, the
> third one, drivers/spi/tegra20_sflash.c, is not, and can not, at least,
> not by me, as I am not a specialist on Tegra SPI.
>
> Tom (Warren), can you advise on how to best solve this?
>
Let me take a look  - IIRC, Simon's use of spi_alloc_slave() was the only
change to tegra20_sflash.c (replaces the normal malloc() in
tegra20_spi_setup_slave()).

Here's a diff of the only change to tegra20_sflash.c (merging Allen's Tegra
SPI changes and Simon's SPI changes):

--- drivers/spi/tegra20_sflash.c 2013-03-22 08:43:02.373219315 -0700
+++ /home/tom/denx/u-boot-arm/drivers/spi/tegra20_sflash.c 2013-03-28
08:04:04.899860607 -0700
@@ -127,7 +127,7 @@
  return NULL;
  }

- spi = spi_alloc_slave(struct tegra_spi_slave, bus, cs);
+ spi = malloc(sizeof(struct tegra_spi_slave));
  if (!spi) {
  printf("SPI error: malloc of SPI structure failed\n");
  return NULL;

Let me know if that's not enough for you to resolve this,

Tom

>
> Amicalement,
> --
> Albert.
>

------------------------------

Message: 40
Date: Thu, 28 Mar 2013 09:10:43 -0600
From: Stephen Warren <swarren at wwwdotorg.org>
Subject: Re: [U-Boot] [PATCH] ARM: bcm2835: fix get_timer() to return
        mS
To: Albert ARIBAUD <albert.u.boot at aribaud.net>
Cc: u-boot at lists.denx.de
Message-ID: <51545D73.4030806 at wwwdotorg.org>
Content-Type: text/plain; charset=ISO-8859-1

On 03/28/2013 03:00 AM, Albert ARIBAUD wrote:
> Hi Stephen,
>
> On Thu, 21 Mar 2013 21:32:30 -0600, Stephen Warren
> <swarren at wwwdotorg.org> wrote:
>
>> Apparently, CONFIG_SYS_HZ must be 1000. Change this, and fix the timer
>> driver to conform to this.
>
> Is this a fix to some known issue or bug?

Yes. The bootdelay timeout implementation was recently(?) changed and
the new code doesn't use CONFIG_SYS_HZ at all, but rather assumes that
it's 1000. Since rpi_b's SYS_HZ was 1000000, the bootdelay runs by far
too fast. This fixes that.


------------------------------

Message: 41
Date: Thu, 28 Mar 2013 16:14:08 +0100
From: Albert ARIBAUD <albert.u.boot at aribaud.net>
Subject: Re: [U-Boot] [PATCH V2] ARM: bcm2835: fix get_timer() to
        return ms
To: Stephen Warren <swarren at wwwdotorg.org>
Cc: u-boot at lists.denx.de
Message-ID: <20130328161408.5341886b at lilith>
Content-Type: text/plain; charset=US-ASCII

Hi Stephen,

On Thu, 28 Mar 2013 08:59:05 -0600, Stephen Warren
<swarren at wwwdotorg.org> wrote:

> On 03/28/2013 05:15 AM, Albert ARIBAUD wrote:
> > Hi Stephen,
> >
> > On Wed, 27 Mar 2013 22:43:23 -0600, Stephen Warren
> > <swarren at wwwdotorg.org> wrote:
> >
> >> Apparently, CONFIG_SYS_HZ must be 1000. Change this, and fix the timer
> >> driver to conform to this.
> >>
> >> Have the timer implementation export a custom API get_timer_us() for use
> >> by the BCM2835 MMC API, which needs us resolution for a HW workaround.
> >>
> >> Signed-off-by: Stephen Warren <swarren at wwwdotorg.org>
> >> ---
> >> v2: Export custom API get_timer_us() to allow the MMC driver to maintain
> >>     its current workaround implementation.
> >> ---
> >
> > This patch and "mmc: bcm2835: fix delays in bug workaround" cannot be
> > both applied together. Can you do a V2 for the delays fix patch too?
>
> This patch replaces the two previous separate patches. Only this one
> needs to be applied.

Ok -- thanks. Will soon (i.e., in one hour at most) be available in
u-boot-arm/master.

Amicalement,
--
Albert.


------------------------------

Message: 42
Date: Thu, 28 Mar 2013 16:16:06 +0100
From: Albert ARIBAUD <albert.u.boot at aribaud.net>
Subject: Re: [U-Boot] [PATCH v9 01/30] mtd: nand: Introduce
        CONFIG_SYS_NAND_BUSWIDTH_16BIT
To: Beno?t Th?baudeau <benoit.thebaudeau at advansee.com>
Cc: Fabio Estevam <fabio.estevam at freescale.com>, Stefano,
        u-boot at lists.denx.de,   Scott Wood <scottwood at freescale.com>
Message-ID: <20130328161606.0c66af14 at lilith>
Content-Type: text/plain; charset=UTF-8

Hi Beno?t,

On Thu, 28 Mar 2013 15:37:57 +0100 (CET), Beno?t Th?baudeau
<benoit.thebaudeau at advansee.com> wrote:

> Hi Albert,
>
> On Thursday, March 28, 2013 10:55:29 AM, Albert ARIBAUD wrote:
> > Hi Beno?t,
> >
> > On Wed,  6 Mar 2013 19:59:07 +0100, Beno?t Th?baudeau
> > <benoit.thebaudeau at advansee.com> wrote:
> >
> > > From: Fabio Estevam <fabio.estevam at freescale.com>
> > >
> > > Introduce CONFIG_SYS_NAND_BUSWIDTH_16BIT option so that other NAND
> > > controller
> > > drivers could use it when a 16-bit NAND is deployed.
> > >
> > > drivers/mtd/nand/ndfc has CONFIG_SYS_NDFC_16BIT, so just rename it, so that
> > > other NAND drivers could reuse the same symbol.
> > >
> > > Signed-off-by: Fabio Estevam <fabio.estevam at freescale.com>
> > > Reviewed-by: Beno?t Th?baudeau <benoit.thebaudeau at advansee.com>
> >
> > Sorry, I may have got the info before but I seem not to find it back:
> > is this series available somewhere as a branch that I could pull in
> > easily for testing?
>
> Yes, in your inbox on March 6, 2013 8:22 PM. ;)

Oh, ok. I'd thought that was v8. I'll pull this in as soon as the
current mainline/ARM merge issue is solved.

> Best regards,
> Beno?t

Amicalement,
--
Albert.


------------------------------

Message: 43
Date: Thu, 28 Mar 2013 08:16:37 -0700
From: Tom Warren <twarren.nvidia at gmail.com>
Subject: Re: [U-Boot] Merge conflict on Tegra SPI between
        u-boot/master and       u-boot-arm/master
To: Albert ARIBAUD <albert.u.boot at aribaud.net>
Cc: Tom Rini <trini at ti.com>, U-Boot <u-boot at lists.denx.de>
Message-ID:
        <CA+m5__Lt_tKrWnYMQEDgaFVcL1WdJDAXBDC9iFaDDcX6-9whvQ at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Albert,


On Thu, Mar 28, 2013 at 8:08 AM, Tom Warren <twarren.nvidia at gmail.com>wrote:

> Albert,
>
>
> On Thu, Mar 28, 2013 at 6:38 AM, Albert ARIBAUD <albert.u.boot at aribaud.net
> > wrote:
>
>> Hello all,
>>
>> While preparing for an ARM PR, specifically a merge between commit
>> 417c55803118eb8e350d5ab8ba6583fb39f4e2e3 (current u-boot/master ToT)
>> and commit d53e340edf65ff253d3a7b06ebe60501045892e3 (current Tot for
>> u-boot-arm/master), I hit the following merge conflicts:
>>
>> CONFLICT (content): Merge conflict in lib/fdtdec.c
>> CONFLICT (content): Merge conflict in include/fdtdec.h
>> CONFLICT (content): Merge conflict in drivers/spi/tegra20_sflash.c
>>
>> While the first two, related to FDT, are simple (colliding additions to
>> the same enum from both branches) and can be manually resolved, the
>> third one, drivers/spi/tegra20_sflash.c, is not, and can not, at least,
>> not by me, as I am not a specialist on Tegra SPI.
>>
>> Tom (Warren), can you advise on how to best solve this?
>>
> Let me take a look  - IIRC, Simon's use of spi_alloc_slave() was the only
> change to tegra20_sflash.c (replaces the normal malloc() in
> tegra20_spi_setup_slave()).
>
> Here's a diff of the only change to tegra20_sflash.c (merging Allen's
> Tegra SPI changes and Simon's SPI changes):
>
> --- drivers/spi/tegra20_sflash.c 2013-03-22 08:43:02.373219315 -0700
> +++ /home/tom/denx/u-boot-arm/drivers/spi/tegra20_sflash.c 2013-03-28
> 08:04:04.899860607 -0700
> @@ -127,7 +127,7 @@
>   return NULL;
>   }
>
> - spi = spi_alloc_slave(struct tegra_spi_slave, bus, cs);
> + spi = malloc(sizeof(struct tegra_spi_slave));
>   if (!spi) {
>   printf("SPI error: malloc of SPI structure failed\n");
>   return NULL;
>
> Let me know if that's not enough for you to resolve this,
>
> Tom
>

Just confirmed - in tegra20_sflash.c, remove the <<<<< HEAD section (#ifdef
CONFIG_OF_CONTROL + 2 lines), and keep the "tegra: spi remove non fdt
support" section (spi->slave.bus = bus + 4 lines).

Tom

>
>> Amicalement,
>> --
>> Albert.
>>
>
>

------------------------------

Message: 44
Date: Thu, 28 Mar 2013 11:21:27 -0400
From: Tom Rini <trini at ti.com>
Subject: Re: [U-Boot] [PATCH 1/1 v2] omap3_beagle: Enabling UART3
        first allows the Transmitter to be empty
To: Andreas Bie??mann <andreas.devel at googlemail.com>
Cc: Scott Wood <scottwood at freescale.com>, u-boot at lists.denx.de
Message-ID: <20130328152127.GD5711 at bill-the-cat>
Content-Type: text/plain; charset="us-ascii"

On Thu, Mar 28, 2013 at 10:50:44AM +0100, Andreas Bie??mann wrote:
> Hi Javier,
>
> On 03/28/2013 10:11 AM, Javier Martinez Canillas wrote:
> > On Thu, Mar 28, 2013 at 9:45 AM, Andreas Bie??mann
> > <andreas.devel at googlemail.com> wrote:
> >> Dear Manfred Huber,
> >>
> >> On 03/28/2013 07:06 AM, Manfred Huber wrote:
> >>> On 2013-03-27 14:37, Andreas Bie??mann wrote:
>
> <snip>
>
> >>> The reason to setup the baud is for the shift register. It only works
> >>> with programmed baud registers. A soft reset would also work, but as
> >>> Scott Wood said it would corrupt the last character. On the other hand
> >>> the character should be corrupted by disabling the UART. I have no
> >>> preferred solution: programming the UART or a soft reset. Maybe someone
> >>> wants to decide.
> >>
> >> Well, I think also that re-programming the UART will destroy the last
> >> character in shift register anyway.
> >> I wonder which use-case requires UART flushing in u-boot context before
> >> initializing the UART for u-boot correctly. Can someone explain this to
> >> me? Shouldn't we always start here from the very beginning and setup
> >> UART as configured?

We shouldn't be concerned with what is destroyed here as it's going to
be related to ROM trying (and then failing and moving on from) to load
via UART the next program.  We've already started and are running, so
the UART is ours to do with as we need.  If ROM did load us over UART it
really should already be in a clean state.

> <snip>
>
> > When I first hit this bug I tried removing the serial debug cable and
> > this made my IGEPv2 to boot correctly. Then I looked at the latest
> > changes to the serial ns16550 driver and found that cb55b332
> > "serial/ns16550: wait for TEMT before initializing" was the culprit
> > commit that made my board to not boot.
>
> Thanks for clarification. So there is a need to flush UART before
> initializing it in u-boot context as said by Scott's comment in
> cb55b332, at least for some systems.
>
> I think Manfred's proposed solution in this patch is ok. It fixes a bug
> when transiting from (some) OMAP ROM code to SPL, therefore we should
> have the code conditionally on SPL and OMAP. Maybe we find out later,
> that this also matches other combinations. But for now I think we should
> just take Manfred's solution in this release, Tom?

Agreed.

> Many thanks to you Manfred for forcing attention on this bug and
> providing a solution.

And also very much agreed!

--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130328/598a67b1/attachment-0001.pgp>

------------------------------

Message: 45
Date: Thu, 28 Mar 2013 11:21:49 -0400
From: Tom Rini <trini at ti.com>
Subject: Re: [U-Boot] [PATCH 1/1 v2] omap3_beagle: Enabling UART3
        first allows the Transmitter to be empty
To: Manfred Huber <man.huber at arcor.de>
Cc: Scott Wood <scottwood at freescale.com>, u-boot at lists.denx.de
Message-ID: <20130328152149.GE5711 at bill-the-cat>
Content-Type: text/plain; charset="us-ascii"

On Wed, Mar 27, 2013 at 05:50:17AM +0100, Manfred Huber wrote:

> Please test the Patch. It is very simple on a Beagleboard. I guess you
> have flashed the actual SPL and u-boot and Beagleboard boots correctly.
> Now press and hold 'User' button and connect power. SPL should hang.
> You can see some symbols on the console from the ROM code.

I cannot reproduce this problem on my Beagleboard C5.  I note this
only so it's clear I tried things out.  I'm still supportive of the
changes overall as they also don't break anything here.  I'm also still
waiting to hear back from some folks that might know what the ROM code
does or doesn't do.

--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20130328/ae913832/attachment.pgp>

------------------------------

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


End of U-Boot Digest, Vol 58, Issue 49
**************************************


-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.



More information about the U-Boot mailing list