summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/audio/cs4398.c41
-rw-r--r--firmware/drivers/audio/sdl.c4
-rw-r--r--firmware/drivers/nand_id.c29
-rw-r--r--firmware/drivers/rtc/rtc_jz4760.c124
4 files changed, 189 insertions, 9 deletions
diff --git a/firmware/drivers/audio/cs4398.c b/firmware/drivers/audio/cs4398.c
new file mode 100644
index 0000000000..35aa99d08c
--- /dev/null
+++ b/firmware/drivers/audio/cs4398.c
@@ -0,0 +1,41 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 by Roman Stolyarov
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "system.h"
23#include "cs4398.h"
24#include "config.h"
25#include "audio.h"
26#include "audiohw.h"
27#include "i2c.h"
28
29void cs4398_write_reg(uint8_t reg, uint8_t val)
30{
31 unsigned char buf[2] = {reg, val};
32 i2c_write(CS4398_I2C_ADDR, (unsigned char *)&buf, 2);
33}
34
35uint8_t cs4398_read_reg(uint8_t reg)
36{
37 unsigned char buf[2] = {reg, 0xff};
38 i2c_write(CS4398_I2C_ADDR, (unsigned char *)&buf[0], 1);
39 i2c_read(CS4398_I2C_ADDR, (unsigned char *)&buf[1], 1);
40 return buf[1];
41}
diff --git a/firmware/drivers/audio/sdl.c b/firmware/drivers/audio/sdl.c
index ae66380d16..a8fd2ffa07 100644
--- a/firmware/drivers/audio/sdl.c
+++ b/firmware/drivers/audio/sdl.c
@@ -122,6 +122,10 @@ void audiohw_set_depth_3d(int value)
122void audiohw_set_lineout_volume(int vol_l, int vol_r) 122void audiohw_set_lineout_volume(int vol_l, int vol_r)
123 { (void)vol_l; (void)vol_r; } 123 { (void)vol_l; (void)vol_r; }
124#endif 124#endif
125#if defined(AUDIOHW_HAVE_FILTER_ROLL_OFF)
126void audiohw_set_filter_roll_off(int value)
127 { (void)value; }
128#endif
125 129
126void audiohw_close(void) {} 130void audiohw_close(void) {}
127 131
diff --git a/firmware/drivers/nand_id.c b/firmware/drivers/nand_id.c
index f2b9861c7c..56132ab090 100644
--- a/firmware/drivers/nand_id.c
+++ b/firmware/drivers/nand_id.c
@@ -34,27 +34,38 @@ static const struct nand_info samsung[] =
34/* 34/*
35 id1, id2 35 id1, id2
36 pages/block, blocks, page_size, spare_size, col_cycles, row_cycles, planes 36 pages/block, blocks, page_size, spare_size, col_cycles, row_cycles, planes
37*/ 37*/
38 {0xDC, 0x10, /* K9F4G08UOM */ 38 {0xDC, 0x10, /* K9F4G08UOM */
39 64, 4096, 2048, 64, 2, 3, 1 }, 39 64, 4096, 2048, 64, 2, 3, 1 },
40 40
41 {0xD3, 0x51, /* K9K8G08UOM */ 41 {0xD3, 0x51, /* K9K8G08UOM */
42 64, 8192, 2048, 64, 2, 3, 1 }, 42 64, 8192, 2048, 64, 2, 3, 1 },
43 43
44 {0xD5, 0x14, /* K9GAG08UOM */ 44 {0xD5, 0x14, /* K9GAG08UOM */
45 128, 4096, 4096, 128, 2, 3, 2 }, 45 128, 4096, 4096, 128, 2, 3, 2 },
46 46
47 {0xD5, 0x55, /* K9LAG08UOM, K9HBG08U1M, K9MCG08U5M */ 47 {0xD5, 0x55, /* K9LAG08UOM, K9HBG08U1M, K9MCG08U5M */
48 128, 8192, 2048, 64, 2, 3, 4 }, 48 128, 8192, 2048, 64, 2, 3, 4 },
49 49
50 {0xD7, 0x55, /* K9LBG08UOM */ 50 {0xD7, 0x55, /* K9LBG08UOM */
51 128, 8192, 4096, 128, 2, 3, 4 }, 51 128, 8192, 4096, 128, 2, 3, 4 },
52}; 52};
53 53
54static const struct nand_info gigadevice[] =
55{
56/*
57 id1, id2
58 pages/block, blocks, page_size, spare_size, col_cycles, row_cycles, planes
59*/
60 {0xB1, 0x80, /* MD5N01G51MSD1B */
61 64, 1024, 2048, 64, 2, 2, 1 },
62};
63
54#define NI(id, x) {id, (struct nand_info*)x, (sizeof(x)/sizeof(struct nand_info))} 64#define NI(id, x) {id, (struct nand_info*)x, (sizeof(x)/sizeof(struct nand_info))}
55static const struct nand_manufacturer all[] = 65static const struct nand_manufacturer all[] =
56{ 66{
57 NI(0xEC, samsung), 67 NI(0xEC, samsung),
68 NI(0x98, gigadevice),
58}; 69};
59 70
60// ----------------------------------------------------------------------------- 71// -----------------------------------------------------------------------------
@@ -63,7 +74,7 @@ struct nand_info* nand_identify(unsigned char data[5])
63 { 74 {
64 unsigned int i; 75 unsigned int i;
65 int found = -1; 76 int found = -1;
66 77
67 for(i = 0; i < (sizeof(all)/sizeof(struct nand_manufacturer)); i++) 78 for(i = 0; i < (sizeof(all)/sizeof(struct nand_manufacturer)); i++)
68 { 79 {
69 if(data[0] == all[i].id) 80 if(data[0] == all[i].id)
@@ -72,16 +83,16 @@ struct nand_info* nand_identify(unsigned char data[5])
72 break; 83 break;
73 } 84 }
74 } 85 }
75 86
76 if(found < 0) 87 if(found < 0)
77 return NULL; 88 return NULL;
78 89
79 for(i = 0; i < all[found].total; i++) 90 for(i = 0; i < all[found].total; i++)
80 { 91 {
81 if(data[1] == all[found].info[i].dev_id && 92 if(data[1] == all[found].info[i].dev_id &&
82 data[2] == all[found].info[i].dev_id2) 93 data[2] == all[found].info[i].dev_id2)
83 return &all[found].info[i]; 94 return &all[found].info[i];
84 } 95 }
85 96
86 return NULL; 97 return NULL;
87} 98}
diff --git a/firmware/drivers/rtc/rtc_jz4760.c b/firmware/drivers/rtc/rtc_jz4760.c
new file mode 100644
index 0000000000..cda618d617
--- /dev/null
+++ b/firmware/drivers/rtc/rtc_jz4760.c
@@ -0,0 +1,124 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 by Roman Stolyarov
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/*
23 * Real Time Clock interface for Jz4760.
24 *
25 */
26
27#include "config.h"
28#include "cpu.h"
29#include "rtc.h"
30#include "timefuncs.h"
31#include "logf.h"
32
33#define RTC_FREQ_DIVIDER (32768 - 1)
34
35/* Stolen from dietlibc-0.29/libugly/gmtime_r.c (GPLv2) */
36#define SPD (24*60*60)
37#define ISLEAP(year) (!(year%4) && ((year%100) || !(year%400)))
38static void _localtime(const time_t t, struct tm *r)
39{
40 time_t i;
41 register time_t work = t % SPD;
42 static int m_to_d[12] = /* This could be shared with mktime() */
43 {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
44
45 r->tm_sec = work % 60;
46 work /= 60;
47 r->tm_min = work % 60;
48 r->tm_hour = work / 60;
49 work = t / SPD;
50 r->tm_wday = (4 + work) % 7;
51
52 for (i=1970; ; ++i)
53 {
54 register time_t k = ISLEAP(i) ? 366 : 365;
55
56 if (work >= k)
57 work -= k;
58 else
59 break;
60 }
61
62 r->tm_year = i - 1900;
63 r->tm_yday = work;
64
65 r->tm_mday = 1;
66 if (ISLEAP(i) && (work>58))
67 {
68 if (work==59)
69 r->tm_mday=2; /* 29.2. */
70
71 work-=1;
72 }
73
74 for (i=11; i && (m_to_d[i] > work); --i);
75 r->tm_mon = i;
76 r->tm_mday += work - m_to_d[i];
77}
78
79int rtc_read_datetime(struct tm *tm)
80{
81 _localtime(rtc_read_reg(RTC_RTCSR), tm);
82
83 return 1;
84}
85
86int rtc_write_datetime(const struct tm *tm)
87{
88 rtc_write_reg(RTC_RTCSR, mktime((struct tm*)tm));
89
90 return 0;
91}
92
93void rtc_init(void)
94{
95 unsigned int cfc,hspr,rgr_1hz;
96
97 __cpm_select_rtcclk_rtc();
98
99 cfc = HSPR_RTCV;
100 hspr = rtc_read_reg(RTC_HSPR);
101 rgr_1hz = rtc_read_reg(RTC_RTCGR) & RTCGR_NC1HZ_MASK;
102
103 if((hspr != cfc) || (rgr_1hz != RTC_FREQ_DIVIDER))
104 {
105 /* We are powered on for the first time !!! */
106
107 /* Set 32768 rtc clocks per seconds */
108 rtc_write_reg(RTC_RTCGR, RTC_FREQ_DIVIDER);
109
110 /* Set minimum wakeup_n pin low-level assertion time for wakeup: 100ms */
111 rtc_write_reg(RTC_HWFCR, HWFCR_WAIT_TIME(100));
112 rtc_write_reg(RTC_HRCR, HRCR_WAIT_TIME(60));
113
114 /* Reset to the default time */
115 rtc_write_reg(RTC_RTCSR, 946681200); /* 01/01/2000 */
116
117 /* start rtc */
118 rtc_write_reg(RTC_RTCCR, RTCCR_RTCE);
119 rtc_write_reg(RTC_HSPR, cfc);
120 }
121
122 /* clear all rtc flags */
123 rtc_write_reg(RTC_HWRSR, 0);
124}