motorola: dlkm: Add Cypress Capsense

Add the Cypress Capsense DLKM.

Change-Id: Ia38e38d0042431be56ed20ec800b9b70bca032c9
Signed-off-by: Kenny Kessler <kenny.kessler@motorola.com>
Reviewed-on: https://gerrit.mot.com/1099054
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Kenneth Kessler <kennykessler@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
Kenny Kessler 2017-12-04 09:53:44 -06:00 • committed by Kenneth Kessler
commit 6f78313042
17 changed files with 4757 additions and 0 deletions

View file

@ -0,0 +1,8 @@
DLKM_DIR := motorola/kernel/modules
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cyttsp_sar.ko
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT)
include $(DLKM_DIR)/AndroidKernelModule.mk

View file

@ -0,0 +1,251 @@
/*****************************************************************************
* File Name: DataFetch.c
* Version 1.0
*
* Description:
* This source file contains the functions to fetch data from the Hex image and
* load in to the arrays used for Programming.
*
* Owner:
* Tushar Rastogi, Application Engineer (tusr@cypress.com)
*
* Related Document:
* AN84858 - PSoC 4 Programming using an External Microcontroller (HSSP)
*
* Hardware Dependency:
* PSoC 5LP Development Kit - CY8CKIT-050
*
* Code Tested With:
* PSoC Creator 2.2
* ARM GCC 4.4.1
* CY8CKIT-050
*
* Note:
* The definitions of the functions used in this file will change based on the
* interface used to get Hex file data.
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
/******************************************************************************
* Header file Inclusion
******************************************************************************/
#include "cycapsense_hssp.h"
#include "DataFetch.h"
/******************************************************************************
* Global Constant declaration
******************************************************************************/
/******************************************************************************
* Function Definitions
******************************************************************************/
/***************************** USER ATTENTION REQUIRED ************************
**************** DEPENDS ON INTERFACE USED TO GET HEX FILE DATA ***************
All the function definitions below should be modified based on the interface
used to get Hex file data to be programmed. If a protocol like I2C, UART is
used to get the hex file data, change the function definitions accordingly */
/******************************************************************************
* Function Name: HEX_ReadSiliconId
*******************************************************************************
*
* Summary:
* Loads the Device Silicon ID data in to an array
*
* Parameters:
* unsigned long *hexSiliconId - Address of variable which will store the
* Silicon ID fetched
*
* Return:
* None.
*
* Note:
* Modify definition based on method of getting programming data
*
******************************************************************************/
void HEX_ReadSiliconId(struct hex_info *inf, unsigned long *hexSiliconId)
{
unsigned char i;
if (!inf || !inf->m_data)
return;
for (i = 0; i < SILICON_ID_BYTE_LENGTH; i++) {
*hexSiliconId = *hexSiliconId |
((unsigned long)(inf->m_data[2 + i]) << (8 * i));
}
}
/******************************************************************************
* Function Name: HEX_ReadRowData
*******************************************************************************
*
* Summary:
* Loads the row data from hex file in to an array
*
* Parameters:
* unsigned short rowCount - Flash row count for which the data has to be
* fetched
* unsigned char * rowData - Base address of array which will store the
* Flash row data fetched
*
* Return:
* None.
*
* Note:
* Modify definition based on the method of getting programming data
*
* REMOVE THIS LOGIC WHILE PORTING THE HSSP CODE TO OTHER HOST PROGRAMMER
*
******************************************************************************/
void HEX_ReadRowData(struct hex_info *inf, unsigned short rowCount,
unsigned char *rowData)
{
unsigned short i; /* Maximum value of 'i' can be 256 */
if (!inf || !inf->data)
return;
for (i = 0; i < FLASH_ROW_BYTE_SIZE_HEX_FILE; i++) {
rowData[i] =
inf->data[i + rowCount * FLASH_ROW_BYTE_SIZE_HEX_FILE];
}
}
/******************************************************************************
* Function Name: HEX_ReadChipProtectionData
*******************************************************************************
*
* Summary:
* Loads the Chip Protection data in to an array
*
* Parameters:
*
* unsigned char * chipProtectionData - Address of variable which will store
* the Chip Protection data fetched
*
* Return:
* None.
*
* Note:
* Modify definition based on the method of getting programming data
*
******************************************************************************/
void HEX_ReadChipProtectionData(struct hex_info *inf,
unsigned char *chipProtectionData)
{
if (inf)
*chipProtectionData = inf->cl_protection;
else
*chipProtectionData = 1;
}
/******************************************************************************
* Function Name: HEX_ReadRowProtectionData
*******************************************************************************
*
* Summary:
* Loads the Flash Row Protection data in to an array
*
* Parameters:
*
* unsigned char * rowProtectionData - Base address of array which will store
* the Flash Row Protection data fetched
* unsigned char rowProtectionByteSize - Size of flash row protection settings
* in bytes
*
* Return:
* None.
*
* Note:
* Modify definition based on the method of getting programming data
*
******************************************************************************/
void HEX_ReadRowProtectionData(struct hex_info *inf,
unsigned char rowProtectionByteSize,
unsigned char *rowProtectionData)
{
if (!inf || !inf->s_data)
return;
memcpy(rowProtectionData, inf->s_data, rowProtectionByteSize);
}
/******************************************************************************
* Function Name: HEX_ReadChecksumData
*******************************************************************************
*
* Summary:
* Loads the Checksum data in to an array
*
* Parameters:
* unsigned short * checksumData - Base address of the array which will store
* the Checksum data fetched
*
* Return:
* None.
*
* Note:
* Modify definition based on the method of getting programming data
*
******************************************************************************/
void HEX_ReadChecksumData(struct hex_info *inf, unsigned short *checksumData)
{
if (!inf)
return;
*checksumData = inf->cs;
}
/******************************************************************************
* Function Name: GetFlashRowCount
*******************************************************************************
*
* Summary:
* Returns the total number of Flash rows in the target PSoC 4 device
*
* Parameters:
* None
*
* Return:
* unsigned short
* Total number of Flash rows in target PSoC 4
*
* Note:
* The Flash row count is from the HexImage.h file. Modify the definition based
* on the method of getting programming data
*
******************************************************************************/
unsigned short GetFlashRowCount(void)
{
return NUMBER_OF_FLASH_ROWS_HEX_FILE;
}
/* [] END OF FILE */

View file

@ -0,0 +1,71 @@
/******************************************************************************
* File Name: DataFetch.h
* Version 1.0
*
* Description:
* This header file contains the definitions for the size of Programming data,
* and declarations for the functions used in getting the Programming data
* from Hex file image. The fuction definitions in corresponding
* DataFetch.c file will have to be modified if the method of getting
* programming data is changed.
*
* Note:
*
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
#ifndef __DATAFETCH_H
#define __DATAFETCH_H
/******************************************************************************
* Macro definitions
******************************************************************************/
/* The below definitions are not dependent on hex file and are always
constant */
#define SILICON_ID_BYTE_LENGTH 4
#define CHECKSUM_BYTE_LENGTH 2
#define MAXIMUM_ROW_PROTECTION_BYTE_LENGTH 32
/******************************************************************************
* Function Prototypes
******************************************************************************/
void HEX_ReadSiliconId(struct hex_info *inf, unsigned long *hexSiliconId);
void HEX_ReadRowData(struct hex_info *inf, unsigned short rowCount,
unsigned char *rowData);
void HEX_ReadChipProtectionData(struct hex_info *inf,
unsigned char *chipProtectionData);
void HEX_ReadRowProtectionData(struct hex_info *inf,
unsigned char rowProtectionByteSize,
unsigned char *rowProtectionData);
void HEX_ReadChecksumData(struct hex_info *inf, unsigned short *checksumData);
unsigned short GetFlashRowCount(void);
#endif /* __DATAFETCH_H */
/* [] END OF FILE */

View file

@ -0,0 +1,13 @@
# add -Wall to try to catch everything we can.
EXTRA_CFLAGS += -Wall
EXTRA_CFLAGS += -I$(TOP)/motorola/kernel/modules/include
EXTRA_CFLAGS += -DCY8C40xx_FAMILY
KBUILD_EXTRA_SYMBOLS += $(CURDIR)/$(KBUILD_EXTMOD)/../../sensors/Module.symvers
cyttsp_sar-y := ProgrammingSteps.o \
SWD_PacketLayer.o \
SWD_UpperPacketLayer.o \
DataFetch.o \
cyttsp_sar_mmi.o
obj-m += cyttsp_sar.o

View file

@ -0,0 +1,11 @@
KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build
all:
$(MAKE) -C $(KERNEL_SRC) M=$(shell pwd) modules $(KBUILD_OPTIONS)
modules_install:
$(MAKE) INSTALL_MOD_STRIP=1 -C $(KERNEL_SRC) M=$(shell pwd) modules_install
clean:
$(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,149 @@
/******************************************************************************
* File Name: ProgrammingSteps.h
* Version 1.0
*
* Description:
* This header file contains high level definitions and function declarations
* associated with programming of the target PSoC 4 device
*
* Note:
*
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
#ifndef __PROGRAMMINGSTEPS_H
#define __PROGRAMMINGSTEPS_H
#include "cycapsense_hssp.h"
/******************************************************************************
* Macro definitions
******************************************************************************/
/* Return value definitions for high level Programming functions */
#ifndef FAILURE
#define FAILURE 0
#endif
#ifndef SUCCESS
#define SUCCESS (!FAILURE)
#endif
/* Return value of PollSromStatus function */
#define SROM_SUCCESS 0x01
/* Error codes returned by Swd_PacketAck whenever any top-level step returns a
failure status*/
/* This bit field is set if programmer fails to acquire the device in 1.5 ms */
#define PORT_ACQUIRE_TIMEOUT_ERROR 0x10
/* This bit field is set if the SROM does not return the success status code
within the SROM Polling timeout duration*/
#define SROM_TIMEOUT_ERROR 0x20
/* This bit field is set in case of JTAG ID mismatch or Flash data verification
mismatch or Checksum data mismatch */
#define VERIFICATION_ERROR 0x40
/* This bit field is set if wrong transition of chip protection settings is
detected */
#define TRANSITION_ERROR 0x80
/* Constants for Address Space of CPU */
#if defined CY8C40xx_FAMILY
#define CPUSS_SYSREQ 0x40100004
#define CPUSS_SYSARG 0x40100008
#else
#define CPUSS_SYSREQ 0x40000004
#define CPUSS_SYSARG 0x40000008
#endif
#define TEST_MODE 0x40030014
#define SRAM_PARAMS_BASE 0x20000100
#define SFLASH_MACRO 0x0FFFF000
#define SFLASH_CPUSS_PROTECTION 0x0FFFF07C
/* SROM Constants */
#define SROM_KEY1 0xB6
#define SROM_KEY2 0xD3
#define SROM_SYSREQ_BIT 0x80000000
#define SROM_PRIVILEGED_BIT 0x10000000
#define SROM_STATUS_SUCCEEDED 0xA0000000
#define SROM_STATUS_FAILED 0xF0000000
/* SROM Commands */
#define SROM_CMD_GET_SILICON_ID 0x00
#define SROM_CMD_LOAD_LATCH 0x04
#define SROM_CMD_PROGRAM_ROW 0x06
#define SROM_CMD_ERASE_ALL 0x0A
#define SROM_CMD_CHECKSUM 0x0B
#define SROM_CMD_WRITE_PROTECTION 0x0D
#if defined CY8C40xx_FAMILY
#define SROM_CMD_SET_IMO_48MHZ 0x15
#endif
/* Chip Level Protection */
#define CHIP_PROT_VIRGIN 0x00
#define CHIP_PROT_OPEN 0x01
#define CHIP_PROT_PROTECTED 0x02
#define CHIP_PROT_KILL 0x04
/* Mask for status code returned by polling SROM */
#define SROM_STATUS_SUCCESS_MASK 0xF0000000
/* Constant for computing checksum of entire flash */
#define CHECKSUM_ENTIRE_FLASH 0x8000
/* Constant DAP ID of ARM Cortex M0 CPU */
#define CM0_DAP_ID 0x0BC11477
#define CM0PLUS_DAP_ID 0x0BC11477
/* Constant maximum number of rows in PSoC 4 */
#define ROWS_PER_ARRAY 256
/******************************************************************************
* Function Prototypes
******************************************************************************/
unsigned char DeviceAcquire(void);
unsigned char VerifySiliconId(struct hssp_data *d);
unsigned char EraseAllFlash(struct hssp_data *d);
unsigned char ChecksumPrivileged(struct hssp_data *d);
unsigned char ProgramFlash(struct hssp_data *d);
unsigned char VerifyFlash(struct hssp_data *d);
unsigned char ProgramProtectionSettings(struct hssp_data *d);
unsigned char VerifyProtectionSettings(struct hssp_data *d);
unsigned char VerifyChecksum(struct hssp_data *d);
unsigned char VerifySwRevision(struct hssp_data *d);
void ExitProgrammingMode(void);
unsigned char ReadHsspErrorStatus(void);
unsigned char ReadSromStatus(void);
#endif /* __PROGRAMMINGSTEPS_H */
/* [] END OF FILE */

View file

@ -0,0 +1,621 @@
/******************************************************************************
* File Name: SWD_PacketLayer.c
* Version 1.0
*
* Description:
* This file provides the source code for the packet layer functions of the
* SWD protocol. This includes SWD Read packet, SWD Write packet.
*
* Owner:
* Tushar Rastogi, Application Engineer (tusr@cypress.com)
*
* Related Document:
* AN84858 - PSoC 4 Programming using an External Microcontroller (HSSP)
*
* Hardware Dependency:
* PSoC 5LP Development Kit - CY8CKIT-050
*
* Code Tested With:
* PSoC Creator 2.2
* ARM GCC 4.4.1
* CY8CKIT-050
*
* Note:
* The functions in SWD packet layer use the bit banging macros, functions
* in "SWD_PhysicalLayer.h"
*
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
/******************************************************************************
* Header file Inclusion
******************************************************************************/
#include "SWD_PacketLayer.h"
/* "SWD_PhysicalLayer.h" file contains the bit banging routines for
programming */
#include "SWD_PhysicalLayer.h"
/******************************************************************************
* Global Variable definitions
******************************************************************************/
/* Stores the 8-bit SWD Packet header */
unsigned char swd_PacketHeader;
/* Stores the 3-bit SWD Packet ACK data */
unsigned char swd_PacketAck;
/* 4-byte Read, Write packet data */
unsigned char swd_PacketData[DATA_BYTES_PER_PACKET];
/******************************************************************************
* Function Definitions
******************************************************************************/
/******************************************************************************
* Function Name: Swd_SendByte
*******************************************************************************
*
* Summary:
* Sends a byte of data on the SWD lines (SWDIO, SWDCK)
*
* Parameters:
* txByte: Data byte to be sent by host on SWDIO line (Least significant bit
* sent first)
*
* Return:
* None.
*
* Note:
* This function is called for sending SWD header data in SWD Read/Write
* packets, and also to send data in a SWD Write packet.
*
******************************************************************************/
static void Swd_SendByte(unsigned char txByte)
{
unsigned char loop = 0;
/* Loop for 8-bits of a byte */
for (loop = 0; loop < 8; loop++) {
if (txByte & LSB_BIT_MASK) { /* Send a '1' */
SetSwdckLow();
SetSwdioHigh();
SetSwdckHigh();
} else { /* Send a '0' */
SetSwdckLow();
SetSwdioLow();
SetSwdckHigh();
}
txByte = txByte >> 1; /* Make the next bit to send as LS bit */
}
}
/******************************************************************************
* Function Name: Swd_ReceiveByte
*******************************************************************************
*
* Summary:
* Receives a byte of data on the SWD lines (SWDIO, SWDCK)
*
* Parameters:
* None.
*
* Return:
* rxByte: Data byte received by host on SWDIO line (Least significant bit is
* first received bit)
*
* Note:
* This function is called for reading data bytes in a SWD Read Packet
*
******************************************************************************/
static unsigned char Swd_ReceiveByte(void)
{
unsigned char loop = 0;
unsigned char rxBit = 0;
unsigned char rxByte = 0;
/* Loop for 8-bits of a byte */
for (loop = 0; loop < 8; loop++) {
SWDCK_OUTPUT_LOW;
/* Read the SWDIO input line */
rxBit = ReadSwdio();
SWDCK_OUTPUT_HIGH;
rxByte = rxByte >> 1;
if (rxBit) { /* Received a '1' */
rxByte = rxByte | MSB_BIT_MASK;
} else { /* Received a '0' */
rxByte = rxByte & (~MSB_BIT_MASK);
}
}
return rxByte;
}
/******************************************************************************
* Function Name: Swd_FirstTurnAroundPhase
*******************************************************************************
*
* Summary:
* Generates one SWDCK clock cycle for Turnaround phase of a SWD packet.
* SWDIO drive mode is changed to High-Z drive mode so that the host can read
* the data on the SWDIO.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* This function is called during SWD Read/Write packets
*
******************************************************************************/
static void Swd_FirstTurnAroundPhase(void)
{
/* Change to High-Z drive mode for host to read the SWDIO line */
SetSwdioHizInput();
SetSwdckLow();
SetSwdckHigh();
}
/******************************************************************************
* Function Name: Swd_SecondTurnAroundPhase
*******************************************************************************
*
* Summary:
* Generates one SWDCK clock cycle for Turnaround phase of a SWD packet.
* SWDIO drive mode is changed to CMOS output drive mode so that the host can
* write data on SWDIO.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* This function is called during SWD Read/Write packets
*
******************************************************************************/
static void Swd_SecondTurnAroundPhase(void)
{
/* Change to CMOS output drive mode for host to write to SWDIO */
SetSwdioCmosOutput();
SetSwdckLow();
SetSwdckHigh();
}
/******************************************************************************
* Function Name: Swd_GetAckSegment
********************************************************************************
*
* Summary:
* Gets the 3-bit ACK response in a SWD packet
*
* Parameters:
* None.
*
* Return:
* ack:
* 3-bit ACK response is returned as a byte. Three possible return values are:
* 0x01 - SWD_OK_ACK
* 0x02 - SWD_WAIT_ACK
* 0x04 - SWD_FAULT_ACK
* Any other return value - Undefined ACK code.
* Treat it similar to SWD_FAULT_ACK and abort operation.
*
* Note:
* This function is called during SWD Read/Write packets
*
******************************************************************************/
static unsigned char Swd_GetAckSegment(void)
{
unsigned char ack = 0;
unsigned char receiveBit = 0;
unsigned char loop = 0;
/* ACK bits are received lsb bit first */
for (loop = 0; loop < NUMBER_OF_ACK_BITS; loop++) {
SetSwdckLow();
/* Store the ACK bit received */
receiveBit = ReadSwdio();
SetSwdckHigh();
/* Concatenate the ACK bit with ACK data byte */
ack = ack | (receiveBit << loop);
}
return ack;
}
/******************************************************************************
* Function Name: Swd_SendParity
*******************************************************************************
*
* Summary:
* Sends the 1-bit parity data on SWD lines
*
* Parameters:
* parity:
* 1-bit parity data received as a byte (either '1' or '0')
*
* Return:
* None.
*
* Note:
* This function is called during SWD Write packet
*
******************************************************************************/
static void Swd_SendParity(unsigned char parity)
{
/* Make the clock low, Send SWDIO data, Make Clock high */
SetSwdckLow();
if (parity)
SetSwdioHigh();
else
SetSwdioLow();
SetSwdckHigh();
}
/******************************************************************************
* Function Name: Swd_ReceiveParity
*******************************************************************************
*
* Summary:
* Receives the 1-bit parity data on SWD lines
*
* Parameters:
* None.
*
* Return:
* parity:
* 1-bit parity data returned as a byte (either '1' or '0')
*
* Note:
* This function is called during SWD Read packet
*
******************************************************************************/
static unsigned char Swd_ReceiveParity(void)
{
unsigned char parity;
/* Make the clock low, Read SWDIO data, Make Clock high */
SetSwdckLow();
parity = ReadSwdio();
SetSwdckHigh();
return parity;
}
/******************************************************************************
* Function Name: Swd_SendDummyClocks
*******************************************************************************
*
* Summary:
* Sends three SWDCK clock cycles with SWDIO line held low
*
* Parameters:
* None.
*
* Return:
* None.
*
* Note:
* This function is called during SWD Read/Write packets.
*
******************************************************************************/
void Swd_SendDummyClocks(void)
{
unsigned char loop;
/* Send three SWDCK clock cycles with SWDIO line held low */
SetSwdioLow();
for (loop = 0; loop < NUMBER_OF_DUMMY_SWD_CLOCK_CYCLES; loop++) {
SetSwdckLow();
SetSwdckHigh();
}
}
/******************************************************************************
* Function Name: Swd_CountOneBits
*******************************************************************************
*
* Summary:
* Counts the number of 1's in a byte
*
* Parameters:
* dataByte:
* Byte for which the number of 1's need to be found
*
* Return:
* count:
* Number of 1's present in DataByte
*
* Note:
* This function is used for computing parity of data
*
******************************************************************************/
static unsigned char Swd_CountOneBits(unsigned char dataByte)
{
unsigned char count = 0;
unsigned char i;
/* Loop for 8-bits of a byte */
/* Increment count variable if LS bit is set */
for (i = 0; i < 8; i++) {
if (dataByte & LSB_BIT_MASK)
count++;
dataByte = dataByte >> 1;
}
return count;
}
/******************************************************************************
* Function Name: Swd_ComputeDataParity
*******************************************************************************
*
* Summary:
* Computes Even parity of 4-byte data
*
* Parameters:
* swd_PacketData[DATA_BYTES_PER_PACKET] - Global variable that holds the data
*
* Return:
* Even parity bit
* 0x01 - Parity is '1' if 4-byte data has an odd number of 1's
* 0x00 - Parity is '0' if 4-byte data has an even number of 1's
*
* Note:
* This function is called during SWD Read/Write packets
*
******************************************************************************/
static unsigned char Swd_ComputeDataParity(void)
{
unsigned char count = 0;
unsigned char i;
/* Count number of 1's in 4-byte data */
for (i = 0; i < DATA_BYTES_PER_PACKET; i++)
count = count + Swd_CountOneBits(swd_PacketData[i]);
/* Return even parity. If Lsb bit is 1, it implies the number of 1's
is odd, and hence the even parity bit is set. For even number
of 1's, parity bit is 0 */
return count & LSB_BIT_MASK;
}
/******************************************************************************
* Function Name: Swd_ReadPacket
*******************************************************************************
*
* Summary:
* Sends a single SWD Read packet
*
* Parameters:
* swd_PacketHeader - Global variable that holds the 8-bit header data for packet
*
* Return:
* swd_PacketData[DATA_BYTES_PER_PACKET] - Global variable that holds the 4-byte
* data that has been read
*
* swd_PacketAck - Global variable that holds the status of the SWD transaction
* ACK response is stored as a byte. Three possible ACK return values are:
* 0x01 - SWD_OK_ACK
* 0x02 - SWD_WAIT_ACK
* 0x04 - SWD_FAULT_ACK
* 0x09 - SWD_OK_ACK, but Parity error in data received
* Any other ACK value - Undefined ACK code.
* Treat it similar to SWD_FAULT_ACK and abort
* operation.
*
* Note:
* 1.)Swd_RawReadPacket() is called during SPC Polling operations when the host
* must read the SPC status register continuously till a Programming
* operation is completed or data is ready to be read.
*
* 2.)This function is called duing continuous multi byte read operations from
* the SPC_DATA register
*
* 3.)This function is called during IDCODE instruction for reading the Device
* JTAG ID
*
* 4.)This function is not called during normal SWD read transactions. To read
* a register data, two SWD Read packets must be sent (call this function
* twice). This method of reading twice has been implemented in
* SWD_ReadPacket() function which will be called during normal read
* transactions.
*
******************************************************************************/
void Swd_ReadPacket(void)
{
unsigned char parity;
unsigned char loop = 0;
unsigned char i;
do {
/* 8-bit Header data */
Swd_SendByte(swd_PacketHeader);
/* First Turnaround phase */
Swd_FirstTurnAroundPhase();
/* Get the 3-bit ACK data */
swd_PacketAck = Swd_GetAckSegment();
/* Read 4-byte data and store in Global
array swd_PacketData[] */
for (i = 0; i < DATA_BYTES_PER_PACKET; i++)
swd_PacketData[i] = Swd_ReceiveByte();
/* Parity phase */
parity = Swd_ReceiveParity();
/* Second Turnaround phase */
Swd_SecondTurnAroundPhase();
/* Dummy clock phase since clock is not free running */
Swd_SendDummyClocks();
/* Repeat for a WAIT ACK till timeout loop expires */
loop++;
} while ((swd_PacketAck == SWD_WAIT_ACK)
&& (loop < NUMBER_OF_WAIT_ACK_LOOPS));
/* For a OK ACK, check the parity bit received with parity computed */
if (swd_PacketAck == SWD_OK_ACK) {
if (parity != Swd_ComputeDataParity()) {
/* Set the Parity error bit in ACK code */
swd_PacketAck = swd_PacketAck | SWD_PARITY_ERROR;
}
}
/* Swd_PacketAck global variable holds the status of
the SWD transaction */
}
/******************************************************************************
* Function Name: Swd_WritePacket
*******************************************************************************
*
* Summary:
* Sends a single SWD Write packet
*
* Parameters:
* swd_PacketHeader - Global variable that holds the 8-bit header data
* for packet
* swd_PacketData[DATA_BYTES_PER_PACKET] - Global variable that holds the data
* to be sent
*
* Return:
* swd_PacketAck - Global variable that holds the status of the SWD transaction
* ACK response is stored as a byte. Three possible ACK return values are:
* 0x01 - SWD_OK_ACK
* 0x02 - SWD_WAIT_ACK
* 0x04 - SWD_FAULT_ACK
* Any other ACK value - Undefined ACK code.
* Treat it similar to SWD_FAULT_ACK and abort operation.
*
* Note:
* This function is called for Address Write, Data Write operations
*
******************************************************************************/
void Swd_WritePacket(void)
{
unsigned char parity;
unsigned char loop = 0;
unsigned char i;
/* Compute Even parity for 4-byte data */
parity = Swd_ComputeDataParity();
do {
/* 8-bit Header data */
Swd_SendByte(swd_PacketHeader);
/* First Turnaround phase */
Swd_FirstTurnAroundPhase();
/* Get the 3-bit ACK data */
swd_PacketAck = Swd_GetAckSegment();
/* Second Turnaround phase */
Swd_SecondTurnAroundPhase();
/* Send 4-byte data stored in Global array swd_PacketData[] */
for (i = 0; i < DATA_BYTES_PER_PACKET; i++)
Swd_SendByte(swd_PacketData[i]);
/* Parity phase */
Swd_SendParity(parity);
/* Dummy clock phase since clock is not free running */
Swd_SendDummyClocks();
loop++;
/* Repeat for a WAIT ACK till timeout loop expires */
} while ((swd_PacketAck == SWD_WAIT_ACK)
&& (loop < NUMBER_OF_WAIT_ACK_LOOPS));
/* swd_PacketAck global variable holds the status of
the SWD transaction */
}
/******************************************************************************
* Function Name: Swd_LineReset
*******************************************************************************
*
* Summary:
* Resets the SWD line by sending 51 SWDCK clock cycles with SWDIO line high
*
* Parameters:
* None
*
* Return:
* None
*
* Note:
* This function is called as part of SWD switching sequence
*
******************************************************************************/
void Swd_LineReset(void)
{
unsigned char i;
/* To reset SWD line, clock more than 50 SWDCK clock cycles with SWDIO
high. */
SWDIO_OUTPUT_HIGH;
for (i = 0; i < NUMBER_OF_SWD_RESET_CLOCK_CYCLES; i++) {
SWDCK_OUTPUT_LOW;
SWDCK_OUTPUT_HIGH;
}
SWDCK_OUTPUT_LOW;
SWDIO_OUTPUT_LOW;
SWDCK_OUTPUT_HIGH;
}
/* []END OF FILE */

View file

@ -0,0 +1,100 @@
/******************************************************************************
* File Name: SWD_PacketLayer.h
* Version 1.0
*
* Description:
* This header file contains the constant definitions, function declarations
* associated with the packet layer of the SWD protocol.
*
* Note:
*
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
#ifndef __SWD_PACKETLAYER_H
#define __SWD_PACKETLAYER_H
/******************************************************************************
* Constant definitions
******************************************************************************/
/* Data size of a SWD Packet in bytes */
#define DATA_BYTES_PER_PACKET 4
/* Number of dummy SWDCK clocks at end of each SWD packet.
Required for bit banging programmers where clock is not free running */
#define NUMBER_OF_DUMMY_SWD_CLOCK_CYCLES 3
/* Minimum number of SWDCK clock cycles to reset the SWD line state */
#define NUMBER_OF_SWD_RESET_CLOCK_CYCLES 51
/* ACK response in a SWD packet is a 3-bit value */
#define NUMBER_OF_ACK_BITS 3
/* SWD ACK response meanings.
* Parity error definition is not part of SWD ACK response from target PSoC 4.
* The actual ACK response is only 3-bit length. The parity error bit is
* defined as fourth bit by host application. It is generated by host if there
* is a parity error in the SWD Read packet data from target PSoC 4 */
#define SWD_OK_ACK 0x01
#define SWD_WAIT_ACK 0x02
#define SWD_FAULT_ACK 0x04
#define SWD_PARITY_ERROR 0x08
/* Maximum SWD packet loop timeout for SWD_WAIT_ACK response */
#define NUMBER_OF_WAIT_ACK_LOOPS 5
/* Mask value to define Most significant bit (MSb) in a Byte */
#define MSB_BIT_MASK 0x80
/* Mask value to define Least significant bit (LSb) in a Byte */
#define LSB_BIT_MASK 0x01
/******************************************************************************
* Global Variable declaration
******************************************************************************/
/* The below global variables are accessed by the upper layer files to create
SWD packet header, ACK, data */
extern unsigned char swd_PacketHeader;
extern unsigned char swd_PacketAck;
extern unsigned char swd_PacketData[DATA_BYTES_PER_PACKET];
/******************************************************************************
* Function Prototypes
******************************************************************************/
/* The below public fuctions are called by the upper layer files to send SWD
packets */
void Swd_WritePacket(void);
void Swd_ReadPacket(void);
void Swd_LineReset(void);
void Swd_SendDummyClocks(void);
#endif /* __SWD_PACKETLAYER_H */
/* [] END OF FILE */

View file

@ -0,0 +1,180 @@
/******************************************************************************
* File Name: SWD_PhysicalLayer.h
* Version 1.0
*
* Description:
* This header file contains the macro definitions, function declarations for
* the physical layer of the SWD protocol. These include -
* a.) Setting a output pin high or low
* b.) Reading the logic level of an input pin
* c.) Configuring the drive mode of the programming pin
*
* The pin manipulation routines are defined both as macros and functions.
* The macros are used in "Step 1. DeviceAcquire()" as the function has strict
* timing requirements for execution. Using the macros instead of fuctions
* reduces execution overhead.
*
* The pin manipulation functions are used instead of macros in all other
* places to save code space.
*
* Note:
* The macros, functions defined here are specific to PSoC 5LP Host Programmer.
* Modify them as applicable for your Host Programmer.
*
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
#ifndef __SWD_PHYSICALLAYER_H
#define __SWD_PHYSICALLAYER_H
/* Host programmer registers, mask values are defined in "RegisterDefines.h" */
#include <linux/io.h>
#include <linux/gpio.h>
#include <linux/kernel.h>
#include "cycapsense_hssp.h"
extern struct cycapsense_ctrl_data *ctrl_data;
#define HSSP_CLK (ctrl_data->hssp_d.c_gpio)
#define HSSP_DAT (ctrl_data->hssp_d.d_gpio)
#define HSSP_RST (ctrl_data->hssp_d.rst_gpio)
#define HSSP_CLK_OFF (ctrl_data->hssp_d.c_offset)
#define HSSP_DAT_OFF (ctrl_data->hssp_d.d_offset)
#define HSSP_CLK_GROUP_OFF (ctrl_data->hssp_d.c_group_offset)
#define HSSP_DAT_GROUP_OFF (ctrl_data->hssp_d.d_group_offset)
#define MSM_TLMM_BASE (ctrl_data->hssp_d.gpio_base)
#define GPIO_IN_OUT(n) (MSM_TLMM_BASE + (0x1000 * n))
static inline void hssp_set_clk_gpio(int gpio, int offset, int value)
{
if (ctrl_data->hssp_d.raw_mode) {
writel_relaxed_no_log(value ? 2 : 0, (GPIO_IN_OUT(offset) + HSSP_CLK_GROUP_OFF));
} else
gpio_set_value(gpio, value);
}
static inline void hssp_set_dat_gpio(int gpio, int offset, int value)
{
if (ctrl_data->hssp_d.raw_mode) {
writel_relaxed_no_log(value ? 2 : 0, (GPIO_IN_OUT(offset) + HSSP_DAT_GROUP_OFF));
} else
gpio_set_value(gpio, value);
}
static inline int hssp_get_gpio(int gpio, int offset)
{
if (ctrl_data->hssp_d.raw_mode)
return !!(readl_relaxed_no_log((GPIO_IN_OUT(offset) + HSSP_DAT_GROUP_OFF)) & 0x1);
else
return gpio_get_value(gpio);
}
/***************************** USER ATTENTION REQUIRED ************************
***************************** HOST PROCESSOR SPECIFIC *************************
**************** Macros for Host Pin Drive mode configuration *****************
*
* Uses the register definitions, mask values in "RegisterDefines.h" to
* configure the pin drive mode
*
* SWDIO pin on host side - CMOS output (host writes data to target PSoC 4),
* High Z digital input (host reads data from target
* PSoC 4 or when host is not programming target
* PSoC 4 (idle))
*
* SWDCK pin on host side - CMOS output (when host is programming target PSoC 4),
* High Z digital input (when host is not programming
* target PSoC 4 (idle))
*
* XRES pin on host side - CMOS output (when host is programming target PSoC 4)
* High Z digital input (when host is not programming
* target PSoC 4 (idle))
*
* Modify these as applicable to your Host Programmer
******************************************************************************/
#define SWDIO_DRIVEMODE_HIGHZIN SetSwdioHizInput()
#define SWDIO_DRIVEMODE_CMOSOUT SetSwdioCmosOutput()
#define SWDCK_DRIVEMODE_HIGHZIN SetSwdckHizInput()
#define SWDCK_DRIVEMODE_CMOSOUT SetSwdckCmosOutput()
#define XRES_DRIVEMODE_CMOSOUT SetXresCmosOutput()
#define XRES_DRIVEMODE_HIGHZIN SetXresHizInput()
/***************************** USER ATTENTION REQUIRED ************************
***************************** HOST PROCESSOR SPECIFIC *************************
**************** Macros for driving output pins on host side ******************
*
* Uses the register definitions, mask values in "RegisterDefines.h" to drive
* output pins either to logic high (suffixed by 'HIGH') or
* logic low (suffixed by 'LOW')
*
* Modify these as applicable to your Host Programmer
******************************************************************************/
#define SWDIO_OUTPUT_HIGH SetSwdioHigh()
#define SWDIO_OUTPUT_LOW SetSwdioLow()
#define SWDCK_OUTPUT_HIGH SetSwdckHigh()
#define SWDCK_OUTPUT_LOW SetSwdckLow()
#define XRES_OUTPUT_HIGH SetXresHigh()
#define XRES_OUTPUT_LOW SetXresLow()
/******************************************************************************
* Function Prototypes
******************************************************************************/
/* The below fuctions are for pin manipulation, and their definitions in
* SWD_PhysicalLayer.c are the same as the corresponding macro defitnions
* above. */
#define SetSwdckHigh() hssp_set_clk_gpio(HSSP_CLK, HSSP_CLK_OFF, 1)
#define SetSwdckLow() hssp_set_clk_gpio(HSSP_CLK, HSSP_CLK_OFF, 0)
#define SetSwdckCmosOutput() gpio_direction_output(HSSP_CLK, 0)
#define SetSwdckHizInput() gpio_direction_input(HSSP_CLK)
#define SetSwdioHigh() hssp_set_dat_gpio(HSSP_DAT, HSSP_DAT_OFF, 1)
#define SetSwdioLow() hssp_set_dat_gpio(HSSP_DAT, HSSP_DAT_OFF, 0)
#define SetSwdioCmosOutput() gpio_direction_output(HSSP_DAT, 0)
#define ReadSwdio() hssp_get_gpio(HSSP_DAT, HSSP_DAT_OFF)
#define SetSwdioHizInput() gpio_direction_input(HSSP_DAT)
#define SetXresHigh() gpio_set_value(HSSP_RST, 1)
#define SetXresLow() gpio_set_value(HSSP_RST, 0)
#define SetXresCmosOutput() gpio_direction_output(HSSP_RST, 0)
#define SetXresHizInput() gpio_direction_input(HSSP_RST)
#endif /* __SWD_PHYSICALLAYER_H */
/*[] END OF FILE */

View file

@ -0,0 +1,182 @@
/******************************************************************************
* File Name: Swd_UpperPacketLayer.c
* Version 1.0
*
* Description:
* This file provides the source code for function associated with the upper
* packet layer of the SWD protocol.
*
* Owner:
* Tushar Rastogi, Application Engineer (tusr@cypress.com)
*
* Related Document:
* AN84858 - PSoC 4 Programming using an External Microcontroller (HSSP)
*
* Hardware Dependency:
* PSoC 5LP Development Kit - CY8CKIT-050
*
* Code Tested With:
* PSoC Creator 2.2
* ARM GCC 4.4.1
* CY8CKIT-050
*
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
/******************************************************************************
* Header file Inclusion
******************************************************************************/
#include "SWD_PacketLayer.h"
#include "SWD_UpperPacketLayer.h"
/******************************************************************************
* Function Definitions
******************************************************************************/
/******************************************************************************
* Function Name: Read_DAP
*******************************************************************************
*
* Summary:
* Reads the Swd_DAP_Register and stores the returned 32 bit value
*
* Parameters:
* swd_DAP_Register - MACROS for reading Debug Port and Access Port Register
* data_32 - 32-bit variable containing the returned value
*
* Return:
* None
*
******************************************************************************/
void Read_DAP(unsigned char swd_DAP_Register, unsigned long *data_32)
{
swd_PacketHeader = swd_DAP_Register;
Swd_ReadPacket();
if (swd_PacketAck != SWD_OK_ACK)
return;
*data_32 =
(((unsigned long)swd_PacketData[3] << 24) |
((unsigned long)swd_PacketData[2] << 16) | ((unsigned long)
swd_PacketData[1] << 8)
| ((unsigned long)swd_PacketData[0]));
}
/******************************************************************************
* Function Name: Write_DAP
*******************************************************************************
*
* Summary:
* Writes a 32-bit value to swd_DAP_Register
*
* Parameters:
* swd_DAP_Register - MACROS for writing to Debug Port and Access Port Register
* data_32 - 32-bit variable containing the value to be written
*
* Return:
* None
*
******************************************************************************/
void Write_DAP(unsigned char swd_DAP_Register, unsigned long data_32)
{
swd_PacketHeader = swd_DAP_Register;
swd_PacketData[3] = (unsigned char)(data_32 >> 24);
swd_PacketData[2] = (unsigned char)(data_32 >> 16);
swd_PacketData[1] = (unsigned char)(data_32 >> 8);
swd_PacketData[0] = (unsigned char)(data_32);
Swd_WritePacket();
}
/******************************************************************************
* Function Name: Read_IO
*******************************************************************************
*
* Summary:
* Reads 32-bit date from specified address of CPU address space.
* Returns OK ACK if all SWD transactions succeeds (ACKed).
*
* Parameters:
* addr_32 - Address from which the data has to be read from CPU address space
* data_32 - 32-bit variable containing the read value
*
* Return:
* Swd_PacketAck - Acknowledge packet for the last SWD transaction
*
*******************************************************************************/
unsigned char Read_IO(unsigned long addr_32, unsigned long *data_32)
{
Write_DAP(DPACC_AP_TAR_WRITE, addr_32);
if (swd_PacketAck != SWD_OK_ACK)
return swd_PacketAck;
Read_DAP(DPACC_AP_DRW_READ, data_32);
if (swd_PacketAck != SWD_OK_ACK)
return swd_PacketAck;
Read_DAP(DPACC_AP_DRW_READ, data_32);
if (swd_PacketAck != SWD_OK_ACK)
return swd_PacketAck;
return swd_PacketAck;
}
/******************************************************************************
* Function Name: Write_IO
*******************************************************************************
*
* Summary:
* Writes 32-bit data into specified address of CPU address space.
* Returns “true” if all SWD transactions succeeded (ACKed).
*
* Parameters:
* addr_32 - Address at which the data has to be written in CPU address space
* data_32 - 32-bit variable containing the value to be written
*
* Return:
* swd_PacketAck - Acknowledge packet for the last SWD transaction
*
******************************************************************************/
unsigned char Write_IO(unsigned long addr_32, unsigned long data_32)
{
Write_DAP(DPACC_AP_TAR_WRITE, addr_32);
if (swd_PacketAck != SWD_OK_ACK)
return swd_PacketAck;
Write_DAP(DPACC_AP_DRW_WRITE, data_32);
if (swd_PacketAck != SWD_OK_ACK)
return swd_PacketAck;
return swd_PacketAck;
}
/* [] END OF FILE */

View file

@ -0,0 +1,72 @@
/******************************************************************************
* File Name: SWD_UpperPacketLayer.h
* Version 1.0
*
* Description:
* This header file contains the constant definitions, function declarations
* associated with the upper packet layer of the SWD protocol.
*
* Note:
*
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
#ifndef __SWD_UPPERPACKETLAYER_H
#define __SWD_UPPERPACKETLAYER_H
/******************************************************************************
* Constant definitions
******************************************************************************/
/* Macro Definitions for Debug and Access Port registers read and write Commands
used in the functions defined in UpperPacketLayer.c */
#define DPACC_DP_CTRLSTAT_READ 0x8D
#define DPACC_DP_IDCODE_READ 0xA5
#define DPACC_AP_CSW_READ 0x87
#define DPACC_AP_TAR_READ 0xAF
#define DPACC_AP_DRW_READ 0x9F
#define DPACC_DP_ABORT_WRITE 0x81
#define DPACC_DP_CTRLSTAT_WRITE 0xA9
#define DPACC_DP_SELECT_WRITE 0xB1
#define DPACC_AP_CSW_WRITE 0xA3
#define DPACC_AP_TAR_WRITE 0x8B
#define DPACC_AP_DRW_WRITE 0xBB
/******************************************************************************
* Function Prototypes
******************************************************************************/
void Read_DAP(unsigned char swd_DAP_Register, unsigned long *data_32);
void Write_DAP(unsigned char swd_DAP_Register, unsigned long data_32);
unsigned char Read_IO(unsigned long addr_32, unsigned long *data_32);
unsigned char Write_IO(unsigned long addr_32, unsigned long data_32);
#endif /* __SWD_UPPERPACKETLAYER_H */
/* [] END OF FILE */

View file

@ -0,0 +1,81 @@
/******************************************************************************
* File Name: Timeout.h
* Version 1.0
*
* Description:
* This header file contains the definitions for timeout parameters, function
* declaration for the delay routine. These definitions will vary based on host
* processor used to program target PSoC 5LP. Change the timeout values based on
* your Host processor.
*
* Note:
* Refer to the TimeoutCalc.h header file in the other project
* "C_Hssp_TimeoutCalc" for details on the procedure to calculate these
* parameters for your specific host programmer.
*
*******************************************************************************
* Copyright (2013), Cypress Semiconductor Corporation.
*******************************************************************************
* This software is owned by Cypress Semiconductor Corporation (Cypress) and is
* protected by and subject to worldwide patent protection (United States and
* foreign), United States copyright laws and international treaty provisions.
* Cypress hereby grants to licensee a personal, non-exclusive, non-transferable
* license to copy, use, modify, create derivative works of, and compile the
* Cypress Source Code and derivative works for the sole purpose of creating
* custom software in support of licensee product to be used only in conjunction
* with a Cypress integrated circuit as specified in the applicable agreement.
* Any reproduction, modification, translation, compilation, or representation of
* this software except as specified above is prohibited without the express
* written permission of Cypress.
*
* Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH
* REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Cypress reserves the right to make changes without further notice to the
* materials described herein. Cypress does not assume any liability arising out
* of the application or use of any product or circuit described herein. Cypress
* does not authorize its products for use as critical components in life-support
* systems where a malfunction or failure may reasonably be expected to result in
* significant injury to the user. The inclusion of Cypress' product in a life-
* support systems application implies that the manufacturer assumes all risk of
* such use and in doing so indemnifies Cypress against all charges. Use may be
* limited by and subject to the applicable Cypress software license agreement.
******************************************************************************/
#ifndef __TIMEOUT_H
#define __TIMEOUT_H
/******************************************************************************
* Macro definitions
******************************************************************************/
#include <linux/delay.h>
/***************************** USER ATTENTION REQUIRED ************************
***************************** HOST PROCESSOR SPECIFIC *************************
* All below three timeout values namely: DEVICE_ACQUIRE_TIMEOUT,
* XRES_PULSE_100US, and SROM_POLLING_TIMEOUT are for a PSoC 5LP Host programmer
* running at 63 MHz. Modify these values as required for your host processor.
* Refer to the TimeoutCalc.h header file in the other project
* "C_Hssp_TimeoutCalc" for details on the procedure to calculate these
* parameters for your specific host programmer.
******************************************************************************/
#define XRES_PULSE_100US 600
#if defined CY8C40xx_FAMILY
#define DEVICE_ACQUIRE_TIMEOUT 40 /* 40 retries, about 2 ms */
#else
#define DEVICE_ACQUIRE_TIMEOUT 15
#endif
#define SROM_POLLING_TIMEOUT 210416
/******************************************************************************
* Function Prototypes
******************************************************************************/
static inline void DelayHundredUs(void)
{
udelay(100);
}
#endif /* __TIMEOUT_H */
/* [] END OF FILE */

View file

@ -0,0 +1,80 @@
/*
* Header file for:
* Cypress CapSense(TM) firmware downloader.
*
* Copyright (c) 2015 Motorola Mobility LLC
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
*/
#ifndef __CYCAPSENSE_HSSP_H__
#define __CYCAPSENSE_HSSP_H__
#include <linux/string.h>
#include <linux/limits.h>
#include <linux/workqueue.h>
struct hex_info {
char fw_name[NAME_MAX];
u8 *data;
u8 *s_data;
u8 *m_data;
u8 cl_protection;
u16 cs;
};
struct hssp_data {
struct hex_info inf;
const char *name;
unsigned int silicon_id;
int block_size;
int num_of_blocks;
int secure_bytes;
int c_gpio;
int d_gpio;
int rst_gpio;
int raw_mode;
int c_offset;
int d_offset;
u32 c_group_offset;
u32 d_group_offset;
void __iomem *gpio_base;
u16 chip_cs;
u16 sw_rev;
};
struct cycapsense_ctrl_data {
struct device *dev;
struct hssp_data hssp_d;
struct work_struct work;
int cmd;
};
#define HSSP_CMD_NONE 0
#define HSSP_CMD_RESET 1
#define HSSP_CMD_ERASE 2
#define HSSP_CMD_FW_UPDATE 3
int cycapsense_hssp_dnld(struct hssp_data *d);
#define P4000_METADATA_SIZE 12
#define SILICON_ID_BYTE_LENGTH 4
#define FLASH_ROW_BYTE_SIZE_HEX_FILE 128
#define NUMBER_OF_FLASH_ROWS_HEX_FILE 128
#define SW_REVISION_OFFSET 0x3f7c
#define FAILURE 1
#define SUCCESS 0
#define RST_GPIO 1
#define CLK_GPIO 4
#define DAT_GPIO 7
#endif /* __CYCAPSENSE_HSSP_H__ */

View file

@ -0,0 +1,125 @@
/*
* Copyright (C) 2013 XiaoMi, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
*/
#ifndef _CYTTSP_SAR_H_
#define _CYTTSP_SAR_H_
#include <linux/types.h>
#define CYTTSP_SAR_CHANNEL_ENABLE 0x06
#define CYTTSP_SAR_FORCE_CALIBRATE 0x07
#define CYTTSP_SAR_CHANNEL_MAX 0x08
#define CYTTSP_SAR_STATE_ERROR 0x03
#define CYTTSP_CMD_VERIFY_CHKSUM 0x31
#define CYTTSP_CMD_GET_FLASH_SIZE 0x32
#define CYTTSP_CMD_ERASE_ROW 0x34
#define CYTTSP_CMD_SEND_DATA 0x37
#define CYTTSP_CMD_ENTER_BTLD 0x38
#define CYTTSP_CMD_PROGRAM_ROW 0x39
#define CYTTSP_CMD_VERIFY_ROW 0x3A
#define CYTTSP_CMD_EXIT_BTLD 0x3B
#define CYTTSP_REG_TOUCHMODE 0x00
#define CYTTSP_REG_HWVERSION 0x59
#define CYTTSP_REG_INTERRUPT_PEDNING 0x50
#define CYTTSP_REG_STATUS_LSB 0x51
#define CYTTSP_REG_STATUS_MSB 0x52
#define CYTTSP_REG_INVALID 0xFF
#define CYTTSP_NORMAL_MODE 0x00
#define CYTTSP_STANDBY_MODE 0x01
#define CYTTSP_STS_SUCCESS 0x00
#define CYTTSP_SAR_OP_MODE 0x00
#define CYTTSP_SAR_FW_VER1 0x57
#define CYTTSP_SAR_FW_VER2 0x58
#define CYTTSP_PACKET_START 0x01
#define CYTTSP_PACKET_END 0x17
#define CYTTSP_MAX_PAYLOAD_LEN 0x15
#define CYTTSP_RESP_HEADER_LEN 0x4
#define CYTTSP_RESP_TAIL_LEN 0x3
#define CYTTSP_ENTER_BTLD_RESP_LEN 8
#define CYTTSP_GET_FLASHSZ_RESP_LEN 4
#define CYTTSP_FW_VERSION_FILE_OFFSET 183
/**************************************
* define platform data
*
**************************************/
struct cyttsp_reg_data {
unsigned char reg;
unsigned char val;
};
static struct cyttsp_reg_data cyttsp_i2c_reg_setup[] = {
{
.reg = CYTTSP_NORMAL_MODE,
.val = 0x00,
},
{
.reg = CYTTSP_SAR_CHANNEL_ENABLE,
.val = 0x0f,
},
{
.reg = CYTTSP_SAR_FORCE_CALIBRATE,
.val = 0x3e,
},
};
typedef struct cyttsp_sar_data *pcyttsp_data_t;
struct cyttsp_sar_data {
struct i2c_client *client;
struct cyttsp_sar_platform_data *pdata;
struct regulator *regulator_vdd;
struct regulator *regulator_avdd;
struct regulator *regulator_vddio;
struct input_dev *input_dev[4];
bool dbgdump;
unsigned long sensorStatus;
bool enable;
u8 bootloader_addr;
u8 app_addr;
};
struct cyttsp_sar_platform_data {
int irq_gpio;
u32 irq_gpio_flags;
unsigned long irqflags;
const char *input_name;
int i2c_reg_num;
struct cyttsp_reg_data *pi2c_reg;
int nsars;
int *key_code;
u8 sar_status_reg;
u8 bootloader_addr;
u8 standby_reg;
int default_config;
int config_array_size;
struct cyttsp_config_info *config_array;
bool cut_off_power;
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,26 @@
/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* 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.
*/
#include <linux/notifier.h>
void register_hssp_update_notify(struct notifier_block *nb);
void unregister_hssp_update_notify(struct notifier_block *nb);
int cycapsense_fw_update(void);
int cycapsense_reset(void);
/*
static inline void register_hssp_update_notify(struct notifier_block *nb) { }
static inline void unregister_hssp_update_notify(struct notifier_block *nb) { }
static inline int cycapsense_fw_update(void) { return 0; }
static inline int cycapsense_reset(void) { return 0; }
*/
#define HSSP_START 0
#define HSSP_STOP 1