spi is shared between the rtc and tsc2100
adds the very begining of the rtc driver (only reads the time currently git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14935 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
ea47ee64f0
commit
03f45d3aff
8 changed files with 95 additions and 19 deletions
|
@ -146,6 +146,8 @@ drivers/rtc/rtc_ds1339_ds3231.c
|
|||
drivers/rtc/rtc_s3c2440.c
|
||||
#elif (CONFIG_RTC == RTC_AS3514)
|
||||
drivers/rtc/rtc_as3514.c
|
||||
#elif (CONFIG_RTC == RTC_RX5X348AB)
|
||||
drivers/rtc/rtc_rx5x348ab.c
|
||||
#endif /* (CONFIG_RTC == RTC_) */
|
||||
#endif /* SIMULATOR */
|
||||
|
||||
|
|
35
firmware/drivers/rtc/rtc_rx5x348ab.c
Normal file
35
firmware/drivers/rtc/rtc_rx5x348ab.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id: rtc_as3514.c 12131 2007-01-27 20:48:48Z dan_a $
|
||||
*
|
||||
* Copyright (C) 2007 by Jonathan Gordon
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
#include "spi.h"
|
||||
#include "rtc.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
void rtc_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
int rtc_read_datetime(unsigned char* buf)
|
||||
{
|
||||
char command = 0x04; /* burst read from the start of the time/date reg */
|
||||
spi_block_transfer(SPI_target_RX5X348AB,
|
||||
&command, 1, buf, 7);
|
||||
return 1;
|
||||
}
|
|
@ -30,7 +30,8 @@ void tsc2100_read_values(short *x, short* y, short *z1, short *z2)
|
|||
unsigned short command = 0x8000|(page << 11)|(address << 5);
|
||||
unsigned char out[] = {command >> 8, command & 0xff};
|
||||
unsigned char in[8];
|
||||
spi_block_transfer(out, sizeof(out), in, sizeof(in));
|
||||
spi_block_transfer(SPI_target_TSC2100,
|
||||
out, sizeof(out), in, sizeof(in));
|
||||
|
||||
*x = (in[0]<<8)|in[1];
|
||||
*y = (in[2]<<8)|in[3];
|
||||
|
@ -43,7 +44,8 @@ short tsc2100_readreg(int page, int address)
|
|||
unsigned short command = 0x8000|(page << 11)|(address << 5);
|
||||
unsigned char out[] = {command >> 8, command & 0xff};
|
||||
unsigned char in[2];
|
||||
spi_block_transfer(out, sizeof(out), in, sizeof(in));
|
||||
spi_block_transfer(SPI_target_TSC2100,
|
||||
out, sizeof(out), in, sizeof(in));
|
||||
return (in[0]<<8)|in[1];
|
||||
}
|
||||
|
||||
|
@ -53,7 +55,8 @@ void tsc2100_writereg(int page, int address, short value)
|
|||
unsigned short command = 0x8000|(page << 11)|(address << 5);
|
||||
unsigned char out[4] = {command >> 8, command & 0xff,
|
||||
value >> 8, value & 0xff};
|
||||
spi_block_transfer(out, sizeof(out), NULL, 0);
|
||||
spi_block_transfer(SPI_target_TSC2100,
|
||||
out, sizeof(out), NULL, 0);
|
||||
}
|
||||
|
||||
void tsc2100_keyclick(void)
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
#define CONFIG_CODEC SWCODEC
|
||||
|
||||
/* define this if you have a real-time clock */
|
||||
//#define CONFIG_RTC RTC_S3C2440
|
||||
#define CONFIG_RTC RTC_RX5X348AB
|
||||
|
||||
/* Define this for LCD backlight available */
|
||||
#define HAVE_BACKLIGHT
|
||||
|
|
|
@ -140,6 +140,7 @@
|
|||
#define RTC_AS3514 6 /* Sandisk Sansa e200 series */
|
||||
#define RTC_DS1339_DS3231 7 /* h1x0 RTC mod */
|
||||
#define RTC_IMX31L 8
|
||||
#define RTC_RX5X348AB 9
|
||||
|
||||
/* USB On-the-go */
|
||||
#define USBOTG_ISP1362 1362 /* iriver H300 */
|
||||
|
|
|
@ -18,9 +18,6 @@
|
|||
****************************************************************************/
|
||||
#ifndef __SPI_H__
|
||||
#define __SPI_H__
|
||||
|
||||
int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size,
|
||||
uint8_t *rx_bytes, unsigned int rx_size);
|
||||
void spi_init(void);
|
||||
#include "spi-target.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,18 +24,43 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "kernel.h"
|
||||
#include "system.h"
|
||||
#include "spi.h"
|
||||
|
||||
#define GIO_TS_ENABLE (1<<2)
|
||||
#define clr_gio_enable() IO_GIO_BITSET1=GIO_TS_ENABLE
|
||||
#define set_gio_enable() IO_GIO_BITCLR1=GIO_TS_ENABLE
|
||||
#define GIO_TS_ENABLE (1<<2)
|
||||
#define GIO_RTC_ENABLE (1<<12)
|
||||
|
||||
int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size,
|
||||
struct mutex spi_lock;
|
||||
|
||||
struct SPI_info {
|
||||
volatile unsigned short *setreg;
|
||||
volatile unsigned short *clrreg;
|
||||
int bit;
|
||||
};
|
||||
#define reg(a) (PHY_IO_BASE+a)
|
||||
struct SPI_info spi_targets[] =
|
||||
{
|
||||
[SPI_target_TSC2100] = { reg(0x0594), reg(0x058E), GIO_TS_ENABLE },
|
||||
[SPI_target_RX5X348AB] = { reg(0x058C), reg(0x0592), GIO_RTC_ENABLE },
|
||||
};
|
||||
|
||||
static void spi_disable_all_targets(void)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<SPI_MAX_TARGETS;i++)
|
||||
{
|
||||
*spi_targets[i].clrreg = spi_targets[i].bit;
|
||||
}
|
||||
}
|
||||
|
||||
int spi_block_transfer(enum SPI_target target,
|
||||
const uint8_t *tx_bytes, unsigned int tx_size,
|
||||
uint8_t *rx_bytes, unsigned int rx_size)
|
||||
{
|
||||
spinlock_lock(&spi_lock);
|
||||
/* Activate the slave select pin */
|
||||
set_gio_enable();
|
||||
*spi_targets[target].setreg = spi_targets[target].bit;
|
||||
|
||||
while (tx_size--)
|
||||
{
|
||||
|
@ -58,13 +83,15 @@ int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size,
|
|||
*rx_bytes++ = data & 0xff;
|
||||
}
|
||||
|
||||
clr_gio_enable();
|
||||
|
||||
*spi_targets[target].clrreg = spi_targets[target].bit;
|
||||
|
||||
spinlock_unlock(&spi_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void spi_init(void)
|
||||
{
|
||||
spinlock_init(&spi_lock);
|
||||
/* Set SCLK idle level = 0 */
|
||||
IO_SERIAL0_MODE |= (1<<10);
|
||||
|
||||
|
@ -72,6 +99,9 @@ void spi_init(void)
|
|||
IO_SERIAL0_TX_ENABLE = 0x0001;
|
||||
|
||||
/* Set GIO 18 to output for touch screen slave enable */
|
||||
IO_GIO_DIR1&=~GIO_TS_ENABLE;
|
||||
clr_gio_enable();
|
||||
IO_GIO_DIR1 &= ~GIO_TS_ENABLE;
|
||||
/* Set GIO 12 to output for rtc slave enable */
|
||||
IO_GIO_DIR0 &= ~GIO_RTC_ENABLE;
|
||||
|
||||
spi_disable_all_targets(); /* make sure only one is ever enabled at a time */
|
||||
}
|
||||
|
|
|
@ -21,9 +21,17 @@
|
|||
#define SPI_TARGET_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
enum SPI_target {
|
||||
SPI_target_TSC2100 = 0,
|
||||
SPI_target_RX5X348AB,
|
||||
SPI_MAX_TARGETS,
|
||||
};
|
||||
|
||||
void spi_init(void);
|
||||
int spi_block_transfer(const uint8_t *tx_bytes, unsigned int tx_size,
|
||||
int spi_block_transfer(enum SPI_target target,
|
||||
const uint8_t *tx_bytes, unsigned int tx_size,
|
||||
uint8_t *rx_bytes, unsigned int rx_size);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue