From 0baa2807a6772c3f98b8ecc9f2b9491de96ed974 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 14 Nov 2013 11:17:00 -0600 Subject: [PATCH] SAMA5 ISI: Framework for ISI drivers. Not much there on initial check-in --- arch/arm/src/sama5/sam_isi.c | 177 +++++++++++++++++++++++++++++++++++ arch/arm/src/sama5/sam_isi.h | 92 ++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 arch/arm/src/sama5/sam_isi.c create mode 100644 arch/arm/src/sama5/sam_isi.h diff --git a/arch/arm/src/sama5/sam_isi.c b/arch/arm/src/sama5/sam_isi.c new file mode 100644 index 0000000000..979517fc7f --- /dev/null +++ b/arch/arm/src/sama5/sam_isi.c @@ -0,0 +1,177 @@ +/**************************************************************************** + * arch/arm/src/sama5/sam_isi.c + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE + * COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include "sam_pio.h" +#include "sam_pck.h" +#include "sam_isi.h" + +#ifdef CONFIG_SAMA5_ISI + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* The sensor master clock (ISI_MCK) is generated by the Advanced Power + * Management Controller (APMC) through a Programmable Clock output. + */ + +#ifndef CONFIG_ISI_MCKFREQ +# error "CONFIG_ISI_MCKFREQ must be defined" +#endif + +#if defined(CONFIG_ISI_PCK0) +# define ISI_PCKID PCK0 +#elif defined(CONFIG_ISI_PCK1) +# define ISI_PCKID PCK1 +#elif defined(CONFIG_ISI_PCK2) +# define ISI_PCKID PCK2 +#else +# error "No valid PCK selection" +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ +/* This structure defines the overall state of the ISI interface */ + +struct sam_isi_s +{ + uint32_t actual; /* Acutal ISI_MCK frequency */ +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* ISI interface state */ + +static struct sam_isi_s g_isi; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: sam_isi_initialize + * + * Description: + * Initialize the ISI driver. + * + * Input Parameters: + * None + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * Called very early in the initialization sequence. + * + ****************************************************************************/ + +int sam_isi_initialize(void) +{ + int ret; + + /* Configure PIO pins for the ISI (outputs) */ + /* Data pins */ + + (void)sam_configpio(PIO_ISI_D0); + (void)sam_configpio(PIO_ISI_D1); + (void)sam_configpio(PIO_ISI_D2); + (void)sam_configpio(PIO_ISI_D3); + (void)sam_configpio(PIO_ISI_D4); + (void)sam_configpio(PIO_ISI_D5); + (void)sam_configpio(PIO_ISI_D6); + (void)sam_configpio(PIO_ISI_D7); + (void)sam_configpio(PIO_ISI_D8); + (void)sam_configpio(PIO_ISI_D9); + (void)sam_configpio(PIO_ISI_D10); + (void)sam_configpio(PIO_ISI_D11); + + /* Horizontal and vertical sync pins (inputs) */ + + (void)sam_configpio(PIO_ISI_HSYNC); + (void)sam_configpio(PIO_ISI_VSYNC); + + /* Pixel clock input (ISI_PCK, not to be confused with the processor clock + * (PCK) or the programmable clock (PCK). + * + * NOTE: "Several parts of the ISI controller use the pixel clock provided + * by the image sensor (ISI_PCK). Thus the user must first program the + * image sensor to provide this clock (ISI_PCK) before programming the + * Image Sensor Controller." + */ + + (void)sam_configpio(PIO_ISI_PCK); + + /* Configure ISI_MCK programmable clock output. + * + * REVISIT: Might this not be needed before the image sensor is + * initialized? + */ + + g_isi.actual = sam_pck_configure(ISI_PCKID, CONFIG_ISI_MCKFREQ); + gvdbg("PCK%d frequency=%d actual=%d\n", + ISI_PCKID, CONFIG_ISI_MCKFREQ, g_isi.actual); + + /* Enable the MCK (output) */ + + sam_pck_enable(ISI_PCKID, true); + + /* Configure the pixel clock */ +#warning Missing logic + + /* Configure color */ +#warning Missing logic + +} + +#endif /* CONFIG_SAMA5_ISI && CONFIG_SAMA5_EMAC */ diff --git a/arch/arm/src/sama5/sam_isi.h b/arch/arm/src/sama5/sam_isi.h new file mode 100644 index 0000000000..24bbb01b9d --- /dev/null +++ b/arch/arm/src/sama5/sam_isi.h @@ -0,0 +1,92 @@ +/************************************************************************************ + * arch/arm/src/sama5/sam_isi.h + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE + * COPYRIGHT OWNER OR CONTRIBUTORS 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 __ARCH_ARM_SRC_SAMA5_SAM_ISI_H +#define __ARCH_ARM_SRC_SAMA5_SAM_ISI_H + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include "chip.h" +#include "chip/sam_isi.h" + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Function: sam_isi_initialize + * + * Description: + * Initialize the ISI driver. + * + * Input Parameters: + * None + * + * Returned Value: + * OK on success; Negated errno on failure. + * + * Assumptions: + * Called very early in the initialization sequence. + * + ****************************************************************************/ + +#ifdef CONFIG_SAMA5_ISI +int sam_isi_initialize(void); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM_SRC_SAMA5_SAM_ISI_H */