summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES117
-rw-r--r--firmware/common/crc32-mi4.c110
-rw-r--r--firmware/common/crc32.c30
-rw-r--r--firmware/common/timefuncs.c16
-rw-r--r--firmware/common/ucl_decompress.c192
-rw-r--r--firmware/common/vuprintf.c11
-rw-r--r--firmware/drivers/ata.c110
-rw-r--r--firmware/drivers/ata_flash.c484
-rw-r--r--firmware/drivers/audio/aic3x.c8
-rw-r--r--firmware/drivers/audio/ak4376.c70
-rw-r--r--firmware/drivers/axp-pmu.c670
-rw-r--r--firmware/drivers/axp173.c419
-rw-r--r--firmware/drivers/fat.c57
-rw-r--r--firmware/drivers/ft6x06.c115
-rw-r--r--firmware/drivers/lcd-16bit-common.c17
-rw-r--r--firmware/drivers/rtc/rtc_d2.c2
-rw-r--r--firmware/drivers/rtc/rtc_ds1339_ds3231.c2
-rw-r--r--firmware/drivers/rtc/rtc_e8564.c2
-rw-r--r--firmware/drivers/rtc/rtc_mr100.c2
-rw-r--r--firmware/drivers/rtc/rtc_pcf50605.c2
-rw-r--r--firmware/drivers/rtc/rtc_pcf50606.c3
-rw-r--r--firmware/drivers/rtc/rtc_rx5x348ab.c2
-rw-r--r--firmware/drivers/rtc/rtc_s35380a.c2
-rw-r--r--firmware/drivers/rtc/rtc_s35390a.c2
-rw-r--r--firmware/drivers/rtc/rtc_s3c2440.c2
-rw-r--r--firmware/drivers/rtc/rtc_tcc77x.c81
-rw-r--r--firmware/drivers/synaptics-mep.c5
-rw-r--r--firmware/drivers/tuner/lv24020lp.c10
-rw-r--r--firmware/drivers/usb-designware.c (renamed from firmware/target/arm/usb-designware.c)13
-rw-r--r--firmware/export/ak4376.h42
-rw-r--r--firmware/export/axp-pmu.h151
-rw-r--r--firmware/export/axp173.h94
-rw-r--r--firmware/export/config.h44
-rw-r--r--firmware/export/config/aigoerosq.h1
-rw-r--r--firmware/export/config/fiiom3k.h27
-rw-r--r--firmware/export/config/iaudio7.h164
-rw-r--r--firmware/export/config/ibassodx50.h6
-rw-r--r--firmware/export/config/ibassodx90.h6
-rw-r--r--firmware/export/config/iriverifp7xx.h129
-rw-r--r--firmware/export/config/logikdax.h152
-rw-r--r--firmware/export/config/sansac100.h130
-rw-r--r--firmware/export/config/sansaconnect.h16
-rw-r--r--firmware/export/config/sansam200.h139
-rw-r--r--firmware/export/cpu.h6
-rw-r--r--firmware/export/dm320.h17
-rw-r--r--firmware/export/ft6x06.h (renamed from firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c)59
-rw-r--r--firmware/export/gdb_api.h3
-rw-r--r--firmware/export/ifp_usb_serial.h30
-rw-r--r--firmware/export/installer.h31
-rw-r--r--firmware/export/tcc77x.h262
-rw-r--r--firmware/export/ucl_decompress.h32
-rw-r--r--firmware/export/usb_ch9.h17
-rw-r--r--firmware/export/x1000.h72
-rw-r--r--firmware/ifp_usb_serial.c1121
-rw-r--r--firmware/include/crc32-mi4.h25
-rw-r--r--firmware/include/crc32.h1
-rw-r--r--firmware/include/timefuncs.h1
-rw-r--r--firmware/rolo.c22
-rw-r--r--firmware/target/arm/ata-nand-telechips.c9
-rw-r--r--firmware/target/arm/lcd-ssd1815.c75
-rw-r--r--firmware/target/arm/pcm-telechips.c18
-rw-r--r--firmware/target/arm/pnx0101/app.lds144
-rw-r--r--firmware/target/arm/pnx0101/backlight-target.h28
-rw-r--r--firmware/target/arm/pnx0101/crt0-pnx0101.S225
-rw-r--r--firmware/target/arm/pnx0101/debug-pnx0101.c5
-rw-r--r--firmware/target/arm/pnx0101/i2c-pnx0101.c24
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/adc-ifp7xx.c59
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/adc-target.h31
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/backlight-ifp7xx.c35
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/button-ifp7xx.c90
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/button-target.h49
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/lcd-ifp7xx.c224
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c76
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c55
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/system-target.h36
-rw-r--r--firmware/target/arm/pnx0101/kernel-pnx0101.c45
-rw-r--r--firmware/target/arm/pnx0101/pcm-pnx0101.c207
-rw-r--r--firmware/target/arm/pnx0101/system-pnx0101.c317
-rw-r--r--firmware/target/arm/pnx0101/timer-pnx0101.c81
-rw-r--r--firmware/target/arm/pp/mi4-loader.c5
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c2
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/rtc-6g.c2
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c47
-rw-r--r--firmware/target/arm/system-arm.h2
-rw-r--r--firmware/target/arm/tcc77x/adc-tcc77x.c121
-rw-r--r--firmware/target/arm/tcc77x/app.lds99
-rw-r--r--firmware/target/arm/tcc77x/ata-nand-target.h33
-rw-r--r--firmware/target/arm/tcc77x/boot.lds63
-rw-r--r--firmware/target/arm/tcc77x/c100/adc-target.h26
-rw-r--r--firmware/target/arm/tcc77x/c100/backlight-target.h40
-rw-r--r--firmware/target/arm/tcc77x/c100/button-c100.c64
-rw-r--r--firmware/target/arm/tcc77x/c100/button-target.h45
-rw-r--r--firmware/target/arm/tcc77x/c100/lcd-S6B33B2.c286
-rw-r--r--firmware/target/arm/tcc77x/c100/power-c100.c43
-rw-r--r--firmware/target/arm/tcc77x/crt0.S230
-rw-r--r--firmware/target/arm/tcc77x/debug-tcc77x.c77
-rw-r--r--firmware/target/arm/tcc77x/i2c-target.h39
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/adc-target.h28
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/ata2501.c110
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/ata2501.h27
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c94
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/backlight-target.h48
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/button-iaudio7.c93
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/button-target.h47
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c260
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c149
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c84
-rw-r--r--firmware/target/arm/tcc77x/kernel-tcc77x.c47
-rw-r--r--firmware/target/arm/tcc77x/logikdax/adc-target.h28
-rw-r--r--firmware/target/arm/tcc77x/logikdax/audio-logikdax.c40
-rw-r--r--firmware/target/arm/tcc77x/logikdax/backlight-target.h40
-rw-r--r--firmware/target/arm/tcc77x/logikdax/button-logikdax.c100
-rw-r--r--firmware/target/arm/tcc77x/logikdax/button-target.h45
-rw-r--r--firmware/target/arm/tcc77x/logikdax/power-logikdax.c44
-rw-r--r--firmware/target/arm/tcc77x/m200/adc-target.h28
-rw-r--r--firmware/target/arm/tcc77x/m200/audio-m200.c38
-rw-r--r--firmware/target/arm/tcc77x/m200/backlight-target.h44
-rw-r--r--firmware/target/arm/tcc77x/m200/button-m200.c99
-rw-r--r--firmware/target/arm/tcc77x/m200/button-target.h45
-rw-r--r--firmware/target/arm/tcc77x/m200/power-m200.c43
-rw-r--r--firmware/target/arm/tcc77x/powermgmt-tcc77x.c66
-rw-r--r--firmware/target/arm/tcc77x/system-target.h59
-rw-r--r--firmware/target/arm/tcc77x/system-tcc77x.c326
-rw-r--r--firmware/target/arm/tcc77x/timer-tcc77x.c69
-rw-r--r--firmware/target/arm/tms320dm320/boot.lds12
-rw-r--r--firmware/target/arm/tms320dm320/crt0.S6
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c468
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h1
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c1
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c14
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c65
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/tnetv105_cppi.c1044
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/tnetv105_cppi.h144
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c1521
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.h335
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c67
-rw-r--r--firmware/target/arm/tms320dm320/sdmmc-dm320.c96
-rw-r--r--firmware/target/arm/tms320dm320/system-dm320.c7
-rw-r--r--firmware/target/arm/tms320dm320/system-target.h1
-rw-r--r--firmware/target/arm/wmcodec-telechips.c2
-rw-r--r--firmware/target/hosted/sdl/sim-ui-defines.h14
-rw-r--r--firmware/target/mips/ingenic_jz47xx/app.lds3
-rw-r--r--firmware/target/mips/ingenic_jz47xx/boot.lds9
-rw-r--r--firmware/target/mips/ingenic_x1000/aic-x1000.c132
-rw-r--r--firmware/target/mips/ingenic_x1000/aic-x1000.h130
-rw-r--r--firmware/target/mips/ingenic_x1000/app.lds38
-rw-r--r--firmware/target/mips/ingenic_x1000/boot.lds6
-rw-r--r--firmware/target/mips/ingenic_x1000/clk-x1000.c236
-rw-r--r--firmware/target/mips/ingenic_x1000/clk-x1000.h6
-rw-r--r--firmware/target/mips/ingenic_x1000/crt0.S33
-rw-r--r--firmware/target/mips/ingenic_x1000/debug-x1000.c8
-rw-r--r--firmware/target/mips/ingenic_x1000/dma-x1000.h5
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c68
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/backlight-fiiom3k.c1
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/boot.make30
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c228
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/gpio-target.h26
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/i2c-target.h4
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/installer-fiiom3k.c338
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/installer-fiiom3k.h51
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/lcd-fiiom3k.c25
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/nand-fiiom3k.c53
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/nand-target.h42
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c41
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/spl-fiiom3k.c190
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/spl-target.h29
-rw-r--r--firmware/target/mips/ingenic_x1000/gpio-x1000.c106
-rw-r--r--firmware/target/mips/ingenic_x1000/gpio-x1000.h170
-rw-r--r--firmware/target/mips/ingenic_x1000/i2c-x1000.c18
-rw-r--r--firmware/target/mips/ingenic_x1000/kernel-x1000.c20
-rw-r--r--firmware/target/mips/ingenic_x1000/lcd-x1000.c61
-rw-r--r--firmware/target/mips/ingenic_x1000/lcd-x1000.h23
-rw-r--r--firmware/target/mips/ingenic_x1000/msc-x1000.c77
-rw-r--r--firmware/target/mips/ingenic_x1000/msc-x1000.h9
-rw-r--r--firmware/target/mips/ingenic_x1000/nand-x1000-err.h18
-rw-r--r--firmware/target/mips/ingenic_x1000/nand-x1000.c663
-rw-r--r--firmware/target/mips/ingenic_x1000/nand-x1000.h217
-rw-r--r--firmware/target/mips/ingenic_x1000/pcm-x1000.c98
-rw-r--r--firmware/target/mips/ingenic_x1000/pwm-x1000.c50
-rw-r--r--firmware/target/mips/ingenic_x1000/sd-x1000.c3
-rw-r--r--firmware/target/mips/ingenic_x1000/sfc-x1000.c44
-rw-r--r--firmware/target/mips/ingenic_x1000/sfc-x1000.h2
-rw-r--r--firmware/target/mips/ingenic_x1000/spl-start.S97
-rw-r--r--firmware/target/mips/ingenic_x1000/spl-x1000-defs.h66
-rw-r--r--firmware/target/mips/ingenic_x1000/spl-x1000.c119
-rw-r--r--firmware/target/mips/ingenic_x1000/spl-x1000.h23
-rw-r--r--firmware/target/mips/ingenic_x1000/spl.lds37
-rw-r--r--firmware/target/mips/ingenic_x1000/system-target.h25
-rw-r--r--firmware/target/mips/ingenic_x1000/system-x1000.c11
-rw-r--r--firmware/target/mips/ingenic_x1000/usb-x1000.c211
-rw-r--r--firmware/target/mips/ingenic_x1000/x1000/aic.h270
-rw-r--r--firmware/target/mips/ingenic_x1000/x1000/cpm.h534
-rw-r--r--firmware/target/mips/ingenic_x1000/x1000/efuse.h173
-rw-r--r--firmware/target/mips/ingenic_x1000/x1000/pcm.h251
-rw-r--r--firmware/target/mips/ingenic_x1000/x1000/ssi.h323
-rw-r--r--firmware/target/mips/ingenic_x1000/x1000/uart.h390
-rw-r--r--firmware/target/mips/ingenic_x1000/x1000boot.make53
-rw-r--r--firmware/target/mips/mipsr2-endian.h7
-rw-r--r--firmware/target/mips/mmu-mips.h17
-rw-r--r--firmware/usb.c2
-rw-r--r--firmware/usbstack/usb_serial.c222
-rw-r--r--firmware/usbstack/usb_storage.c4
202 files changed, 9522 insertions, 10936 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index ce3d8d52e2..dc1ed865dd 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -242,9 +242,6 @@ common/crc32.c
#ifdef MODEL_NUMBER
common/loader_strerror.c
#endif
-#ifdef MI4_FORMAT
-common/crc32-mi4.c
-#endif
#ifdef RKW_FORMAT
common/crc32-rkw.c
#endif
@@ -336,9 +333,6 @@ drivers/touchscreen.c
/* Storage */
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
-#if (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_IFP7XX)
-drivers/ata_flash.c
-#endif
#if (CONFIG_STORAGE & STORAGE_NAND) && (CONFIG_NAND == NAND_TCC)
target/arm/ata-nand-telechips.c
#endif
@@ -392,8 +386,6 @@ drivers/rtc/rtc_rx5x348ab.c
drivers/rtc/rtc_mr100.c
#elif (CONFIG_RTC == RTC_MC13783)
drivers/rtc/rtc_mc13783.c
-#elif (CONFIG_RTC == RTC_TCC77X)
-drivers/rtc/rtc_tcc77x.c
#elif (CONFIG_RTC == RTC_JZ4740)
drivers/rtc/rtc_jz4740.c
#elif (CONFIG_RTC == RTC_JZ4760)
@@ -603,7 +595,7 @@ target/arm/ipod/powermgmt-ipod-pcf.c
target/arm/pp/i2c-pp.c
#elif CONFIG_I2C == I2C_PNX0101
target/arm/pnx0101/i2c-pnx0101.c
-#elif CONFIG_I2C == I2C_TCC780X || CONFIG_I2C == I2C_TCC77X
+#elif CONFIG_I2C == I2C_TCC780X
target/arm/i2c-telechips.c
#elif CONFIG_I2C == I2C_S3C2440
target/arm/s3c2440/i2c-s3c2440.c
@@ -749,8 +741,6 @@ target/arm/pnx0101/crt0-pnx0101.S
target/arm/tms320dm320/crt0.S
#elif CONFIG_CPU==S3C2440
target/arm/s3c2440/crt0.S
-#elif defined(CPU_TCC77X)
-target/arm/tcc77x/crt0.S
#elif defined(CPU_TCC780X)
target/arm/tcc780x/crt0.S
#elif CONFIG_CPU==IMX31L
@@ -841,7 +831,7 @@ target/arm/as3525/usb-drv-as3525.c
#elif CONFIG_USBOTG == USBOTG_S3C6400X
target/arm/usb-s3c6400x.c
#elif CONFIG_USBOTG == USBOTG_DESIGNWARE
-target/arm/usb-designware.c
+drivers/usb-designware.c
#elif CONFIG_USBOTG == USBOTG_ISP1583
drivers/isp1583.c
#elif CONFIG_USBOTG == USBOTG_RK27XX
@@ -897,28 +887,8 @@ target/arm/s5l8700/ipodnano2g/adc-nano2g.c
target/arm/s5l8700/adc-s5l8700.c
# endif
-#elif CONFIG_I2C == I2C_TCC77X
-target/arm/tcc77x/adc-tcc77x.c
-
#endif /* CONFIG_I2C */
-#ifdef CPU_TCC77X
-target/arm/usb-tcc.c
-target/arm/tcc77x/kernel-tcc77x.c
-target/arm/tcc77x/system-tcc77x.c
-target/arm/tcc77x/timer-tcc77x.c
-# ifndef IAUDIO7
-target/arm/tcc77x/powermgmt-tcc77x.c
-# endif /* !IAUDIO7 */
-# ifndef BOOTLOADER
-# ifndef SANSA_C100
-target/arm/wmcodec-telechips.c
-# endif /* !C100 */
-target/arm/pcm-telechips.c
-target/arm/tcc77x/debug-tcc77x.c
-# endif /* !BOOTLOADER */
-#endif /* CPU_TCC77X */
-
#if CONFIG_CPU == S5L8700 || CONFIG_CPU == S5L8701
target/arm/s5l8700/kernel-s5l8700.c
target/arm/s5l8700/system-s5l8700.c
@@ -1063,12 +1033,9 @@ target/coldfire/iaudio/audio-iaudio.c
#endif
#endif /* IAUDIO_M3 */
-#ifdef IRIVER_IFP7XX_SERIES
#ifdef STUB
-ifp_usb_serial.c
libc/sscanf.c
#endif /* STUB */
-#endif /* IRIVER_IFP7XX_SERIES */
#if defined(IRIVER_H300_SERIES) || defined(IRIVER_H100_SERIES)
target/coldfire/iriver/ata-iriver.c
@@ -1293,7 +1260,8 @@ target/arm/tms320dm320/sansa-connect/crt0-board.S
target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c
target/arm/tms320dm320/sansa-connect/adc-sansaconnect.c
target/arm/tms320dm320/sansa-connect/power-sansaconnect.c
-target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c
+target/arm/tms320dm320/sansa-connect/tnetv105_cppi.c
+target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c
target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c
target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
target/arm/tms320dm320/sansa-connect/backlight-sansaconnect.c
@@ -1373,47 +1341,6 @@ target/arm/ipod/button-mini1g.c
target/arm/ipod/button-clickwheel.c
#endif /* IPOD_MINI2G */
-#ifdef IRIVER_IFP7XX
-target/arm/pnx0101/iriver-ifp7xx/adc-ifp7xx.c
-target/arm/pnx0101/iriver-ifp7xx/backlight-ifp7xx.c
-target/arm/pnx0101/iriver-ifp7xx/button-ifp7xx.c
-target/arm/pnx0101/iriver-ifp7xx/lcd-ifp7xx.c
-target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c
-target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c
-target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
-#ifndef BOOTLOADER
-target/arm/pnx0101/pcm-pnx0101.c
-#endif /* BOOTLOADER */
-#endif /* IRIVER_IFP7XX */
-
-#ifdef LOGIK_DAX
-drivers/nand_id.c
-target/arm/tcc77x/logikdax/button-logikdax.c
-target/arm/tcc77x/logikdax/power-logikdax.c
-#ifndef BOOTLOADER
-target/arm/tcc77x/logikdax/audio-logikdax.c
-#endif /* BOOTLOADER */
-#endif /* LOGIK_DAX */
-
-#ifdef SANSA_M200
-drivers/nand_id.c
-target/arm/tcc77x/m200/button-m200.c
-target/arm/tcc77x/m200/power-m200.c
-#ifndef BOOTLOADER
-target/arm/tcc77x/m200/audio-m200.c
-#endif /* BOOTLOADER */
-#endif /* SANSA_M200 */
-
-#ifdef SANSA_C100
-drivers/nand_id.c
-target/arm/tcc77x/c100/lcd-S6B33B2.c
-target/arm/tcc77x/c100/button-c100.c
-target/arm/tcc77x/c100/power-c100.c
-#ifndef BOOTLOADER
-target/arm/tcc77x/c100/audio-c100.c
-#endif /* BOOTLOADER */
-#endif /* SANSA_C100 */
-
#ifdef SANSA_CLIPPLUS
target/arm/as3525/sansa-clipplus/lcd-clip-plus.c
target/arm/as3525/sansa-clipplus/button-clip.c
@@ -1525,19 +1452,6 @@ target/arm/as3525/sansa-clipzip/powermgmt-clipzip.c
#endif /* !BOOTLOADER */
#endif /* SANSA_CLIPZIP */
-#ifdef IAUDIO_7
-drivers/nand_id.c
-drivers/pcf50606.c
-target/arm/tcc77x/iaudio7/lcd-iaudio7.c
-target/arm/tcc77x/iaudio7/power-iaudio7.c
-target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c
-target/arm/tcc77x/iaudio7/button-iaudio7.c
-target/arm/tcc77x/iaudio7/ata2501.c
-#ifndef BOOTLOADER
-target/arm/tcc77x/iaudio7/audio-iaudio7.c
-#endif /* BOOTLOADER */
-#endif /* IAUDIO_7 */
-
#ifdef COWON_D2
drivers/lcd-memframe.c
drivers/nand_id.c
@@ -1741,15 +1655,18 @@ target/mips/ingenic_x1000/pwm-x1000.c
target/mips/ingenic_x1000/sfc-x1000.c
target/mips/ingenic_x1000/system-x1000.c
target/mips/ingenic_x1000/timer-x1000.c
+#ifndef USB_NONE
+target/mips/ingenic_x1000/usb-x1000.c
+#endif
#if (CONFIG_STORAGE & (STORAGE_SD|STORAGE_MMC|STORAGE_ATA))
target/mips/ingenic_x1000/msc-x1000.c
#endif
#if (CONFIG_STORAGE & STORAGE_SD)
target/mips/ingenic_x1000/sd-x1000.c
#endif
-#ifdef BOOTLOADER_SPL
+target/mips/ingenic_x1000/spl-start.S
target/mips/ingenic_x1000/spl-x1000.c
-#endif
+common/ucl_decompress.c
#endif /* CONFIG_CPU == X1000 */
#if defined(ONDA_VX747) || defined(ONDA_VX747P) || defined(ONDA_VX777)
@@ -1779,12 +1696,11 @@ target/mips/ingenic_jz47xx/xduoo_x3/sadc-xduoo_x3.c
target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
target/mips/ingenic_x1000/fiiom3k/backlight-fiiom3k.c
target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c
-target/mips/ingenic_x1000/fiiom3k/installer-fiiom3k.c
target/mips/ingenic_x1000/fiiom3k/lcd-fiiom3k.c
-target/mips/ingenic_x1000/fiiom3k/nand-fiiom3k.c
target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
-#ifdef BOOTLOADER_SPL
target/mips/ingenic_x1000/fiiom3k/spl-fiiom3k.c
+#ifdef BOOTLOADER
+target/mips/ingenic_x1000/fiiom3k/installer-fiiom3k.c
#endif
#endif /* FIIO_M3K */
@@ -2009,12 +1925,17 @@ target/hosted/sdl/filesystem-sdl.c
drivers/touchpad.c
#endif
+/* Hardware drivers */
+#ifndef SIMULATOR
#ifdef HAVE_I2C_ASYNC
drivers/i2c-async.c
#endif
-
-#ifdef HAVE_AXP173
-drivers/axp173.c
+#ifdef HAVE_AXP_PMU
+drivers/axp-pmu.c
+#endif
+#ifdef HAVE_FT6x06
+drivers/ft6x06.c
+#endif
#endif
/* firmware/kernel section */
diff --git a/firmware/common/crc32-mi4.c b/firmware/common/crc32-mi4.c
deleted file mode 100644
index e1a5769018..0000000000
--- a/firmware/common/crc32-mi4.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id: crc32.c 10464 2006-08-05 20:19:10Z miipekk $
- *
- * Copyright (C) 2007 Barry Wardell
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-/*
- * We can't use the CRC32 implementation in the firmware library as it uses a
- * different polynomial. The polynomial needed is 0xEDB88320L
- *
- * CRC32 implementation taken from:
- *
- * efone - Distributed internet phone system.
- *
- * (c) 1999,2000 Krzysztof Dabrowski
- * (c) 1999,2000 ElysiuM deeZine
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
- */
-
-/* based on implementation by Finn Yannick Jacobs */
-
-#include "crc32-mi4.h"
-
-/* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab().
- * so make sure, you call it before using the other
- * functions!
- */
-static const unsigned int crc_tab[256] = {
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
- 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
- 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
- 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
- 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
- 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
- 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
- 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
- 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
- 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
- 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
- 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
- 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
- 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
- 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
- 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
- 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
- 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
- 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
- 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
- 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
- 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
-};
-
-/* chksum_crc() -- to a given block, this one calculates the
- * crc32-checksum until the length is
- * reached. the crc32-checksum will be
- * the result.
- */
-unsigned int chksum_crc32 (unsigned char *block, unsigned int length)
-{
- register unsigned long crc;
- unsigned long i;
-
- crc = 0;
- for (i = 0; i < length; i++)
- {
- crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF];
- }
- return (crc);
-}
diff --git a/firmware/common/crc32.c b/firmware/common/crc32.c
index c8c70e415c..1a9bc4faea 100644
--- a/firmware/common/crc32.c
+++ b/firmware/common/crc32.c
@@ -61,3 +61,33 @@ uint32_t crc_32(const void *src, uint32_t len, uint32_t crc32)
return crc32;
}
+
+/* crc_32r (derived from tinf crc32 which was taken from zlib)
+ * CRC32 algorithm taken from the zlib source, which is
+ * Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
+ */
+
+/* Tool function to calculate a CRC32 (reversed polynomial) across some buffer */
+/* third argument is either the starting value or value from last piece */
+uint32_t crc_32r(const void *src, uint32_t len, uint32_t crc32)
+{
+ const unsigned char* buf = src;
+
+ /* reversed polynomial from other crc32 function -- 0xEDB88320 */
+ static const unsigned crc32_lookup[16] =
+ {
+ 0x00000000, 0x1DB71064, 0x3B6E20C8, 0x26D930AC,
+ 0x76DC4190, 0x6B6B51F4, 0x4DB26158, 0x5005713C,
+ 0xEDB88320, 0xF00F9344, 0xD6D6A3E8, 0xCB61B38C,
+ 0x9B64C2B0, 0x86D3D2D4, 0xA00AE278, 0xBDBDF21C
+ };
+
+ for(uint32_t i = 0; i < len; i++)
+ {
+ crc32 ^= buf[i];
+ crc32 = crc32_lookup[crc32 & 0x0F] ^ (crc32 >> 4);
+ crc32 = crc32_lookup[crc32 & 0x0F] ^ (crc32 >> 4);
+ }
+
+ return crc32;
+}
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index 50addad27a..108431753a 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -135,5 +135,21 @@ void set_day_of_week(struct tm *tm)
if(m == 0 || m == 1) y--;
tm->tm_wday = (d + mo[m] + y + y/4 - y/100 + y/400) % 7;
}
+
+void set_day_of_year(struct tm *tm)
+{
+ int y=tm->tm_year+1900;
+ int d=tm->tm_mday;
+ int m=tm->tm_mon;
+ d+=m*30;
+ if( ( (m>1) && !(y%4) ) && ( (y%100) || !(y%400) ) )
+ d++;
+ if(m>6)
+ {
+ d+=4;
+ m-=7;
+ }
+ tm->tm_yday = d + ((m+1) /2);
+}
#endif /* CONFIG_RTC */
diff --git a/firmware/common/ucl_decompress.c b/firmware/common/ucl_decompress.c
new file mode 100644
index 0000000000..3b43d76f9d
--- /dev/null
+++ b/firmware/common/ucl_decompress.c
@@ -0,0 +1,192 @@
+/* Standalone version of ucl_nrv2e_decompress_8 from UCL library
+ * Original copyright notice:
+ */
+/* n2e_d.c -- implementation of the NRV2E decompression algorithm
+
+ This file is part of the UCL data compression library.
+
+ Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
+ All Rights Reserved.
+
+ The UCL library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ The UCL library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with the UCL library; see the file COPYING.
+ If not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ Markus F.X.J. Oberhumer
+ <markus@oberhumer.com>
+ http://www.oberhumer.com/opensource/ucl/
+ */
+
+#include "ucl_decompress.h"
+
+#define UCL_UINT32_C(c) c ## U
+#define fail(x, r) do if(x) { *dst_len = olen; return r; } while(0)
+
+#define getbit(bb) \
+ (((bb = bb & 0x7f ? bb*2 : ((unsigned)src[ilen++]*2+1)) >> 8) & 1)
+
+int ucl_nrv2e_decompress_8(const uint8_t* src, uint32_t src_len,
+ uint8_t* dst, uint32_t* dst_len)
+{
+ uint32_t bb = 0;
+ uint32_t ilen = 0, olen = 0, last_m_off = 1;
+ uint32_t oend = *dst_len;
+
+ for (;;)
+ {
+ uint32_t m_off, m_len;
+
+ while (getbit(bb))
+ {
+ fail(ilen >= src_len, UCL_E_INPUT_OVERRUN);
+ fail(olen >= oend, UCL_E_OUTPUT_OVERRUN);
+ dst[olen++] = src[ilen++];
+ }
+ m_off = 1;
+ for (;;)
+ {
+ m_off = m_off*2 + getbit(bb);
+ fail(ilen >= src_len, UCL_E_INPUT_OVERRUN);
+ fail(m_off > UCL_UINT32_C(0xffffff) + 3, UCL_E_LOOKBEHIND_OVERRUN);
+ if (getbit(bb)) break;
+ m_off = (m_off-1)*2 + getbit(bb);
+ }
+ if (m_off == 2)
+ {
+ m_off = last_m_off;
+ m_len = getbit(bb);
+ }
+ else
+ {
+ fail(ilen >= src_len, UCL_E_INPUT_OVERRUN);
+ m_off = (m_off-3)*256 + src[ilen++];
+ if (m_off == UCL_UINT32_C(0xffffffff))
+ break;
+ m_len = (m_off ^ UCL_UINT32_C(0xffffffff)) & 1;
+ m_off >>= 1;
+ last_m_off = ++m_off;
+ }
+ if (m_len)
+ m_len = 1 + getbit(bb);
+ else if (getbit(bb))
+ m_len = 3 + getbit(bb);
+ else
+ {
+ m_len++;
+ do {
+ m_len = m_len*2 + getbit(bb);
+ fail(ilen >= src_len, UCL_E_INPUT_OVERRUN);
+ fail(m_len >= oend, UCL_E_OUTPUT_OVERRUN);
+ } while (!getbit(bb));
+ m_len += 3;
+ }
+ m_len += (m_off > 0x500);
+ fail(olen + m_len > oend, UCL_E_OUTPUT_OVERRUN);
+ fail(m_off > olen, UCL_E_LOOKBEHIND_OVERRUN);
+ {
+ const uint8_t *m_pos;
+ m_pos = dst + olen - m_off;
+ dst[olen++] = *m_pos++;
+ do dst[olen++] = *m_pos++; while (--m_len > 0);
+ }
+ }
+ *dst_len = olen;
+ return ilen == src_len ? UCL_E_OK : (ilen < src_len ? UCL_E_INPUT_NOT_CONSUMED : UCL_E_INPUT_OVERRUN);
+}
+
+static uint32_t xread32(const uint8_t* d)
+{
+ uint32_t r = 0;
+ r |= d[0] << 24;
+ r |= d[1] << 16;
+ r |= d[2] << 8;
+ r |= d[3] << 0;
+ return r;
+}
+
+/* From uclpack.c */
+int ucl_unpack(const uint8_t* src, uint32_t src_len,
+ uint8_t* dst, uint32_t* dst_len)
+{
+ static const uint8_t magic[8] =
+ {0x00, 0xe9, 0x55, 0x43, 0x4c, 0xff, 0x01, 0x1a};
+
+ /* make sure there are enough bytes for the header */
+ if(src_len < 18)
+ return UCL_E_BAD_MAGIC;
+
+ /* avoid memcmp for reasons of code size */
+ for(size_t i = 0; i < sizeof(magic); ++i)
+ if(src[i] != magic[i])
+ return UCL_E_BAD_MAGIC;
+
+ /* read the other header fields */
+ /* uint32_t flags = xread32(&src[8]); */
+ uint8_t method = src[12];
+ /* uint8_t level = src[13]; */
+ uint32_t block_size = xread32(&src[14]);
+
+ /* check supported compression method */
+ if(method != 0x2e)
+ return UCL_E_UNSUPPORTED_METHOD;
+
+ /* validate */
+ if(block_size < 1024 || block_size > 8*1024*1024)
+ return UCL_E_BAD_BLOCK_SIZE;
+
+ /* process the blocks */
+ src += 18;
+ src_len -= 18;
+ uint32_t dst_ilen = *dst_len;
+ while(1) {
+ if(src_len < 4)
+ return UCL_E_TRUNCATED;
+
+ uint32_t out_len = xread32(src); src += 4, src_len -= 4;
+ if(out_len == 0)
+ break;
+
+ if(src_len < 4)
+ return UCL_E_TRUNCATED;
+
+ uint32_t in_len = xread32(src); src += 4, src_len -= 4;
+ if(in_len > block_size || out_len > block_size ||
+ in_len == 0 || in_len > out_len)
+ return UCL_E_CORRUPTED;
+
+ if(src_len < in_len)
+ return UCL_E_TRUNCATED;
+
+ if(in_len < out_len) {
+ uint32_t actual_out_len = dst_ilen;
+ int rc = ucl_nrv2e_decompress_8(src, in_len, dst, &actual_out_len);
+ if(rc != UCL_E_OK)
+ return rc;
+ if(actual_out_len != out_len)
+ return UCL_E_CORRUPTED;
+ } else {
+ for(size_t i = 0; i < in_len; ++i)
+ dst[i] = src[i];
+ }
+
+ src += in_len;
+ src_len -= in_len;
+ dst += out_len;
+ dst_ilen -= out_len;
+ }
+
+ /* subtract leftover number of bytes to get size of compressed output */
+ *dst_len -= dst_ilen;
+ return UCL_E_OK;
+}
diff --git a/firmware/common/vuprintf.c b/firmware/common/vuprintf.c
index fb053ae7da..6a3b29388b 100644
--- a/firmware/common/vuprintf.c
+++ b/firmware/common/vuprintf.c
@@ -30,13 +30,10 @@
#ifndef BOOTLOADER
-/* Only the Quake plugin needs float formatting */
-#if defined(HAVE_LCD_COLOR) && \
- (!defined(LCD_STRIDEFORMAT) || (LCD_STRIDEFORMAT != VERTICAL_STRIDE)) && \
- (PLUGIN_BUFFER_SIZE > 0x14000) && (CONFIG_PLATFORM & PLATFORM_NATIVE) && defined(CPU_ARM)
-/* turn everything on */
-#define FMT_LENMOD (0xffffffff)
-#define FMT_RADIX (0xffffffff)
+/* Turn everything on if we have enough RAM. */
+#if MEMORYSIZE >= 8
+# define FMT_LENMOD (0xffffffff)
+# define FMT_RADIX (0xffffffff)
#endif
#endif
diff --git a/firmware/drivers/ata.c b/firmware/drivers/ata.c
index 3514511270..ec99239169 100644
--- a/firmware/drivers/ata.c
+++ b/firmware/drivers/ata.c
@@ -36,14 +36,6 @@
#include "storage.h"
#include "logf.h"
-/* The FC1307A ATA->SD chipset (used by the common iFlash adapters)
- doesn't support mandatory ATA power management commands. Unfortunately
- simply gating off the SLEEP command isn't sufficient; we need to
- disable advanced powersaving entirely because otherwise we might
- kill power before the device has finished flusing writes.
-*/
-//#define FC1307A_WORKAROUND
-
#define SELECT_DEVICE1 0x10
#define SELECT_LBA 0x40
@@ -58,10 +50,14 @@
#define CMD_WRITE_MULTIPLE 0xC5
#define CMD_WRITE_MULTIPLE_EXT 0x39
#define CMD_SET_MULTIPLE_MODE 0xC6
+#ifdef HAVE_ATA_SMART
+#define CMD_SMART 0xB0
+#endif
#define CMD_STANDBY_IMMEDIATE 0xE0
#define CMD_STANDBY 0xE2
#define CMD_IDENTIFY 0xEC
#define CMD_SLEEP 0xE6
+#define CMD_FLUSH_CACHE 0xE7
#define CMD_SET_FEATURES 0xEF
#define CMD_SECURITY_FREEZE_LOCK 0xF5
#ifdef HAVE_ATA_DMA
@@ -75,7 +71,6 @@
#ifdef HAVE_ATA_POWER_OFF
#define ATA_POWER_OFF_TIMEOUT 2*HZ
-#define ATA_POWER_OFF_TIMEOUT_NOPM 5*HZ
#endif
#if defined(HAVE_USBSTACK)
@@ -160,12 +155,7 @@ static inline bool ata_sleep_timed_out(void)
static inline void schedule_ata_power_off(void)
{
#ifdef HAVE_ATA_POWER_OFF
- power_off_tick = current_tick;
- /* If our device doesn't support SLEEP give a bit more time to flush */
- if (!(identify_info[82] & (1 << 3)))
- power_off_tick += ATA_POWER_OFF_TIMEOUT_NOPM;
- else
- power_off_tick += ATA_POWER_OFF_TIMEOUT;
+ power_off_tick = current_tick + ATA_POWER_OFF_TIMEOUT;
#endif
}
@@ -239,12 +229,6 @@ static int ata_perform_wakeup(int state)
static int ata_perform_sleep(void)
{
- /* Don't issue the sleep command if the device
- doesn't support (mandatory!) ATA power management commands!
- */
- if (!(identify_info[82] & (1 << 3)))
- return 0;
-
logf("ata SLEEP %ld", current_tick);
ATA_OUT8(ATA_SELECT, ata_device);
@@ -254,10 +238,25 @@ static int ata_perform_sleep(void)
return -1;
}
- ATA_OUT8(ATA_COMMAND, CMD_SLEEP);
+ /* STANDBY IMMEDIATE
+ - writes all cached data
+ - transitions to PM2:Standby
+ - enters Standby_z power condition
- if (!wait_for_rdy())
- {
+ This places the device into a state where power-off is safe, but
+ it is not the lowest-theoretical power state -- that is SLEEP, but
+ that is bugged on some SSDs (FC1307A-based).
+
+ TODO: Is there a practical downside to using STANDBY_IMMEDIATE instead
+ of SLEEP, assuming the former spins down the drive?
+ */
+ if (ata_disk_isssd()) {
+ ATA_OUT8(ATA_COMMAND, CMD_STANDBY_IMMEDIATE);
+ } else {
+ ATA_OUT8(ATA_COMMAND, CMD_SLEEP);
+ }
+
+ if (!wait_for_rdy()) {
DEBUGF("ata_perform_sleep() - CMD failed\n");
return -2;
}
@@ -265,6 +264,34 @@ static int ata_perform_sleep(void)
return 0;
}
+static int ata_perform_flush_cache(void)
+{
+ /* Don't issue the flush cache command if the device
+ doesn't support it, even though it's mandatory.
+ */
+ if (!(identify_info[83] & (1 << 12)))
+ return 0;
+
+ logf("ata FLUSH CACHE %ld", current_tick);
+
+ ATA_OUT8(ATA_SELECT, ata_device);
+
+ if(!wait_for_rdy()) {
+ DEBUGF("ata_perform_flush_cache() - not RDY\n");
+ return -1;
+ }
+
+ ATA_OUT8(ATA_COMMAND, CMD_FLUSH_CACHE);
+
+ if (!wait_for_rdy()) {
+ DEBUGF("ata_perform_flush_cache() - CMD failed\n");
+ return -2;
+ }
+
+ return 0;
+}
+
+
static ICODE_ATTR int wait_for_start_of_transfer(void)
{
if (!wait_for_bsy())
@@ -361,15 +388,27 @@ static ICODE_ATTR void copy_write_sectors(const unsigned char* buf,
int ata_disk_isssd(void)
{
- /* offset 217 is "Nominal Rotation rate"
+ /*
+ offset 217 is "Nominal Rotation rate"
0x0000 == Not reported
0x0001 == Solid State
0x0401 -> 0xffe == RPM
All others reserved
- Some CF cards return 0x0100 (ie byteswapped 0x0001) so accept either
+ Some CF cards return 0x0100 (ie byteswapped 0x0001) so accept either.
+
+ However, this is a very recent change, and we can't rely on it,
+ especially for the FC1307A CF->SD adapters.
+
+ So we have to resort to other heuristics.
+
+ offset 83 b2 is set to show device implementes CFA commands
+ offset 0 is 0x848a for CF, but that's not guaranteed, because reasons.
+
+ These don't guarantee this is an SSD but it's better than nothing.
*/
- return (identify_info[217] == 0x0001 || identify_info[217] == 0x0100);
+ return (identify_info[83] & (1<<2) ||
+ identify_info[217] == 0x0001 || identify_info[217] == 0x0100);
}
static int ata_transfer_sectors(unsigned long start,
@@ -836,29 +875,16 @@ void ata_spindown(int seconds)
bool ata_disk_is_active(void)
{
-#ifdef FC1307A_WORKAROUND
- /* "active" == "spinning" in this context.
- without power management this becomes moot */
- if (!(identify_info[82] & (1 << 3)))
- return false;
-#endif
-
return ata_state >= ATA_SPINUP;
}
void ata_sleepnow(void)
{
-#ifdef FC1307A_WORKAROUND
- /* Completely disable all power management */
- if (!(identify_info[82] & (1 << 3)))
- return;
-#endif
-
if (ata_state >= ATA_SPINUP) {
logf("ata SLEEPNOW %ld", current_tick);
mutex_lock(&ata_mtx);
if (ata_state == ATA_ON) {
- if (!ata_perform_sleep()) {
+ if (!ata_perform_flush_cache() && !ata_perform_sleep()) {
ata_state = ATA_SLEEPING;
schedule_ata_power_off();
}
@@ -1093,7 +1119,7 @@ static int set_features(void)
unsigned char parameter;
} features[] = {
{ 83, 14, 0x03, 0 }, /* force PIO mode */
- { 83, 3, 0x05, 0x80 }, /* adv. power management: lowest w/o standby */
+ { 83, 3, 0x05, 0x80 }, /* adv. power management: lowest w/o standby */ // TODO: What about FC1307A that doesn't advertise this properly?
{ 83, 9, 0x42, 0x80 }, /* acoustic management: lowest noise */
{ 82, 6, 0xaa, 0 }, /* enable read look-ahead */
#ifdef HAVE_ATA_DMA
diff --git a/firmware/drivers/ata_flash.c b/firmware/drivers/ata_flash.c
deleted file mode 100644
index fbdd7f04ee..0000000000
--- a/firmware/drivers/ata_flash.c
+++ /dev/null
@@ -1,484 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2005 Tomasz Malesinski
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "storage.h"
-#include <stdbool.h>
-#include <string.h>
-
-#if CONFIG_CPU == PNX0101
-#include "pnx0101.h"
-#endif
-
-/*
-#include "kernel.h"
-#include "thread.h"
-#include "led.h"
-#include "cpu.h"
-#include "system.h"
-#include "debug.h"
-#include "panic.h"
-#include "usb.h"
-#include "power.h"
-#include "string.h"
-*/
-
-#define SECTOR_SIZE (512)
-
-static long last_disk_activity = -1;
-
-#if CONFIG_FLASH == FLASH_IFP7XX
-static unsigned char flash_ce[4] = {0x20, 0x02, 0x10, 0x08};
-
-#define FLASH_IO_BASE 0x28000000
-#define FLASH_REG_DATA (*((volatile unsigned char*)(FLASH_IO_BASE)))
-#define FLASH_REG_CMD (*((volatile unsigned char*)(FLASH_IO_BASE + 4)))
-#define FLASH_REG_ADDR (*((volatile unsigned char*)(FLASH_IO_BASE + 8)))
-
-#define SEGMENT_SIZE 1000
-#define MAX_N_SEGMENTS 8
-
-#endif
-
-#define FLASH_MODEL_NONE 0
-#define FLASH_MODEL_256 1
-#define FLASH_MODEL_512 2
-
-struct flash_disk
-{
- unsigned short block_map[MAX_N_SEGMENTS][SEGMENT_SIZE];
- short cur_block;
- int cur_phblock_start;
- int n_chips;
- unsigned char chip_no[4];
- unsigned char model;
-};
-
-static struct flash_disk flash_disk;
-
-static void flash_select_chip(int no, int sel)
-{
-#if CONFIG_FLASH == FLASH_IFP7XX
- if (sel)
- GPIO5_CLR = flash_ce[no];
- else
- GPIO5_SET = flash_ce[no];
-#endif
-}
-
-static inline unsigned char flash_read_data(void)
-{
- return FLASH_REG_DATA;
-}
-
-static inline void flash_write_data(unsigned char data)
-{
- FLASH_REG_DATA = data;
-}
-
-/* TODO: these two doesn't work when inlined, probably some
- delay is required */
-
-static void flash_write_cmd(unsigned char cmd)
-{
- FLASH_REG_CMD = cmd;
-}
-
-static void flash_write_addr(unsigned char addr)
-{
- FLASH_REG_ADDR = addr;
-}
-
-static void flash_wait_ready(void)
-{
- int i;
- for (i = 0; i < 5; i++)
- while ((GPIO6_READ & 8) == 0);
-}
-
-static unsigned char model_n_sectors_order[] = {0, 19, 20};
-
-static int flash_map_sector(int sector, int* chip, int* chip_sector)
-{
- int ord, c;
- if (flash_disk.model == FLASH_MODEL_NONE)
- return -1;
-
- ord = model_n_sectors_order[flash_disk.model];
- c = sector >> ord;
- *chip_sector = sector & ((1 << ord) - 1);
-
- if (c >= flash_disk.n_chips)
- return -1;
-
- *chip = flash_disk.chip_no[c];
- return 0;
-}
-
-static int flash_read_id(int no) {
- int id;
-
- flash_select_chip(no, 1);
- flash_write_cmd(0x90);
- flash_write_addr(0);
-
- flash_read_data();
- id = flash_read_data();
-
- flash_select_chip(no, 0);
- return id;
-}
-
-static int flash_read_sector(int sector, unsigned char* buf,
- unsigned char* oob)
-{
- unsigned long *bufl = (unsigned long *)buf;
- int chip, chip_sector;
- int i;
-
- if (flash_map_sector(sector, &chip, &chip_sector) < 0)
- return -1;
-
- flash_select_chip(chip, 1);
-
- flash_write_cmd(0x00);
- flash_write_addr(0);
- flash_write_addr((chip_sector << 1) & 7);
- flash_write_addr((chip_sector >> 2) & 0xff);
- flash_write_addr((chip_sector >> 10) & 0xff);
- flash_write_addr((chip_sector >> 18) & 0xff);
- flash_write_cmd(0x30);
-
- flash_wait_ready();
-
- if ((unsigned long)buf & 3)
- {
- for (i = 0; i < 512; i++)
- buf[i] = flash_read_data();
- }
- else
- {
- for (i = 0; i < 512 / 4; i++) {
- unsigned long v;
-#ifdef ROCKBOX_LITTLE_ENDIAN
- v = flash_read_data();
- v |= (unsigned long)flash_read_data() << 8;
- v |= (unsigned long)flash_read_data() << 16;
- v |= (unsigned long)flash_read_data() << 24;
-#else
- v = (unsigned long)flash_read_data() << 24;
- v |= (unsigned long)flash_read_data() << 16;
- v |= (unsigned long)flash_read_data() << 8;
- v |= flash_read_data();
-#endif
- bufl[i] = v;
- }
- }
-
- flash_write_cmd(0x05);
- flash_write_addr((chip_sector & 3) * 0x10);
- flash_write_addr(8);
- flash_write_cmd(0xe0);
-
- for (i = 0; i < 16; i++)
- oob[i] = flash_read_data();
-
- flash_select_chip(chip, 0);
- return 0;
-}
-
-static int flash_read_sector_oob(int sector, unsigned char* oob)
-{
- int chip, chip_sector;
- int i;
-
- if (flash_map_sector(sector, &chip, &chip_sector) < 0)
- return -1;
-
- flash_select_chip(chip, 1);
-
- flash_write_cmd(0x00);
- flash_write_addr((chip_sector & 3) * 0x10);
- flash_write_addr(8);
- flash_write_addr((chip_sector >> 2) & 0xff);
- flash_write_addr((chip_sector >> 10) & 0xff);
- flash_write_addr((chip_sector >> 18) & 0xff);
- flash_write_cmd(0x30);
-
- flash_wait_ready();
-
- for (i = 0; i < 16; i++)
- oob[i] = flash_read_data();
-
- flash_select_chip(chip, 0);
- return 0;
-}
-
-static unsigned char model_n_segments[] = {0, 2, 4};
-
-static inline int flash_get_n_segments(void)
-{
- return model_n_segments[flash_disk.model] * flash_disk.n_chips;
-}
-
-static inline int flash_get_n_phblocks(void)
-{
- return 1024;
-}
-
-static int model_n_sectors_in_block[] = {0, 256, 256};
-
-static int flash_get_n_sectors_in_block(void)
-{
- return model_n_sectors_in_block[flash_disk.model];
-}
-
-static int flash_phblock_to_sector(int segment, int block)
-{
- return (segment * flash_get_n_phblocks() + block)
- * flash_get_n_sectors_in_block();
-}
-
-static int flash_is_bad_block(unsigned char* oob)
-{
- /* TODO: should we check two pages? (see datasheet) */
- return oob[0] != 0xff;
-}
-
-static int count_1(int n) {
- int r = 0;
- while (n != 0) {
- r += (n & 1);
- n >>= 1;
- }
- return r;
-}
-
-static int flash_get_logical_block_no(unsigned char* oob)
-{
- int no1, no2;
- no1 = oob[6] + (oob[7] << 8);
- no2 = oob[11] + (oob[12] << 8);
-
- if (no1 == no2 && (no1 & 0xf000) == 0x1000)
- return (no1 & 0xfff) >> 1;
-
- if (count_1(no1 ^ no2) > 1)
- return -1;
-
- if ((no1 & 0xf000) == 0x1000
- && (count_1(no1) & 1) == 0)
- return (no1 & 0xfff) >> 1;
-
- if ((no2 & 0xf000) == 0x1000
- && (count_1(no2) & 1) == 0)
- return (no2 & 0xfff) >> 1;
-
- return -1;
-}
-
-static int flash_disk_scan(void)
-{
- int n_segments, n_phblocks;
- unsigned char oob[16];
- int s, b;
-
- /* TODO: checking for double blocks */
-
- n_segments = flash_get_n_segments();
- n_phblocks = flash_get_n_phblocks();
-
- flash_disk.cur_block = -1;
- flash_disk.cur_phblock_start = -1;
-
- for (s = 0; s < n_segments; s++)
- {
- for (b = 0; b < n_phblocks; b++)
- {
- int r;
- r = flash_read_sector_oob(flash_phblock_to_sector(s, b),
- oob);
- if (r >= 0 && !flash_is_bad_block(oob))
- {
- int lb;
- lb = flash_get_logical_block_no(oob);
- if (lb >= 0 && lb < SEGMENT_SIZE)
- flash_disk.block_map[s][lb] = b;
- }
- }
- }
- return 0;
-}
-
-static int flash_disk_find_block(int block)
-{
- int seg, bmod, phb;
- unsigned char oob[16];
- int r;
-
- if (block >= SEGMENT_SIZE * flash_get_n_segments())
- return -1;
-
- if (block == flash_disk.cur_block)
- return flash_disk.cur_phblock_start;
-
- seg = block / SEGMENT_SIZE;
- bmod = block % SEGMENT_SIZE;
-
- phb = flash_disk.block_map[seg][bmod];
- r = flash_read_sector_oob(flash_phblock_to_sector(seg, phb), oob);
- if (r < 0)
- return -1;
- if (flash_is_bad_block(oob))
- return -1;
- if (flash_get_logical_block_no(oob) != bmod)
- return -1;
-
- flash_disk.cur_block = block;
- flash_disk.cur_phblock_start = flash_phblock_to_sector(seg, phb);
- return flash_disk.cur_phblock_start;
-}
-
-static int flash_disk_read_sectors(unsigned long start,
- int count,
- void* buf)
-{
- int block, secmod, done;
- int phb;
- char oob[16];
-
- block = start / flash_get_n_sectors_in_block();
- secmod = start % flash_get_n_sectors_in_block();
-
- phb = flash_disk_find_block(block);
- done = 0;
- while (count > 0 && secmod < flash_get_n_sectors_in_block())
- {
- if (phb >= 0)
- flash_read_sector(phb + secmod, buf, oob);
- else
- memset(buf, 0, SECTOR_SIZE);
-
- buf += SECTOR_SIZE;
- count--;
- secmod++;
- done++;
- }
- return done;
-}
-
-int nand_read_sectors(IF_MD(int drive,)
- unsigned long start,
- int incount,
- void* inbuf)
-{
- while (incount > 0)
- {
- int done = flash_disk_read_sectors(start, incount, inbuf);
- if (done < 0)
- return -1;
- start += done;
- incount -= done;
- inbuf += SECTOR_SIZE * done;
- }
- return 0;
-}
-
-int nand_write_sectors(IF_MD(int drive,)
- unsigned long start,
- int count,
- const void* buf)
-{
- (void)start;
- (void)count;
- (void)buf;
- return -1;
-}
-
-int nand_init(void)
-{
- int i, id, id2;
-
- id = flash_read_id(0);
- switch (id)
- {
- case 0xda:
- flash_disk.model = FLASH_MODEL_256;
- break;
- case 0xdc:
- flash_disk.model = FLASH_MODEL_512;
- break;
- default:
- flash_disk.model = FLASH_MODEL_NONE;
- return -1;
- }
-
- flash_disk.n_chips = 1;
- flash_disk.chip_no[0] = 0;
- for (i = 1; i < 4; i++)
- {
- id2 = flash_read_id(i);
- if (id2 == id)
- flash_disk.chip_no[flash_disk.n_chips++] = i;
- }
-
- if (flash_disk_scan() < 0)
- return -2;
-
- return 0;
-}
-
-long nand_last_disk_activity(void)
-{
- return last_disk_activity;
-}
-
-#ifdef STORAGE_GET_INFO
-void nand_get_info(struct storage_info *info)
-{
- unsigned long blocks;
- int i;
-
- /* firmware version */
- info->revision="0.00";
-
- /* vendor field, need better name? */
- info->vendor="Rockbox";
- /* model field, need better name? */
- info->product="TNFL";
-
- /* blocks count */
- info->num_sectors = 0;
- info->sector_size=SECTOR_SIZE;
-
- info->serial=0;
-}
-#endif
-
-#ifdef CONFIG_STORAGE_MULTI
-int nand_num_drives(int first_drive)
-{
- /* We don't care which logical drive number(s) we have been assigned */
- (void)first_drive;
-
- return 1;
-}
-#endif
-
diff --git a/firmware/drivers/audio/aic3x.c b/firmware/drivers/audio/aic3x.c
index 9b705db7f5..39576e9f47 100644
--- a/firmware/drivers/audio/aic3x.c
+++ b/firmware/drivers/audio/aic3x.c
@@ -305,8 +305,8 @@ void aic3x_switch_output(bool stereo)
{
if (stereo)
{
- /* mute MONO_LOP/M */
- aic3x_change_reg(AIC3X_MONO_LOP_M_LVL, 0x00, 0xF6);
+ /* MONO_LOP/M not fully powered up */
+ aic3x_change_reg(AIC3X_MONO_LOP_M_LVL, 0x00, 0xFE);
/* HPLOUT fully powered up */
aic3x_change_reg(AIC3X_HPLOUT_LVL, 0x01, 0xFF);
/* HPROUT fully powered up */
@@ -316,8 +316,8 @@ void aic3x_switch_output(bool stereo)
}
else
{
- /* MONO_LOP/M not muted */
- aic3x_change_reg(AIC3X_MONO_LOP_M_LVL, 0x09, 0xFF);
+ /* MONO_LOP/M fully powered up */
+ aic3x_change_reg(AIC3X_MONO_LOP_M_LVL, 0x01, 0xFF);
/* HPLOUT not fully powered up */
aic3x_change_reg(AIC3X_HPLOUT_LVL, 0x00, 0xFE);
/* HPROUT not fully powered up */
diff --git a/firmware/drivers/audio/ak4376.c b/firmware/drivers/audio/ak4376.c
index 494bbabfa4..11714b210d 100644
--- a/firmware/drivers/audio/ak4376.c
+++ b/firmware/drivers/audio/ak4376.c
@@ -27,6 +27,18 @@
#include "system.h"
#include "i2c-async.h"
+/* sample rates supported by the hardware */
+#define CAPS (SAMPR_CAP_192 | SAMPR_CAP_176 | \
+ SAMPR_CAP_96 | SAMPR_CAP_88 | SAMPR_CAP_64 | \
+ SAMPR_CAP_48 | SAMPR_CAP_44 | SAMPR_CAP_32 | \
+ SAMPR_CAP_24 | SAMPR_CAP_22 | SAMPR_CAP_16 | \
+ SAMPR_CAP_12 | SAMPR_CAP_11 | SAMPR_CAP_8)
+
+/* future proofing */
+#if (HW_SAMPR_CAPS & ~CAPS) != 0
+# error "incorrect HW_SAMPR_CAPS"
+#endif
+
#ifndef HAVE_SW_VOLUME_CONTROL
# error "AK4376 requires HAVE_SW_VOLUME_CONTROL!"
#endif
@@ -40,7 +52,7 @@
*/
/* Converts HW_FREQ_XX constants to register values */
-static const int ak4376_fsel_to_hw[] = {
+static const uint8_t ak4376_fsel_to_hw[] = {
HW_HAVE_192_(AK4376_FS_192,)
HW_HAVE_176_(AK4376_FS_176,)
HW_HAVE_96_(AK4376_FS_96,)
@@ -57,19 +69,13 @@ static const int ak4376_fsel_to_hw[] = {
HW_HAVE_8_(AK4376_FS_8,)
};
-static struct ak4376 {
- int fsel;
- int low_mode;
- int regs[AK4376_NUM_REGS];
-} ak4376;
+static int ak4376_regs[AK4376_NUM_REGS];
-void ak4376_init(void)
+void ak4376_open(void)
{
/* Initialize DAC state */
- ak4376.fsel = HW_FREQ_48;
- ak4376.low_mode = 0;
for(int i = 0; i < AK4376_NUM_REGS; ++i)
- ak4376.regs[i] = -1;
+ ak4376_regs[i] = -1;
/* Initial reset after power-on */
ak4376_set_pdn_pin(0);
@@ -102,9 +108,6 @@ void ak4376_init(void)
/* Write initial configuration prior to power-up */
for(size_t i = 0; i < ARRAYLEN(init_config); i += 2)
ak4376_write(init_config[i], init_config[i+1]);
-
- /* Initial frequency setting, also handles DAC/amp power-up */
- audiohw_set_frequency(HW_FREQ_48);
}
void ak4376_close(void)
@@ -121,22 +124,22 @@ void ak4376_close(void)
void ak4376_write(int reg, int value)
{
/* Ensure value is sensible and differs from the last set value */
- if((value & 0xff) == value && ak4376.regs[reg] != value) {
+ if((value & 0xff) == value && ak4376_regs[reg] != value) {
int r = i2c_reg_write1(AK4376_BUS, AK4376_ADDR, reg, value);
if(r == I2C_STATUS_OK)
- ak4376.regs[reg] = value;
+ ak4376_regs[reg] = value;
else
- ak4376.regs[reg] = -1;
+ ak4376_regs[reg] = -1;
}
}
int ak4376_read(int reg)
{
/* Only read from I2C if we don't already know the value */
- if(ak4376.regs[reg] < 0)
- ak4376.regs[reg] = i2c_reg_read1(AK4376_BUS, AK4376_ADDR, reg);
+ if(ak4376_regs[reg] < 0)
+ ak4376_regs[reg] = i2c_reg_read1(AK4376_BUS, AK4376_ADDR, reg);
- return ak4376.regs[reg];
+ return ak4376_regs[reg];
}
static int round_step_up(int x, int step)
@@ -180,7 +183,7 @@ static int amp_vol_to_hw(int vol)
return (vol - AK4376_AMP_VOLUME_MIN) / AK4376_AMP_VOLUME_STEP + 1;
}
-void audiohw_set_volume(int vol_l, int vol_r)
+void ak4376_set_volume(int vol_l, int vol_r)
{
int amp;
int mix_l = AK4376_MIX_LCH, dig_l, sw_l;
@@ -210,7 +213,7 @@ void audiohw_set_volume(int vol_l, int vol_r)
pcm_set_master_volume(sw_l, sw_r);
}
-void audiohw_set_filter_roll_off(int val)
+void ak4376_set_filter_roll_off(int val)
{
int reg = ak4376_read(AK4376_REG_FILTER);
reg &= ~0xc0;
@@ -218,11 +221,8 @@ void audiohw_set_filter_roll_off(int val)
ak4376_write(AK4376_REG_FILTER, reg);
}
-void audiohw_set_frequency(int fsel)
+void ak4376_set_freqmode(int fsel, int mult, int power_mode)
{
- /* Determine master clock multiplier */
- int mult = ak4376_set_mclk_freq(fsel, false);
-
/* Calculate clock mode for frequency. Multipliers of 32/64 are only
* for rates >= 256 KHz which are not supported by Rockbox, so they
* are commented out -- but they're in the correct place. */
@@ -248,27 +248,11 @@ void audiohw_set_frequency(int fsel)
/* Handle the DSMLP bit in the MODE_CTRL register */
int mode_ctrl = 0x00;
- if(ak4376.low_mode || hw_freq_sampr[fsel] <= SAMPR_12)
+ if(power_mode || hw_freq_sampr[fsel] <= SAMPR_12)
mode_ctrl |= 0x40;
/* Program the new settings */
ak4376_write(AK4376_REG_CLOCK_MODE, clock_mode);
ak4376_write(AK4376_REG_MODE_CTRL, mode_ctrl);
- ak4376_write(AK4376_REG_PWR3, ak4376.low_mode ? 0x11 : 0x01);
-
- /* Enable the master clock */
- ak4376_set_mclk_freq(fsel, true);
-
- /* Remember the frequency */
- ak4376.fsel = fsel;
-}
-
-void audiohw_set_power_mode(int mode)
-{
- /* This is handled via audiohw_set_frequency() since changing LPMODE
- * bit requires power-down/power-up & changing other bits as well */
- if(ak4376.low_mode != mode) {
- ak4376.low_mode = mode;
- audiohw_set_frequency(ak4376.fsel);
- }
+ ak4376_write(AK4376_REG_PWR3, power_mode ? 0x11 : 0x01);
}
diff --git a/firmware/drivers/axp-pmu.c b/firmware/drivers/axp-pmu.c
new file mode 100644
index 0000000000..fd1126dbbf
--- /dev/null
+++ b/firmware/drivers/axp-pmu.c
@@ -0,0 +1,670 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2021 Aidan MacDonald
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "axp-pmu.h"
+#include "power.h"
+#include "system.h"
+#include "i2c-async.h"
+#include <string.h>
+
+/* Headers for the debug menu */
+#ifndef BOOTLOADER
+# include "action.h"
+# include "list.h"
+# include <stdio.h>
+#endif
+
+struct axp_adc_info {
+ uint8_t reg;
+ uint8_t en_reg;
+ uint8_t en_bit;
+};
+
+struct axp_supply_info {
+ uint8_t volt_reg;
+ uint8_t volt_reg_mask;
+ uint8_t en_reg;
+ uint8_t en_bit;
+ int min_mV;
+ int max_mV;
+ int step_mV;
+};
+
+static const struct axp_adc_info axp_adc_info[NUM_ADC_CHANNELS] = {
+ {0x56, AXP_REG_ADCENABLE1, 5}, /* ACIN_VOLTAGE */
+ {0x58, AXP_REG_ADCENABLE1, 4}, /* ACIN_CURRENT */
+ {0x5a, AXP_REG_ADCENABLE1, 3}, /* VBUS_VOLTAGE */
+ {0x5c, AXP_REG_ADCENABLE1, 2}, /* VBUS_CURRENT */
+ {0x5e, AXP_REG_ADCENABLE2, 7}, /* INTERNAL_TEMP */
+ {0x62, AXP_REG_ADCENABLE1, 1}, /* TS_INPUT */
+ {0x78, AXP_REG_ADCENABLE1, 7}, /* BATTERY_VOLTAGE */
+ {0x7a, AXP_REG_ADCENABLE1, 6}, /* CHARGE_CURRENT */
+ {0x7c, AXP_REG_ADCENABLE1, 6}, /* DISCHARGE_CURRENT */
+ {0x7e, AXP_REG_ADCENABLE1, 1}, /* APS_VOLTAGE */
+ {0x70, 0xff, 0}, /* BATTERY_POWER */
+};
+
+static const struct axp_supply_info axp_supply_info[AXP_NUM_SUPPLIES] = {
+#if HAVE_AXP_PMU == 192
+ [AXP_SUPPLY_DCDC1] = {
+ .volt_reg = 0x26,
+ .volt_reg_mask = 0x7f,
+ .en_reg = 0x12,
+ .en_bit = 0,
+ .min_mV = 700,
+ .max_mV = 3500,
+ .step_mV = 25,
+ },
+ [AXP_SUPPLY_DCDC2] = {
+ .volt_reg = 0x23,
+ .volt_reg_mask = 0x3f,
+ .en_reg = 0x10,
+ .en_bit = 0,
+ .min_mV = 700,
+ .max_mV = 2275,
+ .step_mV = 25,
+ },
+ [AXP_SUPPLY_DCDC3] = {
+ .volt_reg = 0x27,
+ .volt_reg_mask = 0x7f,
+ .en_reg = 0x12,
+ .en_bit = 1,
+ .min_mV = 700,
+ .max_mV = 3500,
+ .step_mV = 25,
+ },
+ /*
+ * NOTE: LDO1 is always on, and we can't query it or change voltages
+ */
+ [AXP_SUPPLY_LDO2] = {
+ .volt_reg = 0x28,
+ .volt_reg_mask = 0xf0,
+ .en_reg = 0x12,
+ .en_bit = 2,
+ .min_mV = 1800,
+ .max_mV = 3300,
+ .step_mV = 100,
+ },
+ [AXP_SUPPLY_LDO3] = {
+ .volt_reg = 0x28,
+ .volt_reg_mask = 0x0f,
+ .en_reg = 0x12,
+ .en_bit = 3,
+ .min_mV = 1800,
+ .max_mV = 3300,
+ .step_mV = 100,
+ },
+ [AXP_SUPPLY_LDO_IO0] = {
+ .volt_reg = 0x91,
+ .volt_reg_mask = 0xf0,
+ .en_reg = 0x90,
+ .en_bit = 0xff, /* this one requires special handling */
+ .min_mV = 1800,
+ .max_mV = 3300,
+ .step_mV = 100,
+ },
+#else
+# error "Untested AXP chip"
+#endif
+};
+
+static struct axp_driver {
+ int adc_enable;
+ int chargecurrent_setting;
+ int chip_id;
+} axp;
+
+static void axp_init_enabled_adcs(void)
+{
+ axp.adc_enable = 0;
+
+ /* Read chip ID, so we can display it on the debug screen.
+ * This is undocumented but there's Linux driver code floating around
+ * which suggests this should work for many AXP chips. */
+ axp.chip_id = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_CHIP_ID);
+
+ /* Read enabled ADCs from the hardware */
+ uint8_t regs[2];
+ int rc = i2c_reg_read(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_ADCENABLE1, 2, &regs[0]);
+ if(rc != I2C_STATUS_OK)
+ return;
+
+ /* Parse registers to set ADC enable bits */
+ const struct axp_adc_info* info = axp_adc_info;
+ for(int i = 0; i < NUM_ADC_CHANNELS; ++i) {
+ if(info[i].en_reg == 0xff)
+ continue;
+
+ if(regs[info[i].en_reg - AXP_REG_ADCENABLE1] & info[i].en_bit)
+ axp.adc_enable |= 1 << i;
+ }
+
+ /* Handle battery power ADC */
+ if((axp.adc_enable & (1 << ADC_BATTERY_VOLTAGE)) &&
+ (axp.adc_enable & (1 << ADC_DISCHARGE_CURRENT))) {
+ axp.adc_enable |= (1 << ADC_BATTERY_POWER);
+ }
+}
+
+void axp_init(void)
+{
+ axp_init_enabled_adcs();
+
+ /* We need discharge current ADC to reliably poll for a full battery */
+ int bits = axp.adc_enable;
+ bits |= (1 << ADC_DISCHARGE_CURRENT);
+ axp_adc_set_enabled(bits);
+
+ /* Read the maximum charging current */
+ int value = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_CHARGECONTROL1);
+ axp.chargecurrent_setting = (value < 0) ? -1 : (value & 0xf);
+}
+
+void axp_supply_set_voltage(int supply, int voltage)
+{
+ const struct axp_supply_info* info = &axp_supply_info[supply];
+ if(info->volt_reg == 0 || info->volt_reg_mask == 0)
+ return;
+
+ if(voltage > 0 && info->step_mV != 0) {
+ if(voltage < info->min_mV || voltage > info->max_mV)
+ return;
+
+ int regval = (voltage - info->min_mV) / info->step_mV;
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, info->volt_reg,
+ info->volt_reg_mask, regval, NULL);
+ }
+
+ if(info->en_bit != 0xff) {
+ i2c_reg_setbit1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ info->en_reg, info->en_bit,
+ voltage > 0 ? 1 : 0, NULL);
+ }
+}
+
+int axp_supply_get_voltage(int supply)
+{
+ const struct axp_supply_info* info = &axp_supply_info[supply];
+ if(info->volt_reg == 0)
+ return AXP_SUPPLY_NOT_PRESENT;
+
+ if(info->en_reg != 0) {
+ int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, info->en_reg);
+ if(r < 0)
+ return AXP_SUPPLY_DISABLED;
+
+#if HAVE_AXP_PMU == 192
+ if(supply == AXP_SUPPLY_LDO_IO0) {
+ if((r & 7) != 2)
+ return AXP_SUPPLY_DISABLED;
+ } else
+#endif
+ {
+ if(r & (1 << info->en_bit) == 0)
+ return AXP_SUPPLY_DISABLED;
+ }
+ }
+
+ /* Hack, avoid undefined shift below. Can be useful too... */
+ if(info->volt_reg_mask == 0)
+ return info->min_mV;
+
+ int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, info->volt_reg);
+ if(r < 0)
+ return 0;
+
+ int bit = find_first_set_bit(info->volt_reg_mask);
+ int val = (r & info->volt_reg_mask) >> bit;
+ return info->min_mV + (val * info->step_mV);
+}
+
+/* TODO: this can STILL indicate some false positives! */
+int axp_battery_status(void)
+{
+ int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_POWERSTATUS);
+ if(r >= 0) {
+ /* Charging bit indicates we're currently charging */
+ if((r & 0x04) != 0)
+ return AXP_BATT_CHARGING;
+
+ /* Not plugged in means we're discharging */
+ if((r & 0xf0) == 0)
+ return AXP_BATT_DISCHARGING;
+ } else {
+ /* Report discharging if we can't find out power status */
+ return AXP_BATT_DISCHARGING;
+ }
+
+ /* If the battery is full and not in use, the charging bit will be 0,
+ * there will be an external power source, AND the discharge current
+ * will be zero. Seems to rule out all false positives. */
+ int d = axp_adc_read_raw(ADC_DISCHARGE_CURRENT);
+ if(d == 0)
+ return AXP_BATT_FULL;
+
+ return AXP_BATT_DISCHARGING;
+}
+
+int axp_input_status(void)
+{
+#ifdef HAVE_BATTERY_SWITCH
+ int input_status = 0;
+#else
+ int input_status = AXP_INPUT_BATTERY;
+#endif
+
+ int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_POWERSTATUS);
+ if(r < 0)
+ return input_status;
+
+ /* Check for AC input */
+ if(r & 0x80)
+ input_status |= AXP_INPUT_AC;
+
+ /* Only report USB if ACIN and VBUS are not shorted */
+ if((r & 0x20) != 0 && (r & 0x02) == 0)
+ input_status |= AXP_INPUT_USB;
+
+#ifdef HAVE_BATTERY_SWITCH
+ /* Check for battery presence if target defines it as removable */
+ r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_CHARGESTATUS);
+ if(r >= 0 && (r & 0x20) != 0)
+ input_status |= AXP_INPUT_BATTERY;
+#endif
+
+ return input_status;
+}
+
+int axp_adc_read(int adc)
+{
+ int value = axp_adc_read_raw(adc);
+ if(value == INT_MIN)
+ return INT_MIN;
+
+ return axp_adc_conv_raw(adc, value);
+}
+
+int axp_adc_read_raw(int adc)
+{
+ /* Don't give a reading if the ADC is not enabled */
+ if((axp.adc_enable & (1 << adc)) == 0)
+ return INT_MIN;
+
+ /* Read the ADC */
+ uint8_t buf[3];
+ int count = (adc == ADC_BATTERY_POWER) ? 3 : 2;
+ uint8_t reg = axp_adc_info[adc].reg;
+ int rc = i2c_reg_read(AXP_PMU_BUS, AXP_PMU_ADDR, reg, count, &buf[0]);
+ if(rc != I2C_STATUS_OK)
+ return INT_MIN;
+
+ /* Parse the value */
+ if(adc == ADC_BATTERY_POWER)
+ return (buf[0] << 16) | (buf[1] << 8) | buf[2];
+ else if(adc == ADC_CHARGE_CURRENT || adc == ADC_DISCHARGE_CURRENT)
+ return (buf[0] << 5) | (buf[1] & 0x1f);
+ else
+ return (buf[0] << 4) | (buf[1] & 0xf);
+}
+
+int axp_adc_conv_raw(int adc, int value)
+{
+ switch(adc) {
+ case ADC_ACIN_VOLTAGE:
+ case ADC_VBUS_VOLTAGE:
+ /* 0 mV ... 6.9615 mV, step 1.7 mV */
+ return value * 17 / 10;
+ case ADC_ACIN_CURRENT:
+ /* 0 mA ... 2.5594 A, step 0.625 mA */
+ return value * 5 / 8;
+ case ADC_VBUS_CURRENT:
+ /* 0 mA ... 1.5356 A, step 0.375 mA */
+ return value * 3 / 8;
+ case ADC_INTERNAL_TEMP:
+ /* -144.7 C ... 264.8 C, step 0.1 C */
+ return value - 1447;
+ case ADC_TS_INPUT:
+ /* 0 mV ... 3.276 V, step 0.8 mV */
+ return value * 4 / 5;
+ case ADC_BATTERY_VOLTAGE:
+ /* 0 mV ... 4.5045 V, step 1.1 mV */
+ return value * 11 / 10;
+ case ADC_CHARGE_CURRENT:
+ case ADC_DISCHARGE_CURRENT:
+ /* 0 mA to 4.095 A, step 0.5 mA */
+ return value / 2;
+ case ADC_APS_VOLTAGE:
+ /* 0 mV to 5.733 V, step 1.4 mV */
+ return value * 7 / 5;
+ case ADC_BATTERY_POWER:
+ /* 0 uW to 23.6404 W, step 0.55 uW */
+ return value * 11 / 20;
+ default:
+ /* Shouldn't happen */
+ return INT_MIN;
+ }
+}
+
+int axp_adc_get_enabled(void)
+{
+ return axp.adc_enable;
+}
+
+void axp_adc_set_enabled(int adc_bits)
+{
+ /* Ignore no-op */
+ if(adc_bits == axp.adc_enable)
+ return;
+
+ /* Compute the new register values */
+ const struct axp_adc_info* info = axp_adc_info;
+ uint8_t regs[2] = {0, 0};
+ for(int i = 0; i < NUM_ADC_CHANNELS; ++i) {
+ if(info[i].en_reg == 0xff)
+ continue;
+
+ if(adc_bits & (1 << i))
+ regs[info[i].en_reg - 0x82] |= 1 << info[i].en_bit;
+ }
+
+ /* These ADCs share an enable bit */
+ if(adc_bits & ((1 << ADC_CHARGE_CURRENT)|(1 << ADC_DISCHARGE_CURRENT))) {
+ adc_bits |= (1 << ADC_CHARGE_CURRENT);
+ adc_bits |= (1 << ADC_DISCHARGE_CURRENT);
+ }
+
+ /* Enable required bits for battery power ADC */
+ if(adc_bits & (1 << ADC_BATTERY_POWER)) {
+ regs[0] |= 1 << info[ADC_DISCHARGE_CURRENT].en_bit;
+ regs[0] |= 1 << info[ADC_BATTERY_VOLTAGE].en_bit;
+ }
+
+ /* Update the configuration */
+ i2c_reg_write(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_ADCENABLE1, 2, &regs[0]);
+ axp.adc_enable = adc_bits;
+}
+
+int axp_adc_get_rate(void)
+{
+ int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_ADCSAMPLERATE);
+ if(r < 0)
+ return AXP_ADC_RATE_100HZ; /* an arbitrary value */
+
+ return (r >> 6) & 3;
+}
+
+void axp_adc_set_rate(int rate)
+{
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP_REG_ADCSAMPLERATE,
+ 0xc0, (rate & 3) << 6, NULL);
+}
+
+static uint32_t axp_cc_parse(const uint8_t* buf)
+{
+ return ((uint32_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
+}
+
+void axp_cc_read(uint32_t* charge, uint32_t* discharge)
+{
+ uint8_t buf[8];
+ int rc = i2c_reg_read(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_COULOMBCOUNTERBASE, 8, &buf[0]);
+ if(rc != I2C_STATUS_OK) {
+ if(charge)
+ *charge = 0;
+ if(discharge)
+ *discharge = 0;
+ return;
+ }
+
+ if(charge)
+ *charge = axp_cc_parse(&buf[0]);
+ if(discharge)
+ *discharge = axp_cc_parse(&buf[4]);
+}
+
+void axp_cc_clear(void)
+{
+ i2c_reg_setbit1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_COULOMBCOUNTERCTRL, 5, 1, NULL);
+}
+
+void axp_cc_enable(bool en)
+{
+ i2c_reg_setbit1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_COULOMBCOUNTERCTRL, 7, en ? 1 : 0, NULL);
+}
+
+bool axp_cc_is_enabled(void)
+{
+ int reg = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_COULOMBCOUNTERCTRL);
+ return reg >= 0 && (reg & 0x40) != 0;
+}
+
+static const int chargecurrent_tbl[] = {
+ 100, 190, 280, 360,
+ 450, 550, 630, 700,
+ 780, 880, 960, 1000,
+ 1080, 1160, 1240, 1320,
+};
+
+static const int chargecurrent_tblsz = sizeof(chargecurrent_tbl)/sizeof(int);
+
+void axp_set_charge_current(int maxcurrent)
+{
+ /* Find the charge current just higher than maxcurrent */
+ int value = 0;
+ while(value < chargecurrent_tblsz &&
+ chargecurrent_tbl[value] <= maxcurrent)
+ ++value;
+
+ /* Select the next lower current, the greatest current <= maxcurrent */
+ if(value >= chargecurrent_tblsz)
+ value = chargecurrent_tblsz - 1;
+ else if(value > 0)
+ --value;
+
+ /* Don't issue i2c write if desired setting is already in use */
+ if(value == axp.chargecurrent_setting)
+ return;
+
+ /* Update register */
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_CHARGECONTROL1, 0x0f, value, NULL);
+ axp.chargecurrent_setting = value;
+}
+
+int axp_get_charge_current(void)
+{
+ if(axp.chargecurrent_setting < 0)
+ return chargecurrent_tbl[0];
+ else
+ return chargecurrent_tbl[axp.chargecurrent_setting];
+}
+
+void axp_power_off(void)
+{
+ /* Set the shutdown bit */
+ i2c_reg_setbit1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_SHUTDOWNLEDCTRL, 7, 1, NULL);
+}
+
+#ifndef BOOTLOADER
+enum {
+ AXP_DEBUG_CHIP_ID,
+ AXP_DEBUG_BATTERY_STATUS,
+ AXP_DEBUG_INPUT_STATUS,
+ AXP_DEBUG_CHARGE_CURRENT,
+ AXP_DEBUG_COULOMB_COUNTERS,
+ AXP_DEBUG_ADC_RATE,
+ AXP_DEBUG_FIRST_ADC,
+ AXP_DEBUG_FIRST_SUPPLY = AXP_DEBUG_FIRST_ADC + NUM_ADC_CHANNELS,
+ AXP_DEBUG_NUM_ENTRIES = AXP_DEBUG_FIRST_SUPPLY + AXP_NUM_SUPPLIES,
+};
+
+static int axp_debug_menu_cb(int action, struct gui_synclist* lists)
+{
+ (void)lists;
+
+ if(action == ACTION_NONE)
+ action = ACTION_REDRAW;
+
+ return action;
+}
+
+static const char* axp_debug_menu_get_name(int item, void* data,
+ char* buf, size_t buflen)
+{
+ (void)data;
+
+ static const char* const adc_names[] = {
+ "V_acin", "I_acin", "V_vbus", "I_vbus", "T_int",
+ "V_ts", "V_batt", "I_chrg", "I_dchg", "V_aps", "P_batt"
+ };
+
+ static const char* const adc_units[] = {
+ "mV", "mA", "mV", "mA", "C", "mV", "mV", "mA", "mA", "mV", "uW",
+ };
+
+ static const char* const supply_names[] = {
+ "DCDC1", "DCDC2", "DCDC3",
+ "LDO1", "LDO2", "LDO3", "LDO_IO0",
+ };
+
+ int adc = item - AXP_DEBUG_FIRST_ADC;
+ if(item >= AXP_DEBUG_FIRST_ADC && adc < NUM_ADC_CHANNELS) {
+ int raw_value = axp_adc_read_raw(adc);
+ if(raw_value == INT_MIN) {
+ snprintf(buf, buflen, "%s: [Disabled]", adc_names[adc]);
+ return buf;
+ }
+
+ int value = axp_adc_conv_raw(adc, raw_value);
+ if(adc == ADC_INTERNAL_TEMP) {
+ snprintf(buf, buflen, "%s: %d.%d %s", adc_names[adc],
+ value/10, value%10, adc_units[adc]);
+ } else {
+ snprintf(buf, buflen, "%s: %d %s", adc_names[adc],
+ value, adc_units[adc]);
+ }
+
+ return buf;
+ }
+
+ int supply = item - AXP_DEBUG_FIRST_SUPPLY;
+ if(item >= AXP_DEBUG_FIRST_SUPPLY && supply < AXP_NUM_SUPPLIES) {
+ int voltage = axp_supply_get_voltage(supply);
+ if(voltage == AXP_SUPPLY_NOT_PRESENT)
+ snprintf(buf, buflen, "%s: [Not Present]", supply_names[supply]);
+ else if(voltage == AXP_SUPPLY_DISABLED)
+ snprintf(buf, buflen, "%s: [Disabled]", supply_names[supply]);
+ else
+ snprintf(buf, buflen, "%s: %d mV", supply_names[supply], voltage);
+
+ return buf;
+ }
+
+ switch(item) {
+ case AXP_DEBUG_CHIP_ID: {
+ snprintf(buf, buflen, "Chip ID: %d (%02x) [Driver: AXP%d]",
+ axp.chip_id, axp.chip_id, HAVE_AXP_PMU);
+ return buf;
+ } break;
+
+ case AXP_DEBUG_BATTERY_STATUS: {
+ switch(axp_battery_status()) {
+ case AXP_BATT_FULL:
+ return "Battery: Full";
+ case AXP_BATT_CHARGING:
+ return "Battery: Charging";
+ case AXP_BATT_DISCHARGING:
+ return "Battery: Discharging";
+ default:
+ return "Battery: Unknown";
+ }
+ } break;
+
+ case AXP_DEBUG_INPUT_STATUS: {
+ int s = axp_input_status();
+ const char* ac = (s & AXP_INPUT_AC) ? " AC" : "";
+ const char* usb = (s & AXP_INPUT_USB) ? " USB" : "";
+ const char* batt = (s & AXP_INPUT_BATTERY) ? " Battery" : "";
+ snprintf(buf, buflen, "Inputs:%s%s%s", ac, usb, batt);
+ return buf;
+ } break;
+
+ case AXP_DEBUG_CHARGE_CURRENT: {
+ int current = axp_get_charge_current();
+ snprintf(buf, buflen, "Max charge current: %d mA", current);
+ return buf;
+ } break;
+
+ case AXP_DEBUG_COULOMB_COUNTERS: {
+ uint32_t charge, discharge;
+ axp_cc_read(&charge, &discharge);
+
+ snprintf(buf, buflen, "Coulomb counters: +%lu / -%lu",
+ (unsigned long)charge, (unsigned long)discharge);
+ return buf;
+ } break;
+
+ case AXP_DEBUG_ADC_RATE: {
+ int rate = 25 << axp_adc_get_rate();
+ snprintf(buf, buflen, "ADC sample rate: %d Hz", rate);
+ return buf;
+ } break;
+
+ default:
+ return "---";
+ }
+}
+
+bool axp_debug_menu(void)
+{
+ struct simplelist_info info;
+ simplelist_info_init(&info, "AXP debug", AXP_DEBUG_NUM_ENTRIES, NULL);
+ info.action_callback = axp_debug_menu_cb;
+ info.get_name = axp_debug_menu_get_name;
+ return simplelist_show_list(&info);
+}
+#endif /* !BOOTLOADER */
+
+/* This is basically the only valid implementation, so define it here */
+unsigned int power_input_status(void)
+{
+ unsigned int state = 0;
+ int input_status = axp_input_status();
+
+ if(input_status & AXP_INPUT_AC)
+ state |= POWER_INPUT_MAIN_CHARGER;
+
+ if(input_status & AXP_INPUT_USB)
+ state |= POWER_INPUT_USB_CHARGER;
+
+#ifdef HAVE_BATTERY_SWITCH
+ if(input_status & AXP_INPUT_BATTERY)
+ state |= POWER_INPUT_BATTERY;
+#endif
+
+ return state;
+}
diff --git a/firmware/drivers/axp173.c b/firmware/drivers/axp173.c
deleted file mode 100644
index 22417650fc..0000000000
--- a/firmware/drivers/axp173.c
+++ /dev/null
@@ -1,419 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2021 Aidan MacDonald
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "axp173.h"
-#include "power.h"
-#include "i2c-async.h"
-
-/* Headers for the debug menu */
-#ifndef BOOTLOADER
-# include "action.h"
-# include "list.h"
-# include <stdio.h>
-#endif
-
-static const struct axp173_adc_info {
- uint8_t reg;
- uint8_t en_reg;
- uint8_t en_bit;
-} axp173_adc_info[NUM_ADC_CHANNELS] = {
- {0x56, 0x82, 5}, /* ACIN_VOLTAGE */
- {0x58, 0x82, 4}, /* ACIN_CURRENT */
- {0x5a, 0x82, 3}, /* VBUS_VOLTAGE */
- {0x5c, 0x82, 2}, /* VBUS_CURRENT */
- {0x5e, 0x83, 7}, /* INTERNAL_TEMP */
- {0x62, 0x82, 1}, /* TS_INPUT */
- {0x78, 0x82, 7}, /* BATTERY_VOLTAGE */
- {0x7a, 0x82, 6}, /* CHARGE_CURRENT */
- {0x7c, 0x82, 6}, /* DISCHARGE_CURRENT */
- {0x7e, 0x82, 1}, /* APS_VOLTAGE */
- {0x70, 0xff, 0}, /* BATTERY_POWER */
-};
-
-static struct axp173 {
- int adc_enable;
-} axp173;
-
-static void axp173_init_enabled_adcs(void)
-{
- axp173.adc_enable = 0;
-
- /* Read enabled ADCs from the hardware */
- uint8_t regs[2];
- int rc = i2c_reg_read(AXP173_BUS, AXP173_ADDR, 0x82, 2, &regs[0]);
- if(rc != I2C_STATUS_OK)
- return;
-
- /* Parse registers to set ADC enable bits */
- const struct axp173_adc_info* info = axp173_adc_info;
- for(int i = 0; i < NUM_ADC_CHANNELS; ++i) {
- if(info[i].en_reg == 0xff)
- continue;
-
- if(regs[info[i].en_reg - 0x82] & info[i].en_bit)
- axp173.adc_enable |= 1 << i;
- }
-
- /* Handle battery power ADC */
- if((axp173.adc_enable & (1 << ADC_BATTERY_VOLTAGE)) &&
- (axp173.adc_enable & (1 << ADC_DISCHARGE_CURRENT))) {
- axp173.adc_enable |= (1 << ADC_BATTERY_POWER);
- }
-}
-
-void axp173_init(void)
-{
- axp173_init_enabled_adcs();
-
- /* We need discharge current ADC to reliably poll for a full battery */
- int bits = axp173.adc_enable;
- bits |= (1 << ADC_DISCHARGE_CURRENT);
- axp173_adc_set_enabled(bits);
-}
-
-/* TODO: this can STILL indicate some false positives! */
-int axp173_battery_status(void)
-{
- int r = i2c_reg_read1(AXP173_BUS, AXP173_ADDR, 0x00);
- if(r >= 0) {
- /* Charging bit indicates we're currently charging */
- if((r & 0x04) != 0)
- return AXP173_BATT_CHARGING;
-
- /* Not plugged in means we're discharging */
- if((r & 0xf0) == 0)
- return AXP173_BATT_DISCHARGING;
- } else {
- /* Report discharging if we can't find out power status */
- return AXP173_BATT_DISCHARGING;
- }
-
- /* If the battery is full and not in use, the charging bit will be 0,
- * there will be an external power source, AND the discharge current
- * will be zero. Seems to rule out all false positives. */
- int d = axp173_adc_read_raw(ADC_DISCHARGE_CURRENT);
- if(d == 0)
- return AXP173_BATT_FULL;
-
- return AXP173_BATT_DISCHARGING;
-}
-
-int axp173_input_status(void)
-{
-#ifdef HAVE_BATTERY_SWITCH
- int input_status = 0;
-#else
- int input_status = AXP173_INPUT_BATTERY;
-#endif
-
- int r = i2c_reg_read1(AXP173_BUS, AXP173_ADDR, 0x00);
- if(r < 0)
- return input_status;
-
- /* Check for AC input */
- if(r & 0x80)
- input_status |= AXP173_INPUT_AC;
-
- /* Only report USB if ACIN and VBUS are not shorted */
- if((r & 0x20) != 0 && (r & 0x02) == 0)
- input_status |= AXP173_INPUT_USB;
-
-#ifdef HAVE_BATTERY_SWITCH
- /* Check for battery presence if target defines it as removable */
- r = i2c_reg_read1(AXP173_BUS, AXP173_ADDR, 0x01);
- if(r >= 0 && (r & 0x20) != 0)
- input_status |= AXP173_INPUT_BATTERY;
-#endif
-
- return input_status;
-}
-
-int axp173_adc_read(int adc)
-{
- int value = axp173_adc_read_raw(adc);
- if(value == INT_MIN)
- return INT_MIN;
-
- return axp173_adc_conv_raw(adc, value);
-}
-
-int axp173_adc_read_raw(int adc)
-{
- /* Don't give a reading if the ADC is not enabled */
- if((axp173.adc_enable & (1 << adc)) == 0)
- return INT_MIN;
-
- /* Read the ADC */
- uint8_t buf[3];
- int count = (adc == ADC_BATTERY_POWER) ? 3 : 2;
- uint8_t reg = axp173_adc_info[adc].reg;
- int rc = i2c_reg_read(AXP173_BUS, AXP173_ADDR, reg, count, &buf[0]);
- if(rc != I2C_STATUS_OK)
- return INT_MIN;
-
- /* Parse the value */
- if(adc == ADC_BATTERY_POWER)
- return (buf[0] << 16) | (buf[1] << 8) | buf[2];
- else if(adc == ADC_CHARGE_CURRENT || adc == ADC_DISCHARGE_CURRENT)
- return (buf[0] << 5) | (buf[1] & 0x1f);
- else
- return (buf[0] << 4) | (buf[1] & 0xf);
-}
-
-int axp173_adc_conv_raw(int adc, int value)
-{
- switch(adc) {
- case ADC_ACIN_VOLTAGE:
- case ADC_VBUS_VOLTAGE:
- /* 0 mV ... 6.9615 mV, step 1.7 mV */
- return value * 17 / 10;
- case ADC_ACIN_CURRENT:
- /* 0 mA ... 2.5594 A, step 0.625 mA */
- return value * 5 / 8;
- case ADC_VBUS_CURRENT:
- /* 0 mA ... 1.5356 A, step 0.375 mA */
- return value * 3 / 8;
- case ADC_INTERNAL_TEMP:
- /* -144.7 C ... 264.8 C, step 0.1 C */
- return value - 1447;
- case ADC_TS_INPUT:
- /* 0 mV ... 3.276 V, step 0.8 mV */
- return value * 4 / 5;
- case ADC_BATTERY_VOLTAGE:
- /* 0 mV ... 4.5045 V, step 1.1 mV */
- return value * 11 / 10;
- case ADC_CHARGE_CURRENT:
- case ADC_DISCHARGE_CURRENT:
- /* 0 mA to 4.095 A, step 0.5 mA */
- return value / 2;
- case ADC_APS_VOLTAGE:
- /* 0 mV to 5.733 V, step 1.4 mV */
- return value * 7 / 5;
- case ADC_BATTERY_POWER:
- /* 0 uW to 23.6404 W, step 0.55 uW */
- return value * 11 / 20;
- default:
- /* Shouldn't happen */
- return INT_MIN;
- }
-}
-
-int axp173_adc_get_enabled(void)
-{
- return axp173.adc_enable;
-}
-
-void axp173_adc_set_enabled(int adc_bits)
-{
- /* Ignore no-op */
- if(adc_bits == axp173.adc_enable)
- return;
-
- /* Compute the new register values */
- const struct axp173_adc_info* info = axp173_adc_info;
- uint8_t regs[2] = {0, 0};
- for(int i = 0; i < NUM_ADC_CHANNELS; ++i) {
- if(info[i].en_reg == 0xff)
- continue;
-
- if(adc_bits & (1 << i))
- regs[info[i].en_reg - 0x82] |= 1 << info[i].en_bit;
- }
-
- /* These ADCs share an enable bit */
- if(adc_bits & ((1 << ADC_CHARGE_CURRENT)|(1 << ADC_DISCHARGE_CURRENT))) {
- adc_bits |= (1 << ADC_CHARGE_CURRENT);
- adc_bits |= (1 << ADC_DISCHARGE_CURRENT);
- }
-
- /* Enable required bits for battery power ADC */
- if(adc_bits & (1 << ADC_BATTERY_POWER)) {
- regs[0] |= 1 << info[ADC_DISCHARGE_CURRENT].en_bit;
- regs[0] |= 1 << info[ADC_BATTERY_VOLTAGE].en_bit;
- }
-
- /* Update the configuration */
- i2c_reg_write(AXP173_BUS, AXP173_ADDR, 0x82, 2, &regs[0]);
- axp173.adc_enable = adc_bits;
-}
-
-int axp173_adc_get_rate(void)
-{
- int r = i2c_reg_read1(AXP173_BUS, AXP173_ADDR, 0x84);
- if(r < 0)
- return AXP173_ADC_RATE_100HZ; /* an arbitrary value */
-
- return (r >> 6) & 3;
-}
-
-void axp173_adc_set_rate(int rate)
-{
- i2c_reg_modify1(AXP173_BUS, AXP173_ADDR, 0x84,
- 0xc0, (rate & 3) << 6, NULL);
-}
-
-static uint32_t axp173_cc_parse(const uint8_t* buf)
-{
- return ((uint32_t)buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
-}
-
-void axp173_cc_read(uint32_t* charge, uint32_t* discharge)
-{
- uint8_t buf[8];
- int rc = i2c_reg_read(AXP173_BUS, AXP173_ADDR, 0xb0, 8, &buf[0]);
- if(rc != I2C_STATUS_OK) {
- if(charge)
- *charge = 0;
- if(discharge)
- *discharge = 0;
- return;
- }
-
- if(charge)
- *charge = axp173_cc_parse(&buf[0]);
- if(discharge)
- *discharge = axp173_cc_parse(&buf[4]);
-}
-
-void axp173_cc_clear(void)
-{
- i2c_reg_setbit1(AXP173_BUS, AXP173_ADDR, 0xb8, 5, 1, NULL);
-}
-
-void axp173_cc_enable(bool en)
-{
- i2c_reg_setbit1(AXP173_BUS, AXP173_ADDR, 0xb8, 7, en ? 1 : 0, NULL);
-}
-
-#ifndef BOOTLOADER
-#define AXP173_DEBUG_BATTERY_STATUS 0
-#define AXP173_DEBUG_INPUT_STATUS 1
-#define AXP173_DEBUG_ADC_RATE 2
-#define AXP173_DEBUG_FIRST_ADC 3
-#define AXP173_DEBUG_ENTRIES (AXP173_DEBUG_FIRST_ADC + NUM_ADC_CHANNELS)
-
-static int axp173_debug_menu_cb(int action, struct gui_synclist* lists)
-{
- (void)lists;
-
- if(action == ACTION_NONE)
- action = ACTION_REDRAW;
-
- return action;
-}
-
-static const char* axp173_debug_menu_get_name(int item, void* data,
- char* buf, size_t buflen)
-{
- (void)data;
-
- static const char* const adc_names[] = {
- "V_acin", "I_acin", "V_vbus", "I_vbus", "T_int",
- "V_ts", "V_batt", "I_chrg", "I_dchg", "V_aps", "P_batt"
- };
-
- static const char* const adc_units[] = {
- "mV", "mA", "mV", "mA", "C", "mV", "mV", "mA", "mA", "mV", "uW",
- };
-
- int adc = item - AXP173_DEBUG_FIRST_ADC;
- if(item >= AXP173_DEBUG_FIRST_ADC && adc < NUM_ADC_CHANNELS) {
- int raw_value = axp173_adc_read_raw(adc);
- if(raw_value == INT_MIN) {
- snprintf(buf, buflen, "%s: [Disabled]", adc_names[adc]);
- return buf;
- }
-
- int value = axp173_adc_conv_raw(adc, raw_value);
- if(adc == ADC_INTERNAL_TEMP) {
- snprintf(buf, buflen, "%s: %d.%d %s", adc_names[adc],
- value/10, value%10, adc_units[adc]);
- } else {
- snprintf(buf, buflen, "%s: %d %s", adc_names[adc],
- value, adc_units[adc]);
- }
-
- return buf;
- }
-
- switch(item) {
- case AXP173_DEBUG_BATTERY_STATUS: {
- switch(axp173_battery_status()) {
- case AXP173_BATT_FULL:
- return "Battery: Full";
- case AXP173_BATT_CHARGING:
- return "Battery: Charging";
- case AXP173_BATT_DISCHARGING:
- return "Battery: Discharging";
- default:
- return "Battery: Unknown";
- }
- } break;
-
- case AXP173_DEBUG_INPUT_STATUS: {
- int s = axp173_input_status();
- const char* ac = (s & AXP173_INPUT_AC) ? " AC" : "";
- const char* usb = (s & AXP173_INPUT_USB) ? " USB" : "";
- const char* batt = (s & AXP173_INPUT_BATTERY) ? " Battery" : "";
- snprintf(buf, buflen, "Inputs:%s%s%s", ac, usb, batt);
- return buf;
- } break;
-
- case AXP173_DEBUG_ADC_RATE: {
- int rate = 25 << axp173_adc_get_rate();
- snprintf(buf, buflen, "ADC sample rate: %d Hz", rate);
- return buf;
- } break;
-
- default:
- return "---";
- }
-}
-
-bool axp173_debug_menu(void)
-{
- struct simplelist_info info;
- simplelist_info_init(&info, "AXP173 debug", AXP173_DEBUG_ENTRIES, NULL);
- info.action_callback = axp173_debug_menu_cb;
- info.get_name = axp173_debug_menu_get_name;
- return simplelist_show_list(&info);
-}
-#endif /* !BOOTLOADER */
-
-/* This is basically the only valid implementation, so define it here */
-unsigned int power_input_status(void)
-{
- unsigned int state = 0;
- int input_status = axp173_input_status();
-
- if(input_status & AXP173_INPUT_AC)
- state |= POWER_INPUT_MAIN_CHARGER;
-
- if(input_status & AXP173_INPUT_USB)
- state |= POWER_INPUT_USB_CHARGER;
-
-#ifdef HAVE_BATTERY_SWITCH
- if(input_status & AXP173_INPUT_BATTERY)
- state |= POWER_INPUT_BATTERY;
-#endif
-
- return state;
-}
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 50619983e9..337e29a1bc 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -2384,44 +2384,43 @@ static long transfer(struct bpb *fat_bpb, unsigned long start, long count,
panicf("Write %ld after data\n",
start + count - fat_bpb->totalsectors);
}
- else
- {
- rc = storage_write_sectors(IF_MD(fat_bpb->drive,)
- start + fat_bpb->startsector, count, buf);
- }
}
- else
- {
- void* xferbuf = buf;
-#ifdef STORAGE_NEEDS_BOUNCE_BUFFER
- int remain = count;
- int xferred = 0;
- int aligned = 1;
- if(STORAGE_OVERLAP((uintptr_t)buf)) {
- xferbuf = FAT_BOUNCE_BUFFER(fat_bpb);
- aligned = 0;
- count = MIN(remain, FAT_BOUNCE_SECTORS);
- }
- while(remain > 0) {
-#endif
- rc = storage_read_sectors(IF_MD(fat_bpb->drive,)
- start + fat_bpb->startsector, count, xferbuf);
#ifdef STORAGE_NEEDS_BOUNCE_BUFFER
+ if(UNLIKELY(STORAGE_OVERLAP((uintptr_t)buf))) {
+ void* xfer_buf = FAT_BOUNCE_BUFFER(fat_bpb);
+ while(count > 0) {
+ int xfer_count = MIN(count, FAT_BOUNCE_SECTORS);
+
+ if(write) {
+ memcpy(xfer_buf, buf, xfer_count * SECTOR_SIZE);
+ rc = storage_write_sectors(IF_MD(fat_bpb->drive,)
+ start + fat_bpb->startsector, xfer_count, xfer_buf);
+ } else {
+ rc = storage_read_sectors(IF_MD(fat_bpb->drive,)
+ start + fat_bpb->startsector, xfer_count, xfer_buf);
+ memcpy(buf, xfer_buf, xfer_count * SECTOR_SIZE);
+ }
+
if(rc < 0)
break;
- if(LIKELY(aligned))
- break;
- memcpy(buf, xferbuf, count * SECTOR_SIZE);
- buf += count * SECTOR_SIZE;
- xferred += count;
- start += count;
- remain -= count;
- count = MIN(remain, FAT_BOUNCE_SECTORS);
+ buf += xfer_count * SECTOR_SIZE;
+ start += xfer_count;
+ count -= xfer_count;
}
+ } else {
#endif
+ if(write) {
+ rc = storage_write_sectors(IF_MD(fat_bpb->drive,)
+ start + fat_bpb->startsector, count, buf);
+ } else {
+ rc = storage_read_sectors(IF_MD(fat_bpb->drive,)
+ start + fat_bpb->startsector, count, buf);
+ }
+#ifdef STORAGE_NEEDS_BOUNCE_BUFFER
}
+#endif
if (rc < 0)
{
diff --git a/firmware/drivers/ft6x06.c b/firmware/drivers/ft6x06.c
new file mode 100644
index 0000000000..538ca10480
--- /dev/null
+++ b/firmware/drivers/ft6x06.c
@@ -0,0 +1,115 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2021 Aidan MacDonald
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "ft6x06.h"
+#include "kernel.h"
+#include "i2c-async.h"
+#include <string.h>
+
+struct ft6x06_driver {
+ /* i2c bus data */
+ int i2c_cookie;
+ i2c_descriptor i2c_desc;
+
+ /* callback for touch events */
+ ft6x06_event_cb event_cb;
+
+ /* buffer for I2C transfers */
+ uint8_t raw_data[6];
+};
+
+static struct ft6x06_driver ft_drv;
+struct ft6x06_state ft6x06_state;
+
+static void ft6x06_i2c_callback(int status, i2c_descriptor* desc)
+{
+ (void)desc;
+ if(status != I2C_STATUS_OK)
+ return;
+
+ int evt = ft_drv.raw_data[1] >> 6;
+ int tx = ft_drv.raw_data[2] | ((ft_drv.raw_data[1] & 0xf) << 8);
+ int ty = ft_drv.raw_data[4] | ((ft_drv.raw_data[3] & 0xf) << 8);
+
+ ft6x06_state.event = evt;
+#ifdef FT6x06_SWAP_AXES
+ ft6x06_state.pos_x = ty;
+ ft6x06_state.pos_y = tx;
+#else
+ ft6x06_state.pos_x = tx;
+ ft6x06_state.pos_y = ty;
+#endif
+
+ ft_drv.event_cb(evt, ft6x06_state.pos_x, ft6x06_state.pos_y);
+}
+
+static void ft6x06_dummy_event_cb(int evt, int tx, int ty)
+{
+ (void)evt;
+ (void)tx;
+ (void)ty;
+}
+
+void ft6x06_init(void)
+{
+ /* Initialize stuff */
+ memset(&ft_drv, 0, sizeof(ft_drv));
+ ft_drv.event_cb = ft6x06_dummy_event_cb;
+
+ ft6x06_state.event = FT6x06_EVT_NONE;
+ ft6x06_state.pos_x = 0;
+ ft6x06_state.pos_y = 0;
+
+ /* Reserve bus management cookie */
+ ft_drv.i2c_cookie = i2c_async_reserve_cookies(FT6x06_BUS, 1);
+
+ /* Prep an I2C descriptor to read touch data */
+ ft_drv.i2c_desc.slave_addr = FT6x06_ADDR;
+ ft_drv.i2c_desc.bus_cond = I2C_START | I2C_STOP;
+ ft_drv.i2c_desc.tran_mode = I2C_READ;
+ ft_drv.i2c_desc.buffer[0] = &ft_drv.raw_data[5];
+ ft_drv.i2c_desc.count[0] = 1;
+ ft_drv.i2c_desc.buffer[1] = &ft_drv.raw_data[0];
+ ft_drv.i2c_desc.count[1] = 5;
+ ft_drv.i2c_desc.callback = ft6x06_i2c_callback;
+ ft_drv.i2c_desc.arg = 0;
+ ft_drv.i2c_desc.next = NULL;
+
+ /* Set I2C register address */
+ ft_drv.raw_data[5] = 0x02;
+}
+
+void ft6x06_set_event_cb(ft6x06_event_cb cb)
+{
+ ft_drv.event_cb = cb ? cb : ft6x06_dummy_event_cb;
+}
+
+void ft6x06_enable(bool en)
+{
+ i2c_reg_write1(FT6x06_BUS, FT6x06_ADDR, 0xa5, en ? 0 : 3);
+}
+
+void ft6x06_irq_handler(void)
+{
+ /* We don't care if this fails, there's not much we can do about it */
+ i2c_async_queue(FT6x06_BUS, TIMEOUT_NOBLOCK, I2C_Q_ONCE,
+ ft_drv.i2c_cookie, &ft_drv.i2c_desc);
+}
diff --git a/firmware/drivers/lcd-16bit-common.c b/firmware/drivers/lcd-16bit-common.c
index 5ec142c855..dbfea50dd7 100644
--- a/firmware/drivers/lcd-16bit-common.c
+++ b/firmware/drivers/lcd-16bit-common.c
@@ -341,12 +341,18 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
if (y + height > LCD_HEIGHT)
height = LCD_HEIGHT - y;
#endif
-
src += stride * (src_y >> 3) + src_x; /* move starting point */
src_y &= 7;
src_end = src + width;
dst_col = FBADDR(x, y);
+ /* 'Bugfix' mono_bitmap_part reads ahead in the buffer,
+ * if the height is <= char bit pixels other memory gets read
+ * the other option is to check in the hot code path but this appears
+ * sufficient
+ */
+ if (height <= CHAR_BIT)
+ stride = 0;
if (drmode & DRMODE_INVERSEVID)
{
@@ -462,14 +468,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
/* Draw a full monochrome bitmap */
void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width, int height)
{
- int stride = width;
-
- /* 'Bugfix' mono_bitmap_part reads ahead in the buffer,
- * if the height is <= char bit pixels other memory gets read
- */
- if (height <= CHAR_BIT)
- stride = 0;
- lcd_mono_bitmap_part(src, 0, 0, stride, x, y, width, height);
+ lcd_mono_bitmap_part(src, 0, 0, width, x, y, width, height);
}
diff --git a/firmware/drivers/rtc/rtc_d2.c b/firmware/drivers/rtc/rtc_d2.c
index 1d202410e2..726564a255 100644
--- a/firmware/drivers/rtc/rtc_d2.c
+++ b/firmware/drivers/rtc/rtc_d2.c
@@ -53,9 +53,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_ds1339_ds3231.c b/firmware/drivers/rtc/rtc_ds1339_ds3231.c
index 8f2a531e5f..b77e059595 100644
--- a/firmware/drivers/rtc/rtc_ds1339_ds3231.c
+++ b/firmware/drivers/rtc/rtc_ds1339_ds3231.c
@@ -126,9 +126,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = BCD2DEC(buf[4] & 0x3f);
tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1;
tm->tm_year = BCD2DEC(buf[6]) + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_e8564.c b/firmware/drivers/rtc/rtc_e8564.c
index 4bb61410db..775ff86728 100644
--- a/firmware/drivers/rtc/rtc_e8564.c
+++ b/firmware/drivers/rtc/rtc_e8564.c
@@ -86,9 +86,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = BCD2DEC(buf[3] & 0x3f);
tm->tm_mon = BCD2DEC(buf[5] & 0x1f) - 1;
tm->tm_year = BCD2DEC(buf[6]) + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return read;
}
diff --git a/firmware/drivers/rtc/rtc_mr100.c b/firmware/drivers/rtc/rtc_mr100.c
index 6e1b0b5f40..2f44137e38 100644
--- a/firmware/drivers/rtc/rtc_mr100.c
+++ b/firmware/drivers/rtc/rtc_mr100.c
@@ -144,9 +144,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[2];
tm->tm_mon = buf[1] - 1;
tm->tm_year = buf[0] + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_pcf50605.c b/firmware/drivers/rtc/rtc_pcf50605.c
index daa35fb13f..42ea15ff2e 100644
--- a/firmware/drivers/rtc/rtc_pcf50605.c
+++ b/firmware/drivers/rtc/rtc_pcf50605.c
@@ -52,9 +52,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_pcf50606.c b/firmware/drivers/rtc/rtc_pcf50606.c
index 540ebfff06..16ae5a3e9c 100644
--- a/firmware/drivers/rtc/rtc_pcf50606.c
+++ b/firmware/drivers/rtc/rtc_pcf50606.c
@@ -56,7 +56,7 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_hour = buf[2];
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
- tm->tm_yday = 0; /* Not implemented for now */
+
#ifdef IRIVER_H300_SERIES
/* Special kludge to coexist with the iriver firmware. The iriver firmware
stores the date as 1965+nn, and allows a range of 1980..2064. We use
@@ -68,6 +68,7 @@ int rtc_read_datetime(struct tm *tm)
#endif /* IRIVER_H300_SERIES */
set_day_of_week(tm);
+ set_day_of_year(tm);
return rc;
}
diff --git a/firmware/drivers/rtc/rtc_rx5x348ab.c b/firmware/drivers/rtc/rtc_rx5x348ab.c
index 6d7b78b281..d95186e8be 100644
--- a/firmware/drivers/rtc/rtc_rx5x348ab.c
+++ b/firmware/drivers/rtc/rtc_rx5x348ab.c
@@ -52,9 +52,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return 1;
}
diff --git a/firmware/drivers/rtc/rtc_s35380a.c b/firmware/drivers/rtc/rtc_s35380a.c
index f32c431990..6deaed6354 100644
--- a/firmware/drivers/rtc/rtc_s35380a.c
+++ b/firmware/drivers/rtc/rtc_s35380a.c
@@ -192,9 +192,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[TIME_DAY];
tm->tm_mon = buf[TIME_MONTH] - 1;
tm->tm_year = buf[TIME_YEAR] + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return ret;
}
diff --git a/firmware/drivers/rtc/rtc_s35390a.c b/firmware/drivers/rtc/rtc_s35390a.c
index b82029a114..6e69073254 100644
--- a/firmware/drivers/rtc/rtc_s35390a.c
+++ b/firmware/drivers/rtc/rtc_s35390a.c
@@ -79,9 +79,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[2];
tm->tm_mon = buf[1] - 1;
tm->tm_year = buf[0] + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return ret;
}
diff --git a/firmware/drivers/rtc/rtc_s3c2440.c b/firmware/drivers/rtc/rtc_s3c2440.c
index 6cd34f0e23..71f99ac6f4 100644
--- a/firmware/drivers/rtc/rtc_s3c2440.c
+++ b/firmware/drivers/rtc/rtc_s3c2440.c
@@ -39,9 +39,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = BCD2DEC(BCDDATE);
tm->tm_mon = BCD2DEC(BCDMON) - 1;
tm->tm_year = BCD2DEC(BCDYEAR) + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return 1;
}
diff --git a/firmware/drivers/rtc/rtc_tcc77x.c b/firmware/drivers/rtc/rtc_tcc77x.c
deleted file mode 100644
index a85c93d65a..0000000000
--- a/firmware/drivers/rtc/rtc_tcc77x.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "rtc.h"
-#include "system.h"
-#include <stdbool.h>
-
-void rtc_init(void)
-{
-}
-
-int rtc_read_datetime(struct tm *tm)
-{
- (void)tm;
- return 0;
-}
-
-int rtc_write_datetime(const struct tm *tm)
-{
- (void)tm;
- return 1;
-}
-
-#ifdef HAVE_RTC_ALARM
-/**
- * Checks to see if an alarm interrupt has triggered since last we checked.
- */
-bool rtc_check_alarm_flag(void)
-{
-}
-
-/**
- * Enables or disables the alarm.
- */
-void rtc_enable_alarm(bool enable)
-{
-}
-
-/**
- * Check if alarm caused unit to start.
- */
-bool rtc_check_alarm_started(bool release_alarm)
-{
-}
-
-void rtc_set_alarm(int h, int m)
-{
- /* Convert to BCD */
-// pcf50605_write(0x12, ((m/10) << 4) | m%10);
-// pcf50605_write(0x13, ((h/10) << 4) | h%10);
-}
-
-void rtc_get_alarm(int *h, int *m)
-{
- char buf[2];
-
- /* Convert from BCD */
-// *m = ((buf[0] >> 4) & 0x7)*10 + (buf[0] & 0x0f);
-// *h = ((buf[1] >> 4) & 0x3)*10 + (buf[1] & 0x0f);
-}
-#endif /* HAVE_RTC_ALARM */
-
-
diff --git a/firmware/drivers/synaptics-mep.c b/firmware/drivers/synaptics-mep.c
index 01845bfe0c..bae17e08c7 100644
--- a/firmware/drivers/synaptics-mep.c
+++ b/firmware/drivers/synaptics-mep.c
@@ -560,7 +560,10 @@ int touchpad_read_device(char *data, int len)
{
/* for HDD6330 an absolute packet will follow for sensor nr 0 which we ignore */
#if defined(PHILIPS_HDD6330)
- if ((data[3]>>6) == 0) syn_read(tmp, 4);
+ if ((data[3]>>6) == 0)
+ syn_read(tmp, 4);
+ else
+ tmp[1] = 0x0; /* Initialize explicitly */
// relay tap gesture packet
if (tmp[1]==0x02) { data[1]=0x02; data[2]=0x00; data[3]=0x00; }
#endif
diff --git a/firmware/drivers/tuner/lv24020lp.c b/firmware/drivers/tuner/lv24020lp.c
index bb137d60ff..2fbf88b01b 100644
--- a/firmware/drivers/tuner/lv24020lp.c
+++ b/firmware/drivers/tuner/lv24020lp.c
@@ -80,16 +80,6 @@ static int fd_log = -1;
#define FM_CLOCK_PIN 4
#define FM_DATA_PIN 5
-#elif defined(IAUDIO_7)
-#define TUNER_GPIO_INPUT_VAL GPIOA
-#define TUNER_GPIO_OUTPUT_EN_SET(mask) (GPIOA_DIR |= (mask))
-#define TUNER_GPIO_OUTPUT_EN_CLEAR(mask) (GPIOA_DIR &= ~(mask))
-#define TUNER_GPIO_OUTPUT_VAL_SET(mask) (GPIOA |= (mask))
-#define TUNER_GPIO_OUTPUT_VAL_CLEAR(mask) (GPIOA &= ~(mask))
-#define FM_CLOCK_PIN 5
-#define FM_DATA_PIN 6
-#define FM_NRW_PIN 7
-
#elif defined(COWON_D2)
#define TUNER_GPIO_INPUT_VAL GPIOC
#define TUNER_GPIO_OUTPUT_EN_SET(mask) (GPIOC_DIR |= (mask))
diff --git a/firmware/target/arm/usb-designware.c b/firmware/drivers/usb-designware.c
index 24c6055434..375fd8be74 100644
--- a/firmware/target/arm/usb-designware.c
+++ b/firmware/drivers/usb-designware.c
@@ -53,6 +53,15 @@
#define COMMIT_DCACHE_RANGE(b,s) commit_dcache_range(b,s)
#endif
+/* On some platforms, virtual addresses must be mangled to
+ * get a physical address for DMA
+ */
+#if CONFIG_CPU == X1000
+# define DMA_ADDR2PHYS(x) PHYSADDR(x)
+#else
+# define DMA_ADDR2PHYS(x) x
+#endif
+
#ifndef USB_DW_TOUTCAL
#define USB_DW_TOUTCAL 0
#endif
@@ -449,7 +458,7 @@ static void usb_dw_nptx_unqueue(int epnum)
dw_ep->addr -= (bytesinfifo + 3) >> 2;
#else
(void) bytesinfifo;
- DWC_DIEPDMA(ep) = (uint32_t)(dw_ep->addr) + sentbytes;
+ DWC_DIEPDMA(ep) = DMA_ADDR2PHYS((uint32_t)(dw_ep->addr) + sentbytes);
#endif
DWC_DIEPTSIZ(ep) = PKTCNT(packetsleft) | (dw_ep->size - sentbytes);
@@ -676,7 +685,7 @@ static void usb_dw_start_xfer(int epnum,
/* Set up data source */
dw_ep->addr = (uint32_t*)buf;
#ifndef USB_DW_ARCH_SLAVE
- DWC_EPDMA(epnum, epdir) = (uint32_t)buf;
+ DWC_EPDMA(epnum, epdir) = DMA_ADDR2PHYS((uint32_t)buf);
#endif
if (epdir == USB_DW_EPDIR_IN)
diff --git a/firmware/export/ak4376.h b/firmware/export/ak4376.h
index eb06755e92..eab0bc24f3 100644
--- a/firmware/export/ak4376.h
+++ b/firmware/export/ak4376.h
@@ -104,10 +104,12 @@ AUDIOHW_SETTING(POWER_MODE, "", 0, 1, 0, 1, 0)
#define AK4376_FS_176 17
#define AK4376_FS_192 18
-/* Functions to power on / off the DAC which should be called from
- * the target's audiohw_init() / audiohw_close() implementation.
+/* Functions to power on / off the DAC.
+ *
+ * NOTE: Target must call ak4376_set_frequency() after ak4376_open() to
+ * finish the power-up sequence of the headphone amp.
*/
-extern void ak4376_init(void);
+extern void ak4376_open(void);
extern void ak4376_close(void);
/* Register read/write. Cached to avoid redundant reads/writes. */
@@ -117,16 +119,17 @@ extern int ak4376_read(int reg);
/* Target-specific function to set the PDN pin level. */
extern void ak4376_set_pdn_pin(int level);
-/* Target-specific function to control the external master clock frequency.
- * This is called by the ak4376's audiohw implementation when switching to
- * or from a frequency that is configured to use this clock source.
- *
- * - hw_freq is the new sample rate -- one of the HW_FREQ_XX constants.
- * - enabled is true if clock should be output, false if not.
+/* Set overall output volume */
+extern void ak4376_set_volume(int vol_l, int vol_r);
+
+/* Set the roll-off filter */
+extern void ak4376_set_filter_roll_off(int val);
+
+/* Set audio sampling frequency and power mode.
*
- * The return value is the master clock rate as a multiple of the sampling
- * frequency. The allowed multiples depend on the sampling frequency, shown
- * in the table below.
+ * If the I2S master clock is being supplied externally, the caller must also
+ * give the master clock multiplier 'mult'. The accepted values depend on the
+ * sampling rate, see below:
*
* +-----------+------------------------+
* | frequency | master clock rate |
@@ -137,16 +140,13 @@ extern void ak4376_set_pdn_pin(int level);
* | 128 - 192 | 128fs |
* +-----------+------------------------+
*
- * For example, at 48 KHz you could return either 256 or 512 depending on
- * the rate you decided to actually use.
- *
- * You need to return a valid master multiplier for supported frequencies
- * even when enabled = false, since the driver needs to know the multiplier
- * _before_ enabling the clock.
+ * Switching between high-power and low-power mode requires the same registers
+ * and power-up / power-down sequences as a frequency switch, so both settings
+ * are controlled by this function.
*
- * For unsupported frequencies you don't need to return a valid master
- * multiplier, because the DAC doesn't need the return value in such cases.
+ * high power mode -- use power_mode=0
+ * low power mode -- use power_mode=1
*/
-extern int ak4376_set_mclk_freq(int hw_freq, bool enabled);
+extern void ak4376_set_freqmode(int fsel, int mult, int power_mode);
#endif /* __AK4376_H__ */
diff --git a/firmware/export/axp-pmu.h b/firmware/export/axp-pmu.h
new file mode 100644
index 0000000000..457f746e8c
--- /dev/null
+++ b/firmware/export/axp-pmu.h
@@ -0,0 +1,151 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2021 Aidan MacDonald
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __AXP_PMU_H__
+#define __AXP_PMU_H__
+
+#include "config.h"
+#include <stdbool.h>
+#include <stdint.h>
+
+/* ADC channels */
+#define ADC_ACIN_VOLTAGE 0
+#define ADC_ACIN_CURRENT 1
+#define ADC_VBUS_VOLTAGE 2
+#define ADC_VBUS_CURRENT 3
+#define ADC_INTERNAL_TEMP 4
+#define ADC_TS_INPUT 5
+#define ADC_BATTERY_VOLTAGE 6
+#define ADC_CHARGE_CURRENT 7
+#define ADC_DISCHARGE_CURRENT 8
+#define ADC_APS_VOLTAGE 9
+#define ADC_BATTERY_POWER 10
+#define NUM_ADC_CHANNELS 11
+
+/* ADC sampling rates */
+#define AXP_ADC_RATE_25HZ 0
+#define AXP_ADC_RATE_50HZ 1
+#define AXP_ADC_RATE_100HZ 2
+#define AXP_ADC_RATE_200HZ 3
+
+/* Return values of axp_battery_status() */
+#define AXP_BATT_DISCHARGING 0
+#define AXP_BATT_CHARGING 1
+#define AXP_BATT_FULL 2
+
+/* Bits returned by axp_input_status() */
+#define AXP_INPUT_AC (1 << 0)
+#define AXP_INPUT_USB (1 << 1)
+#define AXP_INPUT_BATTERY (1 << 2)
+#define AXP_INPUT_EXTERNAL (AXP_INPUT_AC|AXP_INPUT_USB)
+
+/* Power supplies known by this driver. Not every chip has all supplies! */
+#define AXP_SUPPLY_DCDC1 0
+#define AXP_SUPPLY_DCDC2 1
+#define AXP_SUPPLY_DCDC3 2
+#define AXP_SUPPLY_LDO1 3
+#define AXP_SUPPLY_LDO2 4
+#define AXP_SUPPLY_LDO3 5
+#define AXP_SUPPLY_LDO_IO0 6
+#define AXP_NUM_SUPPLIES 7
+
+/* Special values returned by axp_supply_get_voltage */
+#define AXP_SUPPLY_NOT_PRESENT INT_MIN
+#define AXP_SUPPLY_DISABLED (-1)
+
+/* Registers -- common to AXP173 and AXP192 (incomplete listing) */
+#define AXP_REG_POWERSTATUS 0x00
+#define AXP_REG_CHARGESTATUS 0x01
+#define AXP_REG_CHIP_ID 0x03
+#define AXP_REG_PWROUTPUTCTRL1 0x10
+#define AXP_REG_PWROUTPUTCTRL2 0x12
+#define AXP_REG_SHUTDOWNLEDCTRL 0x32
+#define AXP_REG_CHARGECONTROL1 0x33
+#define AXP_REG_DCDCWORKINGMODE 0x80
+#define AXP_REG_ADCENABLE1 0x82
+#define AXP_REG_ADCENABLE2 0x83
+#define AXP_REG_ADCSAMPLERATE 0x84
+#define AXP_REG_COULOMBCOUNTERBASE 0xb0
+#define AXP_REG_COULOMBCOUNTERCTRL 0xb8
+
+/* AXP192-only registers (incomplete listing) */
+#define AXP192_REG_GPIO0FUNCTION 0x90
+#define AXP192_REG_GPIO1FUNCTION 0x92
+#define AXP192_REG_GPIO2FUNCTION 0x93
+#define AXP192_REG_GPIOSTATE1 0x94
+
+/* Must be called from power_init() to initialize the driver state */
+extern void axp_init(void);
+
+/* - axp_supply_set_voltage(): set a supply voltage to the given value
+ * in millivolts. Pass a voltage of AXP_SUPPLY_DISABLED to shut off
+ * the supply. Any invalid supply or voltage will make the call a no-op.
+ *
+ * - axp_supply_get_voltage() returns a supply voltage in millivolts.
+ * If the supply is powered off, returns AXP_SUPPLY_DISABLED.
+ * If the chip does not have the supply, returns AXP_SUPPLY_NOT_PRESENT.
+ */
+extern void axp_supply_set_voltage(int supply, int voltage);
+extern int axp_supply_get_voltage(int supply);
+
+/* Basic battery and power supply status */
+extern int axp_battery_status(void);
+extern int axp_input_status(void);
+
+/* ADC access -- ADCs which are not enabled will return INT_MIN if read.
+ * The output of axp_adc_read() is normalized to appropriate units:
+ *
+ * - for voltages, the scale is millivolts
+ * - for currents, the scale is milliamps
+ * - for temperatures, the scale is tenths of a degree Celsius
+ * - for power, the scale is microwatts
+ *
+ * See the comment in axp_adc_conv_raw() for raw value precision/scale.
+ */
+extern int axp_adc_read(int adc);
+extern int axp_adc_read_raw(int adc);
+extern int axp_adc_conv_raw(int adc, int value);
+extern int axp_adc_get_enabled(void);
+extern void axp_adc_set_enabled(int adc_bits);
+extern int axp_adc_get_rate(void);
+extern void axp_adc_set_rate(int rate);
+
+/* - axp_cc_read() reads the coulomb counters
+ * - axp_cc_clear() resets both counters to zero
+ * - axp_cc_enable() will stop/start the counters running
+ * - axp_cc_is_enabled() returns true if the counters are running
+ */
+extern void axp_cc_read(uint32_t* charge, uint32_t* discharge);
+extern void axp_cc_clear(void);
+extern void axp_cc_enable(bool en);
+extern bool axp_cc_is_enabled(void);
+
+/* Set/get maximum charging current in milliamps */
+extern void axp_set_charge_current(int maxcurrent);
+extern int axp_get_charge_current(void);
+
+/* Set the shutdown bit */
+extern void axp_power_off(void);
+
+/* Debug menu */
+extern bool axp_debug_menu(void);
+
+#endif /* __AXP_PMU_H__ */
diff --git a/firmware/export/axp173.h b/firmware/export/axp173.h
deleted file mode 100644
index 60519138e1..0000000000
--- a/firmware/export/axp173.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2021 Aidan MacDonald
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#ifndef __AXP173_H__
-#define __AXP173_H__
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#define ADC_ACIN_VOLTAGE 0
-#define ADC_ACIN_CURRENT 1
-#define ADC_VBUS_VOLTAGE 2
-#define ADC_VBUS_CURRENT 3
-#define ADC_INTERNAL_TEMP 4
-#define ADC_TS_INPUT 5
-#define ADC_BATTERY_VOLTAGE 6
-#define ADC_CHARGE_CURRENT 7
-#define ADC_DISCHARGE_CURRENT 8
-#define ADC_APS_VOLTAGE 9
-#define ADC_BATTERY_POWER 10
-#define NUM_ADC_CHANNELS 11
-
-/* ADC sampling rates */
-#define AXP173_ADC_RATE_25HZ 0
-#define AXP173_ADC_RATE_50HZ 1
-#define AXP173_ADC_RATE_100HZ 2
-#define AXP173_ADC_RATE_200HZ 3
-
-/* Return values of axp173_battery_status() */
-#define AXP173_BATT_DISCHARGING 0
-#define AXP173_BATT_CHARGING 1
-#define AXP173_BATT_FULL 2
-
-/* Bits returned by axp173_input_status() */
-#define AXP173_INPUT_AC (1 << 0)
-#define AXP173_INPUT_USB (1 << 1)
-#define AXP173_INPUT_BATTERY (1 << 2)
-#define AXP173_INPUT_EXTERNAL (AXP173_INPUT_AC|AXP173_INPUT_USB)
-
-/* Must be called from power_init() to initialize the driver state */
-extern void axp173_init(void);
-
-/* Basic battery and power supply status */
-extern int axp173_battery_status(void);
-extern int axp173_input_status(void);
-
-/* ADC access -- ADCs which are not enabled will return INT_MIN if read.
- * The output of axp173_adc_read() is normalized to appropriate units:
- *
- * - for voltages, the scale is millivolts
- * - for currents, the scale is milliamps
- * - for temperatures, the scale is tenths of a degree Celsius
- * - for power, the scale is microwatts
- *
- * See the comment in axp173_adc_conv_raw() for raw value precision/scale.
- */
-extern int axp173_adc_read(int adc);
-extern int axp173_adc_read_raw(int adc);
-extern int axp173_adc_conv_raw(int adc, int value);
-extern int axp173_adc_get_enabled(void);
-extern void axp173_adc_set_enabled(int adc_bits);
-extern int axp173_adc_get_rate(void);
-extern void axp173_adc_set_rate(int rate);
-
-/* - axp173_cc_read() reads the coulomb counters
- * - axp173_cc_clear() resets both counters to zero
- * - axp173_cc_enable() will stop/start the counters running
- */
-extern void axp173_cc_read(uint32_t* charge, uint32_t* discharge);
-extern void axp173_cc_clear(void);
-extern void axp173_cc_enable(bool en);
-
-/* Debug menu */
-extern bool axp173_debug_menu(void);
-
-#endif /* __AXP173_H__ */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index db1c589043..623ef8b4ff 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -68,9 +68,6 @@
#define DSC25 25
#define DM320 320
#define IMX31L 31
-#define TCC770 770
-#define TCC771L 771
-#define TCC773L 773
#define TCC7801 7801
#define S5L8700 8700
#define S5L8701 8701
@@ -104,7 +101,6 @@
#define IPOD_4G_PAD 7
#define IPOD_3G_PAD 8
#define IPOD_1G2G_PAD 9
-#define IRIVER_IFP7XX_PAD 10
#define GIGABEAT_PAD 11
#define IRIVER_H10_PAD 12
#define SANSA_E200_PAD 13
@@ -113,15 +109,12 @@
#define MROBE100_PAD 17
#define MROBE500_PAD 18
#define GIGABEAT_S_PAD 19
-#define LOGIK_DAX_PAD 20
-#define IAUDIO67_PAD 21
#define COWON_D2_PAD 22
#define IAUDIO_M3_PAD 23
#define CREATIVEZVM_PAD 24
#define SANSA_M200_PAD 25
#define CREATIVEZV_PAD 26
#define PHILIPS_SA9200_PAD 27
-#define SANSA_C100_PAD 28
#define PHILIPS_HDD1630_PAD 29
#define MEIZU_M6SL_PAD 30
#define ONDAVX747_PAD 31
@@ -228,7 +221,6 @@
#define LCD_IPODVIDEO 8 /* as used by iPod Video */
#define LCD_IPOD2BPP 9 /* as used by all fullsize greyscale iPods */
#define LCD_IPODMINI 10 /* as used by iPod Mini g1/g2 */
-#define LCD_IFP7XX 11 /* as used by iRiver iFP 7xx/8xx */
#define LCD_GIGABEAT 12
#define LCD_H10_20GB 13 /* as used by iriver H10 20Gb */
#define LCD_H10_5GB 14 /* as used by iriver H10 5Gb */
@@ -236,13 +228,11 @@
#define LCD_C200 17 /* as used by Sandisk Sansa c200 */
#define LCD_MROBE500 18 /* as used by Olympus M:Robe 500i */
#define LCD_MROBE100 19 /* as used by Olympus M:Robe 100 */
-#define LCD_LOGIKDAX 20 /* as used by Logik DAX - SSD1815 */
-#define LCD_IAUDIO67 21 /* as used by iAudio 6/7 - unknown */
#define LCD_CREATIVEZVM 22 /* as used by Creative Zen Vision:M */
#define LCD_TL0350A 23 /* as used by the iAudio M3 remote, treated as main LCD */
#define LCD_COWOND2 24 /* as used by Cowon D2 - LTV250QV, TCC7801 driver */
#define LCD_SA9200 25 /* as used by the Philips SA9200 */
-#define LCD_S6B33B2 26 /* as used by the Sansa c100 */
+#define LCD_S6B33B2 26 /* as used by the Samsumg YH820 */
#define LCD_HDD1630 27 /* as used by the Philips HDD1630 */
#define LCD_MEIZUM6 28 /* as used by the Meizu M6SP and M6SL (various models) */
#define LCD_ONDAVX747 29 /* as used by the Onda VX747 */
@@ -314,7 +304,6 @@ Lyre prototype 1 */
#define I2C_S3C2440 7
#define I2C_PP5024 8 /* PP5024 style */
#define I2C_IMX31L 9
-#define I2C_TCC77X 10
#define I2C_TCC780X 11
#define I2C_DM320 12 /* DM320 style */
#define I2C_S5L8700 13
@@ -331,7 +320,6 @@ Lyre prototype 1 */
/* else HW controlled LED (iRiver H1x0) */
/* CONFIG_NAND */
-#define NAND_IFP7XX 1
#define NAND_TCC 2
#define NAND_SAMSUNG 3
#define NAND_CC 4 /* ChinaChip */
@@ -347,7 +335,6 @@ Lyre prototype 1 */
#define RTC_DS1339_DS3231 7 /* h1x0 RTC mod */
#define RTC_IMX31L 8
#define RTC_RX5X348AB 9
-#define RTC_TCC77X 10
#define RTC_TCC780X 11
#define RTC_MR100 12
#define RTC_MC13783 13 /* Freescale MC13783 PMIC */
@@ -420,8 +407,6 @@ Lyre prototype 1 */
#include "config/ipodnano2g.h"
#elif defined(IPOD_6G)
#include "config/ipod6g.h"
-#elif defined(IRIVER_IFP7XX)
-#include "config/iriverifp7xx.h"
#elif defined(GIGABEAT_F)
#include "config/gigabeatfx.h"
#elif defined(GIGABEAT_S)
@@ -438,18 +423,12 @@ Lyre prototype 1 */
#include "config/sansae200.h"
#elif defined(SANSA_C200)
#include "config/sansac200.h"
-#elif defined(SANSA_M200)
-#include "config/sansam200.h"
#elif defined(TATUNG_TPJ1022)
#include "config/tatungtpj1022.h"
#elif defined(MROBE_100)
#include "config/mrobe100.h"
#elif defined(MROBE_500)
#include "config/mrobe500.h"
-#elif defined(LOGIK_DAX)
-#include "config/logikdax.h"
-#elif defined(IAUDIO_7)
-#include "config/iaudio7.h"
#elif defined(COWON_D2)
#include "config/cowond2.h"
#elif defined(CREATIVE_ZVM)
@@ -468,8 +447,6 @@ Lyre prototype 1 */
#include "config/gogearhdd1630.h"
#elif defined(PHILIPS_HDD6330)
#include "config/gogearhdd6330.h"
-#elif defined(SANSA_C100)
-#include "config/sansac100.h"
#elif defined(MEIZU_M6SL)
#include "config/meizum6sl.h"
#elif defined(MEIZU_M6SP)
@@ -666,11 +643,6 @@ Lyre prototype 1 */
#define CPU_S5L870X
#endif
-/* define for all cpus from TCC77X family */
-#if (CONFIG_CPU == TCC771L) || (CONFIG_CPU == TCC773L) || (CONFIG_CPU == TCC770)
-#define CPU_TCC77X
-#endif
-
/* define for all cpus from TCC780 family */
#if (CONFIG_CPU == TCC7801)
#define CPU_TCC780X
@@ -930,6 +902,10 @@ Lyre prototype 1 */
#define INCLUDE_TIMEOUT_API
#define USB_DRIVER_CLOSE
#endif
+#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_TNETV105
+#define INCLUDE_TIMEOUT_API
+#define USB_DRIVER_CLOSE
+#endif
#endif
#else /* !BOOTLOADER */
@@ -966,6 +942,9 @@ Lyre prototype 1 */
#define USB_DETECT_BY_REQUEST
#elif CONFIG_USBOTG == USBOTG_RK27XX
#define USB_DETECT_BY_REQUEST
+#elif CONFIG_USBOTG == USBOTG_TNETV105
+#define USB_STATUS_BY_EVENT
+#define USB_DETECT_BY_REQUEST
#endif /* CONFIG_USB == */
#endif /* HAVE_USBSTACK */
@@ -1199,10 +1178,11 @@ Lyre prototype 1 */
(CONFIG_USBOTG == USBOTG_M66591) || \
(CONFIG_USBOTG == USBOTG_DESIGNWARE) || \
(CONFIG_USBOTG == USBOTG_AS3525) || \
- (CONFIG_USBOTG == USBOTG_RK27XX)
+ (CONFIG_USBOTG == USBOTG_RK27XX) || \
+ (CONFIG_USBOTG == USBOTG_TNETV105)
#define USB_HAS_BULK
#define USB_HAS_INTERRUPT
-#elif defined(CPU_TCC780X) || defined(CPU_TCC77X)
+#elif defined(CPU_TCC780X)
#define USB_HAS_BULK
#elif CONFIG_USBOTG == USBOTG_S3C6400X
#define USB_HAS_BULK
@@ -1219,7 +1199,7 @@ Lyre prototype 1 */
/* enable usb storage for targets that do bootloader usb */
#if defined(HAVE_BOOTLOADER_USB_MODE) || \
- defined(CREATIVE_ZVx) || defined(CPU_TCC77X) || defined(CPU_TCC780X) || \
+ defined(CREATIVE_ZVx) || defined(CPU_TCC780X) || \
CONFIG_USBOTG == USBOTG_JZ4740 || CONFIG_USBOTG == USBOTG_AS3525 || \
CONFIG_USBOTG == USBOTG_S3C6400X || CONFIG_USBOTG == USBOTG_DESIGNWARE || \
CONFIG_USBOTG == USBOTG_JZ4760
diff --git a/firmware/export/config/aigoerosq.h b/firmware/export/config/aigoerosq.h
index 2d0f7a0cdf..bfaa323968 100644
--- a/firmware/export/config/aigoerosq.h
+++ b/firmware/export/config/aigoerosq.h
@@ -15,6 +15,7 @@
/* define this if you have access to the quickscreen */
#define HAVE_QUICKSCREEN
+#define HAVE_HOTKEY
#define HAVE_HEADPHONE_DETECTION
#define HAVE_LINEOUT_DETECTION
diff --git a/firmware/export/config/fiiom3k.h b/firmware/export/config/fiiom3k.h
index 99285728a2..849aa9c0a6 100644
--- a/firmware/export/config/fiiom3k.h
+++ b/firmware/export/config/fiiom3k.h
@@ -10,25 +10,20 @@
/* CPU defines */
#define CONFIG_CPU X1000
#define X1000_EXCLK_FREQ 24000000
+#define CPU_FREQ 1008000000
#ifndef SIMULATOR
#define TIMER_FREQ X1000_EXCLK_FREQ
#endif
-#define CPU_FREQ 1008000000
-#define CPUFREQ_MAX CPU_FREQ
-/* TODO: figure out if this does in fact affect power consumption. */
-#define CPUFREQ_DEFAULT (CPUFREQ_MAX/4)
-#define CPUFREQ_NORMAL (CPUFREQ_MAX/4)
-#define HAVE_ADJUSTABLE_CPU_FREQ
-#define HAVE_GUI_BOOST
-
/* Kernel defines */
#define INCLUDE_TIMEOUT_API
#define HAVE_SEMAPHORE_OBJECTS
/* Drivers */
#define HAVE_I2C_ASYNC
+#define HAVE_FT6x06
+#define FT6x06_SWAP_AXES
/* Buffer for plugins and codecs. */
#define PLUGIN_BUFFER_SIZE 0x200000 /* 2 MiB */
@@ -97,7 +92,7 @@
#define HAVE_SW_POWEROFF
#ifndef SIMULATOR
-#define HAVE_AXP173
+#define HAVE_AXP_PMU 192
#define HAVE_POWEROFF_WHILE_CHARGING
#endif
@@ -108,9 +103,18 @@
#define BATTERY_CAPACITY_INC 0
#define BATTERY_TYPES_COUNT 1
-/* USB is still TODO. */
+/* USB support */
#ifndef SIMULATOR
-#define USB_NONE
+#define CONFIG_USBOTG USBOTG_DESIGNWARE
+#define USB_DW_ARCH_SLAVE
+#define USB_DW_TURNAROUND 5
+#define HAVE_USBSTACK
+#define USB_VENDOR_ID 0x2972
+#define USB_PRODUCT_ID 0x0003
+#define USB_DEVBSS_ATTR __attribute__((aligned(32)))
+#define HAVE_USB_POWER
+#define HAVE_USB_CHARGING_ENABLE
+#define HAVE_BOOTLOADER_USB_MODE
#endif
/* Rockbox capabilities */
@@ -122,4 +126,5 @@
#define HAVE_VOLUME_IN_LIST
#define HAVE_QUICKSCREEN
#define HAVE_HOTKEY
+#define HAVE_LOCKED_ACTIONS
#define AB_REPEAT_ENABLE
diff --git a/firmware/export/config/iaudio7.h b/firmware/export/config/iaudio7.h
deleted file mode 100644
index 698ff13724..0000000000
--- a/firmware/export/config/iaudio7.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * This config file is for the Iaudio7 series
- */
-
-/* For Rolo and boot loader */
-#define MODEL_NUMBER 32
-#define MODEL_NAME "Cowon iAudio7"
-
-/* define this if you have recording possibility */
-#define HAVE_RECORDING
-
-/* Define bitmask of input sources - recordable bitmask can be defined
- explicitly if different */
-#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN | SRC_CAP_FMRADIO)
-
-/* FM Tuner */
-#define CONFIG_TUNER LV24020LP
-#define HAVE_TUNER_PWR_CTRL
-
-/* Define this for FM radio input available */
-#define HAVE_FMRADIO_IN
-
-/* define hardware samples rate caps mask */
-#define HW_SAMPR_CAPS (/*SAMPR_CAP_88 | */SAMPR_CAP_44/* | SAMPR_CAP_22 | SAMPR_CAP_11*/)
-
-/* define the bitmask of recording sample rates */
-#define REC_SAMPR_CAPS (SAMPR_CAP_44/* | SAMPR_CAP_22 | SAMPR_CAP_11*/)
-
-
-
-
-/* define this if you have a colour LCD */
-#define HAVE_LCD_COLOR
-
-/* define this if you can flip your LCD */
-//#define HAVE_LCD_FLIP
-
-/* define this if you can invert the colours on your LCD */
-//#define HAVE_LCD_INVERT
-
-/* define this if you want album art for this target */
-#define HAVE_ALBUMART
-
-/* define this to enable bitmap scaling */
-#define HAVE_BMP_SCALING
-
-/* define this to enable JPEG decoding */
-#define HAVE_JPEG
-
-/* define this if you have access to the quickscreen */
-#define HAVE_QUICKSCREEN
-
-/* define this if you have LCD enable function */
-#define HAVE_LCD_ENABLE
-
-/* define this if you would like tagcache to build on this target */
-#define HAVE_TAGCACHE
-
-#define HAVE_FAT16SUPPORT
-
-#if 0 && !defined(SIMULATOR) /* Enable for USB driver test */
-#define HAVE_USBSTACK
-#define USB_VENDOR_ID 0x0e21
-#define USB_PRODUCT_ID 0x0750
-#endif
-
-/* define this if you have a flash memory storage */
-#define HAVE_FLASH_STORAGE
-
-#define CONFIG_STORAGE STORAGE_NAND
-
-#define CONFIG_NAND NAND_TCC
-
-/* LCD dimensions */
-#define LCD_WIDTH 160
-#define LCD_HEIGHT 128
-/* sqrt(160^2 + 128^2) / 1.3 = 157.6 */
-#define LCD_DPI 158
-/* 16bits for now... */
-#define LCD_DEPTH 16 /* 262144 colours */
-#define LCD_PIXELFORMAT RGB565 /*rgb565*/
-
-/*#define LCD_PIXELFORMAT VERTICAL_PACKING*/
-
-/* define this to indicate your device's keypad */
-#define CONFIG_KEYPAD IAUDIO67_PAD
-
-/* #define HAVE_BUTTON_DATA */
-
-/* define this if you have a real-time clock */
-#define CONFIG_RTC RTC_PCF50606
-
-/* define this if you have RTC RAM available for settings */
-//#define HAVE_RTC_RAM
-
-/* Define this if you have a software controlled poweroff */
-#define HAVE_SW_POWEROFF
-
-/* Reduce Tremor's ICODE usage */
-#define ICODE_ATTR_TREMOR_NOT_MDCT
-
-/* The number of bytes reserved for loadable codecs */
-#define CODEC_SIZE 0x100000
-
-/* The number of bytes reserved for loadable plugins */
-#define PLUGIN_BUFFER_SIZE 0x80000
-
-#define AB_REPEAT_ENABLE
-
-
-
-
-/* The iaudio7 uses built-in WM8731 codec */
-#define HAVE_WM8731
-/* Codec is slave on serial bus */
-#define CODEC_SLAVE
-
-/* WM8731 has no tone controls, so we use the software ones */
-#define HAVE_SW_TONE_CONTROLS
-
-/* Define this for LCD backlight available */
-#define HAVE_BACKLIGHT
-
-#define CONFIG_I2C I2C_TCC77X
-
-#define BATTERY_CAPACITY_DEFAULT 540 /* default battery capacity */
-#define BATTERY_CAPACITY_MIN 540 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 540 /* max. capacity selectable */
-#define BATTERY_CAPACITY_INC 50 /* capacity increment */
-#define BATTERY_TYPES_COUNT 1 /* only one type */
-
-#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
-
-#define CONFIG_CHARGING CHARGING_SIMPLE
-
-/* Define this if you have a TCC770 */
-#define CONFIG_CPU TCC770
-
-/* Define this if you have ATA power-off control */
-#define HAVE_ATA_POWER_OFF
-
-/* Define this to the CPU frequency */
-#define CPU_FREQ 120000000
-
-/* Offset ( in the firmware file's header ) to the file CRC */
-#define FIRMWARE_OFFSET_FILE_CRC 0
-
-/* Offset ( in the firmware file's header ) to the real data */
-#define FIRMWARE_OFFSET_FILE_DATA 8
-
-#define CONFIG_LCD LCD_IAUDIO67
-
-#define BOOTFILE_EXT "iaudio"
-#define BOOTFILE "rockbox." BOOTFILE_EXT
-#define BOOTDIR "/.rockbox"
-
-#ifdef BOOTLOADER
-#define TCCBOOT
-#endif
-
-#define IRAM_LCDFRAMEBUFFER IBSS_ATTR /* put the lcd frame buffer in IRAM */
-
-/* Define this if a programmable hotkey is mapped */
-//#define HAVE_HOTKEY
diff --git a/firmware/export/config/ibassodx50.h b/firmware/export/config/ibassodx50.h
index bb4b2809e5..2161d9f3e3 100644
--- a/firmware/export/config/ibassodx50.h
+++ b/firmware/export/config/ibassodx50.h
@@ -97,11 +97,9 @@
/* Which backlight fading type? */
#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
-
-
#define HAVE_SW_TONE_CONTROLS
#define HAVE_SW_VOLUME_CONTROL
-#define HW_SAMPR_CAPS SAMPR_CAP_ALL_96
+#define HW_SAMPR_CAPS SAMPR_CAP_ALL_192
//#define HAVE_MULTIMEDIA_KEYS
#define CONFIG_KEYPAD DX50_PAD
@@ -111,7 +109,7 @@
#define BATTERY_CAPACITY_DEFAULT 2100 /* default battery capacity */
#define BATTERY_CAPACITY_MIN 1700 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable */
+#define BATTERY_CAPACITY_MAX 7300 /* max. capacity selectable */
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
diff --git a/firmware/export/config/ibassodx90.h b/firmware/export/config/ibassodx90.h
index cd7ddf78cd..570a8d2a35 100644
--- a/firmware/export/config/ibassodx90.h
+++ b/firmware/export/config/ibassodx90.h
@@ -96,11 +96,9 @@
/* Which backlight fading type? */
#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
-
-
#define HAVE_SW_TONE_CONTROLS
#define HAVE_SW_VOLUME_CONTROL
-#define HW_SAMPR_CAPS SAMPR_CAP_ALL_96
+#define HW_SAMPR_CAPS SAMPR_CAP_ALL_192
//#define HAVE_MULTIMEDIA_KEYS
#define CONFIG_KEYPAD DX50_PAD
@@ -110,7 +108,7 @@
#define BATTERY_CAPACITY_DEFAULT 2100 /* default battery capacity */
#define BATTERY_CAPACITY_MIN 1700 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable */
+#define BATTERY_CAPACITY_MAX 7300 /* max. capacity selectable */
#define BATTERY_CAPACITY_INC 50 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
diff --git a/firmware/export/config/iriverifp7xx.h b/firmware/export/config/iriverifp7xx.h
deleted file mode 100644
index 0db9a7810d..0000000000
--- a/firmware/export/config/iriverifp7xx.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * This config file is for iriver iFP-799
- */
-
-#define IRIVER_IFP7XX_SERIES 1
-
-#define MODEL_NAME "iriver iFP-799"
-
-/* For Rolo and boot loader */
-#define MODEL_NUMBER 6
-
-/* define this if you have recording possibility */
-/*#define HAVE_RECORDING*/
-
-
-
-
-/* define this if you would like tagcache to build on this target */
-/* #define HAVE_TAGCACHE */
-
-/* LCD dimensions */
-#define LCD_WIDTH 128
-#define LCD_HEIGHT 64
-/* sqrt(128^2 + 64^2) / 1.0 = 143.1 */
-#define LCD_DPI 143
-#define LCD_DEPTH 1
-
-#define LCD_PIXELFORMAT VERTICAL_PACKING
-
-/* Display colours, for screenshots and sim (0xRRGGBB) */
-#define LCD_DARKCOLOR 0x000000
-#define LCD_BRIGHTCOLOR 0x5e6854
-#define LCD_BL_DARKCOLOR 0x000000
-#define LCD_BL_BRIGHTCOLOR 0x3ca0e6
-
-#define CONFIG_KEYPAD IRIVER_IFP7XX_PAD
-
-#define CONFIG_STORAGE STORAGE_NAND
-
-#define CONFIG_NAND NAND_IFP7XX
-
-#define HAVE_FAT16SUPPORT
-
-
-
-
-/* Define this if you have a software controlled poweroff */
-#define HAVE_SW_POWEROFF
-
-/* The number of bytes reserved for loadable codecs */
-#define CODEC_SIZE 0x38000
-
-/* The number of bytes reserved for loadable plugins */
-#define PLUGIN_BUFFER_SIZE 0x10000
-
-/* Define this if you have the WM8975 audio codec */
-/* #define HAVE_WM8975 */
-
-#define HAVE_LCD_CONTRAST
-
-#define MIN_CONTRAST_SETTING 5
-#define MAX_CONTRAST_SETTING 63
-#define DEFAULT_CONTRAST_SETTING 40
-
-/* define this if you have a flash memory storage */
-#define HAVE_FLASH_STORAGE
-
-#define BATTERY_CAPACITY_DEFAULT 1000 /* default battery capacity */
-#define BATTERY_CAPACITY_MIN 500 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 2800 /* max. capacity selectable */
-#define BATTERY_CAPACITY_INC 50 /* capacity increment */
-#define BATTERY_TYPES_COUNT 2 /* Alkalines or NiMH */
-
-#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
-
-/* define this if the unit should not shut down on low battery. */
-#define NO_LOW_BATTERY_SHUTDOWN
-
-/* Define this if you have a Philips PNX0101 */
-#define CONFIG_CPU PNX0101
-
-/* Define this if you want to use the PNX0101 i2c interface */
-#define CONFIG_I2C I2C_PNX0101
-
-/* The start address index for ROM builds */
-#define ROM_START 0x00000000
-
-/* Define this for LCD backlight available */
-#define HAVE_BACKLIGHT
-
-/* Define this to the CPU frequency */
-#define CPU_FREQ 48000000
-
-#define CONFIG_LCD LCD_IFP7XX
-
-/* Offset ( in the firmware file's header ) to the file length */
-#define FIRMWARE_OFFSET_FILE_LENGTH 0
-
-/* Offset ( in the firmware file's header ) to the file CRC */
-#define FIRMWARE_OFFSET_FILE_CRC 0
-
-/* Offset ( in the firmware file's header ) to the real data */
-#define FIRMWARE_OFFSET_FILE_DATA 8
-
-#define USB_ISP1582
-
-#define HAVE_GDB_API
-
-/* Define this if you have adjustable CPU frequency */
-#define HAVE_ADJUSTABLE_CPU_FREQ
-
-#define BOOTFILE_EXT "iriver"
-#define BOOTFILE "rockbox." BOOTFILE_EXT
-#define BOOTDIR "/.rockbox"
-
-#define IBSS_ATTR_VOICE_STACK
-#define ICODE_ATTR_TREMOR_NOT_MDCT
-#define ICODE_ATTR_TREMOR_MDCT
-#define ICODE_ATTR_FLAC
-#define IBSS_ATTR_FLAC_DECODED0
-#define ICONST_ATTR_MPA_HUFFMAN
-#define IBSS_ATTR_MPC_SAMPLE_BUF
-#define ICODE_ATTR_ALAC
-#define IBSS_ATTR_SHORTEN_DECODED0
-
-#define IRAM_LCDFRAMEBUFFER IBSS_ATTR /* put the lcd frame buffer in IRAM */
-
-/* Define this if a programmable hotkey is mapped */
-#define HAVE_HOTKEY
diff --git a/firmware/export/config/logikdax.h b/firmware/export/config/logikdax.h
deleted file mode 100644
index 47229f7a1d..0000000000
--- a/firmware/export/config/logikdax.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * This config file is for the Logik DAX MP3/DAB
- */
-
-/* For Rolo and boot loader */
-#define MODEL_NUMBER 33
-
-#define MODEL_NAME "Logik DAX MP3/DAB"
-
-/* define this if you have recording possibility */
-//#define HAVE_RECORDING
-
-/* Define bitmask of input sources - recordable bitmask can be defined
- explicitly if different */
-//#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN | SRC_CAP_SPDIF)
-
-#if 0 /* Enable for USB driver test */
-#define HAVE_USBSTACK
-#define USB_VENDOR_ID 0x13d1
-#define USB_PRODUCT_ID 0x1002
-#endif
-
-
-
-
-
-/* define this if you can flip your LCD */
-#define HAVE_LCD_FLIP
-
-/* define this if you can invert the colours on your LCD */
-#define HAVE_LCD_INVERT
-
-/* define this if you have access to the quickscreen */
-#define HAVE_QUICKSCREEN
-
-/* define this if you would like tagcache to build on this target */
-#define HAVE_TAGCACHE
-
-#define HAVE_FAT16SUPPORT
-
-/* define this if you have a flash memory storage */
-#define HAVE_FLASH_STORAGE
-
-#define CONFIG_STORAGE STORAGE_NAND
-
-#define CONFIG_NAND NAND_TCC
-
-/* LCD dimensions */
-#define LCD_WIDTH 128
-#define LCD_HEIGHT 64
-/* sqrt(128^2 + 64^2) / 1.0 = 143.1 */
-#define LCD_DPI 143
-#define LCD_DEPTH 1
-
-#define LCD_PIXELFORMAT VERTICAL_PACKING
-
-/* Display colours, for screenshots and sim (0xRRGGBB) */
-#define LCD_DARKCOLOR 0x000000
-#define LCD_BRIGHTCOLOR 0x5a915a
-#define LCD_BL_DARKCOLOR 0x000000
-#define LCD_BL_BRIGHTCOLOR 0x82b4fa
-
-/* define this to indicate your device's keypad */
-#define CONFIG_KEYPAD LOGIK_DAX_PAD
-
-/* define this if you have a real-time clock */
-#define CONFIG_RTC RTC_TCC77X
-
-/* define this if you have RTC RAM available for settings */
-//#define HAVE_RTC_RAM
-
-/* Define this if you have a software controlled poweroff */
-#define HAVE_SW_POWEROFF
-
-/* The number of bytes reserved for loadable codecs */
-#define CODEC_SIZE 0x38000
-
-/* The number of bytes reserved for loadable plugins */
-#define PLUGIN_BUFFER_SIZE 0x10000
-
-#define AB_REPEAT_ENABLE
-
-
-
-
-/* The DAX uses built-in WM8731 codec */
-#define HAVE_WM8731
-/* Codec is slave on serial bus */
-#define CODEC_SLAVE
-/* WM8731 has no tone controls, so we use the software ones */
-#define HAVE_SW_TONE_CONTROLS
-
-/* Define this for LCD backlight available */
-#define HAVE_BACKLIGHT
-
-#define CONFIG_I2C I2C_TCC77X
-
-#define BATTERY_CAPACITY_DEFAULT 1500 /* default battery capacity */
-#define BATTERY_CAPACITY_MIN 1500 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable */
-#define BATTERY_CAPACITY_INC 50 /* capacity increment */
-#define BATTERY_TYPES_COUNT 1 /* only one type */
-
-#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
-
-/* define this if the unit should not shut down on low battery. */
-#define NO_LOW_BATTERY_SHUTDOWN
-
-/* Define this if you have a TCC773L */
-#define CONFIG_CPU TCC773L
-
-/* Define this if you have ATA power-off control */
-#define HAVE_ATA_POWER_OFF
-
-#define HAVE_FAT16SUPPORT
-
-/* Define this to the CPU frequency */
-#define CPU_FREQ 120000000
-
-/* Offset ( in the firmware file's header ) to the file length */
-#define FIRMWARE_OFFSET_FILE_LENGTH 0
-
-/* Offset ( in the firmware file's header ) to the file CRC */
-#define FIRMWARE_OFFSET_FILE_CRC 4
-
-/* Offset ( in the firmware file's header ) to the real data */
-#define FIRMWARE_OFFSET_FILE_DATA 6
-
-/* The start address index for ROM builds */
-/* #define ROM_START 0x11010 for behind original Archos */
-#define ROM_START 0x7010 /* for behind BootBox */
-
-#define CONFIG_LCD LCD_SSD1815
-
-#define BOOTFILE_EXT "logik"
-#define BOOTFILE "rockbox." BOOTFILE_EXT
-#define BOOTDIR "/"
-
-#define IBSS_ATTR_VOICE_STACK
-#define ICODE_ATTR_TREMOR_NOT_MDCT
-#define ICODE_ATTR_TREMOR_MDCT
-#define ICODE_ATTR_FLAC
-#define IBSS_ATTR_FLAC_DECODED0
-#define ICONST_ATTR_MPA_HUFFMAN
-#define IBSS_ATTR_MPC_SAMPLE_BUF
-#define ICODE_ATTR_ALAC
-#define IBSS_ATTR_SHORTEN_DECODED0
-
-#define IRAM_LCDFRAMEBUFFER IBSS_ATTR /* put the lcd frame buffer in IRAM */
-
-/* Define this if a programmable hotkey is mapped */
-//#define HAVE_HOTKEY
diff --git a/firmware/export/config/sansac100.h b/firmware/export/config/sansac100.h
deleted file mode 100644
index c2956eed12..0000000000
--- a/firmware/export/config/sansac100.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * This config file is for the Sansa C100 series
- */
-
-#define MODEL_NAME "Sandisk Sansa c100 series"
-
-/* For Rolo and bootloader */
-#define MODEL_NUMBER 30
-
-/* define hardware samples rate caps mask */
-#define HW_SAMPR_CAPS (/*SAMPR_CAP_88 | */SAMPR_CAP_44/* | SAMPR_CAP_22 | SAMPR_CAP_11*/)
-
-
-
-
-/* define this if you have a colour LCD */
-#define HAVE_LCD_COLOR
-
-/* define this if you can flip your LCD */
-/*#define HAVE_LCD_FLIP*/
-
-/* define this if you can invert the colours on your LCD */
-/*#define HAVE_LCD_INVERT*/
-
-/* define this if you have access to the quickscreen */
-#define HAVE_QUICKSCREEN
-
-/* define this if you would like tagcache to build on this target */
-#define HAVE_TAGCACHE
-
-/* define this if you have a flash memory storage */
-#define HAVE_FLASH_STORAGE
-
-/* Only v1 */
-#define CONFIG_STORAGE STORAGE_NAND
-#define CONFIG_NAND NAND_TCC
-
-/* c100's with direct-to-NAND access are FAT16 */
-#define HAVE_FAT16SUPPORT
-
-/* LCD dimensions */
-#define LCD_WIDTH 128
-#define LCD_HEIGHT 64
-/* sqrt(128^2 + 64^2) / 1.7 = 84.2 */
-#define LCD_DPI 84
-#define LCD_DEPTH 16 /* 65536 colours */
-#define LCD_PIXELFORMAT RGB565 /*rgb565*/
-
-/*#define LCD_PIXELFORMAT VERTICAL_PACKING*/
-
-/* define this to indicate your device's keypad */
-#define CONFIG_KEYPAD SANSA_C100_PAD
-
-/* define this if you have a real-time clock */
-#define CONFIG_RTC RTC_TCC77X
-
-/* define this if you have RTC RAM available for settings */
-//#define HAVE_RTC_RAM
-
-/* Define this if you have a software controlled poweroff */
-#define HAVE_SW_POWEROFF
-
-/* The number of bytes reserved for loadable codecs */
-#define CODEC_SIZE 0x50000
-
-/* The number of bytes reserved for loadable plugins */
-#define PLUGIN_BUFFER_SIZE 0x50000
-
-#define AB_REPEAT_ENABLE
-
-
-
-
-/* Define this if you have the TLV320 audio codec */
-#define HAVE_TLV320
-
-/*#define CONFIG_TUNER TEA5767*/
-
-/* TLV320 has no tone controls, so we use the software ones */
-#define HAVE_SW_TONE_CONTROLS
-
-/* Define this for LCD backlight available */
-#define HAVE_BACKLIGHT
-
-#define CONFIG_I2C I2C_TCC77X
-
-#define BATTERY_CAPACITY_DEFAULT 540 /* default battery capacity */
-#define BATTERY_CAPACITY_MIN 540 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 540 /* max. capacity selectable */
-#define BATTERY_CAPACITY_INC 50 /* capacity increment */
-#define BATTERY_TYPES_COUNT 1 /* only one type */
-
-#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
-
-/* define this if the unit should not shut down on low battery. */
-#define NO_LOW_BATTERY_SHUTDOWN
-
-/* Define this if you have a TCC770 */
-#define CONFIG_CPU TCC770
-
-/* Define this if you have ATA power-off control */
-#define HAVE_ATA_POWER_OFF
-
-/* Define this to the CPU frequency */
-#define CPU_FREQ 120000000
-
-/* Offset ( in the firmware file's header ) to the file CRC */
-#define FIRMWARE_OFFSET_FILE_CRC 0
-
-/* Offset ( in the firmware file's header ) to the real data */
-#define FIRMWARE_OFFSET_FILE_DATA 8
-
-/* The start address index for ROM builds */
-/* #define ROM_START 0x11010 for behind original Archos */
-#define ROM_START 0x7010 /* for behind BootBox */
-
-#define CONFIG_LCD LCD_S6B33B2
-
-#define BOOTFILE_EXT "c100"
-#define BOOTFILE "rockbox." BOOTFILE_EXT
-#define BOOTDIR "/.rockbox"
-
-#ifdef BOOTLOADER
-#define TCCBOOT
-#endif
-
-#define IRAM_LCDFRAMEBUFFER IBSS_ATTR /* put the lcd frame buffer in IRAM */
-
-/* Define this if a programmable hotkey is mapped */
-#define HAVE_HOTKEY
diff --git a/firmware/export/config/sansaconnect.h b/firmware/export/config/sansaconnect.h
index 465a576664..5909d3bf84 100644
--- a/firmware/export/config/sansaconnect.h
+++ b/firmware/export/config/sansaconnect.h
@@ -147,7 +147,7 @@
#define BATTERY_CAPACITY_INC 100 /* capacity increment */
#define BATTERY_TYPES_COUNT 1 /* only one type */
-#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+#define CONFIG_BATTERY_MEASURE PERCENTAGE_MEASURE
/* define current usage levels */
#if 0
@@ -156,9 +156,6 @@
#define CURRENT_BACKLIGHT 200
#endif
-/* Hardware controlled charging with monitoring */
-//#define CONFIG_CHARGING CHARGING_MONITOR
-
#define CONFIG_CPU DM320
#define CONFIG_I2C I2C_DM320
@@ -182,11 +179,18 @@
/* Offset ( in the firmware file's header ) to the real data */
#define FIRMWARE_OFFSET_FILE_DATA 8
-#if 0
+/* Hardware controlled charging */
+#define CONFIG_CHARGING CHARGING_MONITOR
+
+#define CONFIG_USBOTG USBOTG_TNETV105
+
#define HAVE_USBSTACK
+#define HAVE_USB_POWER
+#define HAVE_USB_CHARGING_ENABLE
+#define HAVE_BOOTLOADER_USB_MODE
#define USB_VENDOR_ID 0x0781
#define USB_PRODUCT_ID 0x7480
-#endif
+#define USB_NUM_ENDPOINTS 5
#define INCLUDE_TIMEOUT_API
diff --git a/firmware/export/config/sansam200.h b/firmware/export/config/sansam200.h
deleted file mode 100644
index 95647013e7..0000000000
--- a/firmware/export/config/sansam200.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * This config file is for the Sansa M200 series
- */
-
-/* For Rolo and boot loader */
-#define MODEL_NUMBER 29
-
-#define MODEL_NAME "Sandisk Sansa m200 series"
-
-/* Enable FAT16 support */
-#define HAVE_FAT16SUPPORT
-
-/* define this if you have recording possibility */
-//#define HAVE_RECORDING
-
-/* Define bitmask of input sources - recordable bitmask can be defined
- explicitly if different */
-//#define INPUT_SRC_CAPS (SRC_CAP_MIC | SRC_CAP_LINEIN | SRC_CAP_SPDIF)
-
-
-
-
-/* define this if you can flip your LCD */
-#define HAVE_LCD_FLIP
-
-/* define this if you can invert the colours on your LCD */
-#define HAVE_LCD_INVERT
-
-/* define this if you have access to the quickscreen */
-#define HAVE_QUICKSCREEN
-
-/* define this if you would like tagcache to build on this target */
-#define HAVE_TAGCACHE
-
-/* define this if you have a flash memory storage */
-#define HAVE_FLASH_STORAGE
-
-#define CONFIG_STORAGE STORAGE_NAND
-
-#define CONFIG_NAND NAND_TCC
-
-/* LCD dimensions */
-#define LCD_WIDTH 128
-#define LCD_HEIGHT 64
-/* sqrt(128^2 + 64^2) / 1.8 = 79.5 */
-#define LCD_DPI 80
-#define LCD_DEPTH 1
-
-#define LCD_PIXELFORMAT VERTICAL_PACKING
-
-/* Display colours, for screenshots and sim (0xRRGGBB) */
-#define LCD_BARKCOLOR 0x000000
-#define LCD_BRIGHTCOLOR 0x5e6854
-#define LCD_BL_DARKCOLOR 0x000000
-#define LCD_BL_BRIGHTCOLOR 0x3ca0e6
-
-/* define this to indicate your device's keypad */
-#define CONFIG_KEYPAD SANSA_M200_PAD
-
-/* Define this to enable morse code input */
-#define HAVE_MORSE_INPUT
-
-/* define this if you have a real-time clock */
-#define CONFIG_RTC RTC_TCC77X
-
-/* define this if you have RTC RAM available for settings */
-//#define HAVE_RTC_RAM
-
-/* Define this if you have a software controlled poweroff */
-#define HAVE_SW_POWEROFF
-
-/* The number of bytes reserved for loadable codecs */
-#define CODEC_SIZE 0x38000
-
-/* The number of bytes reserved for loadable plugins */
-#define PLUGIN_BUFFER_SIZE 0x10000
-
-#define AB_REPEAT_ENABLE
-
-
-
-
-/* Define this if you have the TLV320 audio codec */
-#define HAVE_TLV320
-
-/* TLV320 has no tone controls, so we use the software ones */
-#define HAVE_SW_TONE_CONTROLS
-
-/* Define this for LCD backlight available */
-#define HAVE_BACKLIGHT
-
-#define CONFIG_I2C I2C_TCC77X
-
-#define BATTERY_CAPACITY_DEFAULT 1500 /* default battery capacity */
-#define BATTERY_CAPACITY_MIN 1500 /* min. capacity selectable */
-#define BATTERY_CAPACITY_MAX 3200 /* max. capacity selectable */
-#define BATTERY_CAPACITY_INC 50 /* capacity increment */
-#define BATTERY_TYPES_COUNT 1 /* only one type */
-
-#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
-
-/* define this if the unit should not shut down on low battery. */
-#define NO_LOW_BATTERY_SHUTDOWN
-
-/* Define this if you have a TCC770 */
-#define CONFIG_CPU TCC770
-
-/* Define this if you have ATA power-off control */
-#define HAVE_ATA_POWER_OFF
-
-/* Define this to the CPU frequency */
-#define CPU_FREQ 120000000
-
-/* Offset ( in the firmware file's header ) to the file CRC */
-#define FIRMWARE_OFFSET_FILE_CRC 0
-
-/* Offset ( in the firmware file's header ) to the real data */
-#define FIRMWARE_OFFSET_FILE_DATA 8
-
-#define CONFIG_LCD LCD_SSD1815
-
-#define BOOTFILE_EXT "m200"
-#define BOOTFILE "rockbox." BOOTFILE_EXT
-#define BOOTDIR "/"
-
-#define IBSS_ATTR_VOICE_STACK
-#define ICODE_ATTR_TREMOR_NOT_MDCT
-#define ICODE_ATTR_TREMOR_MDCT
-#define ICODE_ATTR_FLAC
-#define IBSS_ATTR_FLAC_DECODED0
-#define ICONST_ATTR_MPA_HUFFMAN
-#define IBSS_ATTR_MPC_SAMPLE_BUF
-#define ICODE_ATTR_ALAC
-#define IBSS_ATTR_SHORTEN_DECODED0
-
-#define IRAM_LCDFRAMEBUFFER IBSS_ATTR /* put the lcd frame buffer in IRAM */
-
-/* Define this if a programmable hotkey is mapped */
-#define HAVE_HOTKEY
diff --git a/firmware/export/cpu.h b/firmware/export/cpu.h
index aade199dd2..67509141aa 100644
--- a/firmware/export/cpu.h
+++ b/firmware/export/cpu.h
@@ -50,9 +50,6 @@
#if CONFIG_CPU == IMX31L
#include "imx31l.h"
#endif
-#ifdef CPU_TCC77X
-#include "tcc77x.h"
-#endif
#ifdef CPU_TCC780X
#include "tcc780x.h"
#endif
@@ -80,3 +77,6 @@
#if CONFIG_CPU == RK27XX
#include "rk27xx.h"
#endif
+#if CONFIG_CPU == X1000
+#include "x1000.h"
+#endif
diff --git a/firmware/export/dm320.h b/firmware/export/dm320.h
index def8508b0b..01f206bfc9 100644
--- a/firmware/export/dm320.h
+++ b/firmware/export/dm320.h
@@ -930,11 +930,27 @@ extern unsigned long _ttbstart;
#define MMC_ST1_DXFULL (1 << 3)
#define MMC_ST1_DAT3ST (1 << 4)
+#define MMC_IE_EDATDNE (1 << 0)
+#define MMC_IE_EBSYDNE (1 << 1)
+#define MMC_IE_ERSPDNE (1 << 2)
+#define MMC_IE_ETOUTRD (1 << 3)
+#define MMC_IE_ETOUTRS (1 << 4)
+#define MMC_IE_ECRCWR (1 << 5)
+#define MMC_IE_ECRCRD (1 << 6)
+#define MMC_IE_ECRCRS (1 << 7)
+#define MMC_IE_EDXRDY (1 << 9)
+#define MMC_IE_EDRRDY (1 << 10)
+#define MMC_IE_EDATED (1 << 11)
+
#define MMC_DMAMODE_RD_WORDSWAP (1 << 10)
#define MMC_DMAMODE_WR_WORDSWAP (1 << 11)
#define MMC_DMAMODE_WRITE (1 << 12)
#define MMC_DMAMODE_ENABLE (1 << 13)
#define MMC_DMAMODE_TIMEOUTIRQ_EN (1 << 14)
+
+#define MMC_DMASTAT1_RUNST (1 << 12)
+#define MMC_DMASTAT1_TOUTDT (1 << 13)
+
/*
* IO_EINTx bits
*/
@@ -1001,6 +1017,7 @@ extern unsigned long _ttbstart;
#define INTR_IRQ1_EXT0 INTR_EINT1_EXT0
#define INTR_IRQ1_EXT2 INTR_EINT1_EXT2
#define INTR_IRQ1_EXT7 INTR_EINT1_EXT7
+#define INTR_IRQ1_MMCSDMS0 INTR_EINT1_MMCSDMS0
#define INTR_IRQ1_MTC0 INTR_EINT1_MTC0
/*
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c b/firmware/export/ft6x06.h
index 0bfcdf3b1a..de1fdd0979 100644
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
+++ b/firmware/export/ft6x06.h
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id$
*
- * Copyright (C) 2006 by Barry Wardell
+ * Copyright (C) 2021 Aidan MacDonald
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -18,32 +18,33 @@
* KIND, either express or implied.
*
****************************************************************************/
+
+#ifndef __FT6x06_H__
+#define __FT6x06_H__
+
#include "config.h"
-#include "cpu.h"
-#include "kernel.h"
-#include "thread.h"
-#include "system.h"
-#include "debug.h"
-#include "ata.h"
-#include "disk.h"
-#include "panic.h"
-#include "lcd.h"
-#include "usb.h"
-#include "button.h"
-#include "string.h"
-
-void usb_init_device(void)
-{
-}
-
-int usb_detect(void)
-{
- /* TODO: Implement USB_ISP1582 */
- return USB_EXTRACTED;
-}
-
-void usb_enable(bool on)
-{
- /* TODO: Implement USB_ISP1582 */
- (void)on;
-}
+#include <stdbool.h>
+
+typedef void(*ft6x06_event_cb)(int, int, int);
+
+struct ft6x06_state {
+ int event;
+ int pos_x;
+ int pos_y;
+};
+
+enum ft6x06_event {
+ FT6x06_EVT_NONE = -1,
+ FT6x06_EVT_PRESS = 0,
+ FT6x06_EVT_RELEASE = 1,
+ FT6x06_EVT_CONTACT = 2,
+};
+
+extern struct ft6x06_state ft6x06_state;
+
+void ft6x06_init(void);
+void ft6x06_set_event_cb(ft6x06_event_cb fn);
+void ft6x06_enable(bool en);
+void ft6x06_irq_handler(void);
+
+#endif /* __FT6x06_H__ */
diff --git a/firmware/export/gdb_api.h b/firmware/export/gdb_api.h
index 1836c5992e..d2358ee3bb 100644
--- a/firmware/export/gdb_api.h
+++ b/firmware/export/gdb_api.h
@@ -25,9 +25,6 @@
#include "config.h"
#define GDB_API_MAGIC 0x6db570b
-#ifdef IRIVER_IFP7XX_SERIES
-#define GDB_API_ADDRESS 0xc06000
-#endif
struct gdb_api
{
diff --git a/firmware/export/ifp_usb_serial.h b/firmware/export/ifp_usb_serial.h
deleted file mode 100644
index b56e5fff86..0000000000
--- a/firmware/export/ifp_usb_serial.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2006 by Tomasz Malesinski
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _USB_SERIAL_H_
-#define _USB_SERIAL_H_
-
-void usb_serial_init(void);
-void usb_serial_put_byte(int b);
-int usb_serial_get_byte(void);
-int usb_serial_try_put_byte(int b);
-int usb_serial_try_get_byte(void);
-
-#endif
diff --git a/firmware/export/installer.h b/firmware/export/installer.h
deleted file mode 100644
index 802798618d..0000000000
--- a/firmware/export/installer.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2021 Aidan MacDonald
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#ifndef _INSTALLER_H_
-#define _INSTALLER_H_
-
-/* Provisional interface for installing/dumping a bootloader */
-
-extern int install_bootloader(const char* path);
-extern int dump_bootloader(const char* path);
-extern const char* installer_strerror(int rc);
-
-#endif /* _INSTALLER_H_ */
diff --git a/firmware/export/tcc77x.h b/firmware/export/tcc77x.h
deleted file mode 100644
index 3c457c5b38..0000000000
--- a/firmware/export/tcc77x.h
+++ /dev/null
@@ -1,262 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef __TCC77X_H__
-#define __TCC77X_H__
-
-#define CACHEALIGN_BITS (5)
-
-/* General-purpose IO */
-
-#define GPIOA (*(volatile unsigned long *)0x80000300)
-#define GPIOB (*(volatile unsigned long *)0x80000310)
-#define GPIOC (*(volatile unsigned long *)0x80000320)
-#define GPIOD (*(volatile unsigned long *)0x80000330)
-#define GPIOE (*(volatile unsigned long *)0x80000340)
-
-#define GPIOA_DIR (*(volatile unsigned long *)0x80000304)
-#define GPIOB_DIR (*(volatile unsigned long *)0x80000314)
-#define GPIOC_DIR (*(volatile unsigned long *)0x80000324)
-#define GPIOD_DIR (*(volatile unsigned long *)0x80000334)
-#define GPIOE_DIR (*(volatile unsigned long *)0x80000344)
-
-#define GPIOA_FUNC (*(volatile unsigned long *)0x80000308)
-#define GPIOB_FUNC (*(volatile unsigned long *)0x80000318)
-#define GPIOC_FUNC (*(volatile unsigned long *)0x80000328)
-#define GPIOD_FUNC (*(volatile unsigned long *)0x80000338)
-#define GPIOE_FUNC (*(volatile unsigned long *)0x80000348)
-
-#define BMI (*(volatile unsigned long *)0x80000364)
-
-/* Clock Generator */
-
-#define CLKCTRL (*(volatile unsigned long *)0x80000400)
-#define PLL0CFG (*(volatile unsigned long *)0x80000404)
-#define CLKDIVC (*(volatile unsigned long *)0x8000040c)
-#define MODECTR (*(volatile unsigned long *)0x80000410)
-#define BCLKCTR (*(volatile unsigned long *)0x80000414)
-#define SWRESET (*(volatile unsigned long *)0x80000418)
-#define PCLKCFG0 (*(volatile unsigned long *)0x8000041c)
-#define PCLKCFG1 (*(volatile unsigned long *)0x80000420)
-#define PCLKCFG2 (*(volatile unsigned long *)0x80000424)
-#define PCLKCFG3 (*(volatile unsigned long *)0x80000428)
-#define PCLKCFG4 (*(volatile unsigned long *)0x8000042c)
-#define PCLKCFG5 (*(volatile unsigned long *)0x80000430)
-#define PCLKCFG6 (*(volatile unsigned long *)0x80000434)
-
-#define PCLK_DAI PCLKCFG6
-
-/* Device bits for SWRESET & BCLKCTR */
-
-#define DEV_DAI (1<<0)
-#define DEV_USBD (1<<4)
-#define DEV_ECC (1<<9)
-#define DEV_NAND (1<<16)
-
-/* ADC */
-
-#define ADCCON (*(volatile unsigned long *)0x80000a00)
-#define ADCDATA (*(volatile unsigned long *)0x80000a04)
-#define ADCCONA (*(volatile unsigned long *)0x80000a80)
-#define ADCSTATUS (*(volatile unsigned long *)0x80000a84)
-#define ADCCFG (*(volatile unsigned long *)0x80000a88)
-
-
-/* Memory Controller */
-#define SDCFG (*(volatile unsigned long *)0xf0000000)
-#define SDFSM (*(volatile unsigned long *)0xf0000004)
-#define MCFG (*(volatile unsigned long *)0xf0000008)
-#define TST (*(volatile unsigned long *)0xf000000c)
-#define CSCFG0 (*(volatile unsigned long *)0xf0000010)
-#define CSCFG1 (*(volatile unsigned long *)0xf0000014)
-#define CSCFG2 (*(volatile unsigned long *)0xf0000018)
-#define CSCFG3 (*(volatile unsigned long *)0xf000001c)
-#define CLKCFG (*(volatile unsigned long *)0xf0000020)
-#define SDCMD (*(volatile unsigned long *)0xf0000024)
-
-
-/* IRQ Controller */
-#define EXT0_IRQ_MASK (1<<0)
-#define EXT1_IRQ_MASK (1<<1)
-#define EXT2_IRQ_MASK (1<<2)
-#define EXT3_IRQ_MASK (1<<3)
-#define I2SR_IRQ_MASK (1<<4)
-#define I2ST_IRQ_MASK (1<<5)
-#define TIMER0_IRQ_MASK (1<<6)
-#define USBD_IRQ_MASK (1<<8) /* USB 2.0 device */
-#define USBH_IRQ_MASK (1<<10) /* USB 1.1 host */
-#define ADC_IRQ_MASK (1<<16)
-#define USB_DMA_IRQ_MASK (1<<26) /* USB DMA */
-#define ECC_IRQ_MASK (1<<27)
-
-#define DAI_RX_IRQ_MASK I2SR_IRQ_MASK
-#define DAI_TX_IRQ_MASK I2ST_IRQ_MASK
-
-#define USB_DMA_IRQ_MASK (1<<26) /* USB DMA */
-
-#define IEN (*(volatile unsigned long *)0x80000100)
-#define CREQ (*(volatile unsigned long *)0x80000104)
-#define IREQ (*(volatile unsigned long *)0x80000108)
-#define IRQSEL (*(volatile unsigned long *)0x8000010c)
-#define ICFG (*(volatile unsigned long *)0x80000110)
-#define MREQ (*(volatile unsigned long *)0x80000114)
-#define TSTREQ (*(volatile unsigned long *)0x80000118)
-#define IRQ (*(volatile unsigned long *)0x80000120)
-#define FIQ (*(volatile unsigned long *)0x80000124)
-#define MIRQ (*(volatile unsigned long *)0x80000128)
-#define MFIQ (*(volatile unsigned long *)0x8000012c)
-#define TMODE (*(volatile unsigned long *)0x80000130)
-#define SYNC (*(volatile unsigned long *)0x80000134)
-#define WKUP (*(volatile unsigned long *)0x80000138)
-
-/* Timer Controller */
-
-#define TCFG0 (*(volatile unsigned long *)0x80000200)
-#define TCNT0 (*(volatile unsigned long *)0x80000204)
-#define TREF0 (*(volatile unsigned long *)0x80000208)
-#define TMREF0 (*(volatile unsigned long *)0x8000020c)
-#define TCFG1 (*(volatile unsigned long *)0x80000210)
-#define TCNT1 (*(volatile unsigned long *)0x80000214)
-#define TREF1 (*(volatile unsigned long *)0x80000218)
-#define TMREF1 (*(volatile unsigned long *)0x8000021c)
-#define TCFG2 (*(volatile unsigned long *)0x80000220)
-#define TCNT2 (*(volatile unsigned long *)0x80000224)
-#define TREF2 (*(volatile unsigned long *)0x80000228)
-#define TMREF2 (*(volatile unsigned long *)0x8000022c)
-#define TCFG3 (*(volatile unsigned long *)0x80000230)
-#define TCNT3 (*(volatile unsigned long *)0x80000234)
-#define TREF3 (*(volatile unsigned long *)0x80000238)
-#define TMREF3 (*(volatile unsigned long *)0x8000023c)
-#define TCFG4 (*(volatile unsigned long *)0x80000240)
-#define TCNT4 (*(volatile unsigned long *)0x80000244)
-#define TREF4 (*(volatile unsigned long *)0x80000248)
-#define TCFG5 (*(volatile unsigned long *)0x80000250)
-#define TCNT5 (*(volatile unsigned long *)0x80000254)
-#define TREF5 (*(volatile unsigned long *)0x80000258)
-#define TIREQ (*(volatile unsigned long *)0x80000260)
-#define TWDCFG (*(volatile unsigned long *)0x80000270)
-#define TWDCLR (*(volatile unsigned long *)0x80000274)
-#define TC32EN (*(volatile unsigned long *)0x80000280)
-#define TC32LDV (*(volatile unsigned long *)0x80000284)
-#define TC32CMP0 (*(volatile unsigned long *)0x80000288)
-#define TC32CMP1 (*(volatile unsigned long *)0x8000028c)
-#define TC32PCNT (*(volatile unsigned long *)0x80000290)
-#define TC32MCNT (*(volatile unsigned long *)0x80000294)
-#define TC32IRQ (*(volatile unsigned long *)0x80000298)
-
-/* TIREQ flags */
-#define TF0 (1<<8) /* Timer 0 reference value reached */
-#define TF1 (1<<9) /* Timer 1 reference value reached */
-#define TI0 (1<<0) /* Timer 0 IRQ flag */
-#define TI1 (1<<1) /* Timer 1 IRQ flag */
-
-/* NAND Flash Controller */
-
-#define NFC_CMD (*(volatile unsigned long *)0x90000000)
-#define NFC_SADDR (*(volatile unsigned long *)0x9000000C)
-#define NFC_SDATA (*(volatile unsigned long *)0x90000040)
-#define NFC_WDATA (*(volatile unsigned long *)0x90000010)
-#define NFC_CTRL (*(volatile unsigned long *)0x90000050)
- #define NFC_16BIT (1<<26)
- #define NFC_CS0 (1<<23)
- #define NFC_CS1 (1<<22)
- #define NFC_READY (1<<20)
-#define NFC_IREQ (*(volatile unsigned long *)0x90000060)
-#define NFC_RST (*(volatile unsigned long *)0x90000064)
-
-
-/* ECC controller */
-
-#define ECC_CTRL (*(volatile unsigned long *)0x80000900)
- #define ECC_DMA_REQ (1<<28)
- #define ECC_ENC (1<<27) /* MLC ECC3/4 */
- #define ECC_READY (1<<26)
- #define ECC_IEN (1<<25)
- #define ECC_MANUAL (1<<22)
- #define ECC_WCNT (1<<12) /* [21:12] */
- #define ECC_HOLD (1<<7)
- #define ECC_M4EN (1<<6)
- #define ECC_ZERO (1<<5)
- #define ECC_M3EN (1<<4)
- #define ECC_CNT_MASK (7<<1)
- #define ECC_CNT (1<<1)
- #define ECC_SLC (1<<0)
-
-#define ECC_BASE (*(volatile unsigned long *)0x80000904)
-#define ECC_MASK (*(volatile unsigned long *)0x80000908)
-#define ECC_CLR (*(volatile unsigned long *)0x8000090c)
-#define SLC_ECC0 (*(volatile unsigned long *)0x80000910)
-#define SLC_ECC1 (*(volatile unsigned long *)0x80000914)
-#define SLC_ECC2 (*(volatile unsigned long *)0x80000918)
-#define SLC_ECC3 (*(volatile unsigned long *)0x8000091c)
-#define SLC_ECC4 (*(volatile unsigned long *)0x80000920)
-#define SLC_ECC5 (*(volatile unsigned long *)0x80000924)
-#define SLC_ECC6 (*(volatile unsigned long *)0x80000928)
-#define SLC_ECC7 (*(volatile unsigned long *)0x8000092c)
-#define MLC_ECC0W (*(volatile unsigned long *)0x80000930)
-#define MLC_ECC1W (*(volatile unsigned long *)0x80000934)
-#define MLC_ECC2W (*(volatile unsigned long *)0x80000938)
-#define MLC_ECC0R (*(volatile unsigned long *)0x80000940)
-#define MLC_ECC1R (*(volatile unsigned long *)0x80000944)
-#define MLC_ECC2R (*(volatile unsigned long *)0x80000948)
-#define ECC_CORR_START (*(volatile unsigned long *)0x8000094c)
-#define ECC_ERRADDR(x) (*(volatile unsigned long *)(0x80000950+4*(x)))
-#define ECC_ERRDATA(x) (*(volatile unsigned long *)(0x80000960+4*(x)))
-#define ECC_ERR_NUM (*(volatile unsigned long *)0x80000970)
-
-
-/* Digital Audio Interface */
-#define DADI_L0 (*(volatile unsigned long *)0x80000000)
-#define DADI_R0 (*(volatile unsigned long *)0x80000004)
-#define DADI_L1 (*(volatile unsigned long *)0x80000008)
-#define DADI_R1 (*(volatile unsigned long *)0x8000000C)
-#define DADI_L2 (*(volatile unsigned long *)0x80000010)
-#define DADI_R2 (*(volatile unsigned long *)0x80000014)
-#define DADI_L3 (*(volatile unsigned long *)0x80000018)
-#define DADI_R3 (*(volatile unsigned long *)0x8000001c)
-
-#define DADO_L0 (*(volatile unsigned long *)0x80000020)
-#define DADO_R0 (*(volatile unsigned long *)0x80000024)
-#define DADO_L1 (*(volatile unsigned long *)0x80000028)
-#define DADO_R1 (*(volatile unsigned long *)0x8000002C)
-#define DADO_L2 (*(volatile unsigned long *)0x80000030)
-#define DADO_R2 (*(volatile unsigned long *)0x80000034)
-#define DADO_L3 (*(volatile unsigned long *)0x80000038)
-#define DADO_R3 (*(volatile unsigned long *)0x8000003c)
-
-#define DAMR (*(volatile unsigned long *)0x80000040)
-#define DAVC (*(volatile unsigned long *)0x80000044)
-
-#define DADI_L(x) (*(volatile unsigned long *)(0x80000000 + (x) * 8))
-#define DADI_R(x) (*(volatile unsigned long *)(0x80000004 + (x) * 8))
-#define DADO_L(x) (*(volatile unsigned long *)(0x80000020 + (x) * 8))
-#define DADO_R(x) (*(volatile unsigned long *)(0x80000024 + (x) * 8))
-
-/* USB 2.0 device system MMR base address */
-#define USB_BASE 0x90000b00
-
-#define USB_NUM_ENDPOINTS 3
-#define USB_DEVBSS_ATTR IBSS_ATTR
-
-/* Timer frequency */
-/* timers are based on XIN (12Mhz) */
-#define TIMER_FREQ (12000000)
-
-#endif
diff --git a/firmware/export/ucl_decompress.h b/firmware/export/ucl_decompress.h
new file mode 100644
index 0000000000..bea7564a94
--- /dev/null
+++ b/firmware/export/ucl_decompress.h
@@ -0,0 +1,32 @@
+/* Standalone UCL decompressor and uclpack-compatible unpacker,
+ * adapted for Rockbox from the libucl code.
+ *
+ * Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
+ * All Rights Reserved.
+ *
+ * See firmware/common/ucl_decompress.c for full copyright notice
+ */
+#ifndef UCL_DECOMPRESS_H
+#define UCL_DECOMPRESS_H
+
+#include <stdint.h>
+#include <stdlib.h>
+
+#define UCL_E_OK 0
+#define UCL_E_INPUT_OVERRUN 1
+#define UCL_E_OUTPUT_OVERRUN 2
+#define UCL_E_LOOKBEHIND_OVERRUN 3
+#define UCL_E_INPUT_NOT_CONSUMED 4
+#define UCL_E_BAD_MAGIC 5
+#define UCL_E_BAD_BLOCK_SIZE 6
+#define UCL_E_UNSUPPORTED_METHOD 7
+#define UCL_E_TRUNCATED 8
+#define UCL_E_CORRUPTED 9
+
+extern int ucl_nrv2e_decompress_8(const uint8_t* src, uint32_t src_len,
+ uint8_t* dst, uint32_t* dst_len);
+
+extern int ucl_unpack(const uint8_t* src, uint32_t src_len,
+ uint8_t* dst, uint32_t* dst_len);
+
+#endif /* UCL_DECOMPRESS_H */
diff --git a/firmware/export/usb_ch9.h b/firmware/export/usb_ch9.h
index c11775b893..659bcca101 100644
--- a/firmware/export/usb_ch9.h
+++ b/firmware/export/usb_ch9.h
@@ -391,6 +391,23 @@ struct usb_debug_descriptor {
} __attribute__((packed));
/*-------------------------------------------------------------------------*/
+
+/* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */
+struct usb_interface_assoc_descriptor {
+ uint8_t bLength;
+ uint8_t bDescriptorType;
+
+ uint8_t bFirstInterface;
+ uint8_t bInterfaceCount;
+ uint8_t bFunctionClass;
+ uint8_t bFunctionSubClass;
+ uint8_t bFunctionProtocol;
+ uint8_t iFunction;
+} __attribute__ ((packed));
+
+#define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
+
+/*-------------------------------------------------------------------------*/
/* USB 2.0 defines three speeds, here's how Linux identifies them */
enum usb_device_speed {
diff --git a/firmware/export/x1000.h b/firmware/export/x1000.h
new file mode 100644
index 0000000000..102d4ec978
--- /dev/null
+++ b/firmware/export/x1000.h
@@ -0,0 +1,72 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2021 Aidan MacDonald
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef __X1000_H__
+#define __X1000_H__
+
+#include "config.h"
+
+/* Frequency of external oscillator EXCLK */
+//#define X1000_EXCLK_FREQ 24000000
+
+/* Maximum CPU frequency that can be achieved on the target */
+//#define CPU_FREQ 1008000000
+
+/* Only 24 MHz and 26 MHz external oscillators are supported by the X1000 */
+#if X1000_EXCLK_FREQ == 24000000
+# define X1000_EXCLK_24MHZ
+#elif X1000_EXCLK_FREQ == 26000000
+# define X1000_EXCLK_26MHZ
+#else
+# error "Unsupported EXCLK freq"
+#endif
+
+/* On-chip TCSM (tightly coupled shared memory), aka IRAM */
+#define X1000_TCSM_BASE 0xf4000000
+#define X1000_TCSM_SIZE (16 * 1024)
+
+/* External SDRAM */
+#define X1000_SDRAM_BASE 0x80000000
+#define X1000_SDRAM_SIZE (MEMORYSIZE * 1024 * 1024)
+
+/* Memory definitions for Rockbox */
+#define X1000_IRAM_BASE X1000_SDRAM_BASE
+#define X1000_IRAM_SIZE (16 * 1024)
+#define X1000_IRAM_END (X1000_IRAM_BASE + X1000_IRAM_SIZE)
+#define X1000_DRAM_BASE X1000_IRAM_END
+#define X1000_DRAM_SIZE (X1000_SDRAM_SIZE - X1000_IRAM_SIZE)
+#define X1000_DRAM_END (X1000_DRAM_BASE + X1000_DRAM_SIZE)
+#define X1000_STACKSIZE 0x1e00
+#define X1000_IRQSTACKSIZE 0x300
+
+/* Convert kseg0 address to physical address or uncached address */
+#define PHYSADDR(x) ((unsigned long)(x) & 0x1fffffff)
+#define UNCACHEDADDR(x) (PHYSADDR(x) | 0xa0000000)
+
+/* Defines for usb-designware driver */
+#define OTGBASE 0xb3500000
+#define USB_NUM_ENDPOINTS 9
+
+/* CPU cache parameters */
+#define CACHEALIGN_BITS 5
+#define CACHE_SIZE (16 * 1024)
+
+#endif /* __X1000_H__ */
diff --git a/firmware/ifp_usb_serial.c b/firmware/ifp_usb_serial.c
deleted file mode 100644
index f7e3a51858..0000000000
--- a/firmware/ifp_usb_serial.c
+++ /dev/null
@@ -1,1121 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2006 by Tomasz Malesinski
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-/*
-#define LCD_DEBUG
-#define BUTTONS
-*/
-
-/* #include "config.h" */
-#include <stdlib.h>
-#include "pnx0101.h"
-#include "ifp_usb_serial.h"
-
-#ifdef BUTTONS
-#include "kernel.h"
-#include "button.h"
-#include "system.h"
-#endif
-
-#ifdef LCD_DEBUG
-#include "lcd.h"
-#endif
-
-
-#define ISP1582_BASE (0x24100000)
-#define ISP1582_ADDRESS (*(volatile unsigned char *)ISP1582_BASE)
-#define ISP1582_MODE (*(volatile unsigned short *)(ISP1582_BASE + 0xc))
-#define ISP1582_INTCONF (*(volatile unsigned char *)(ISP1582_BASE + 0x10))
-#define ISP1582_OTG (*(volatile unsigned char *)(ISP1582_BASE + 0x12))
-#define ISP1582_INTEN (*(volatile unsigned long *)(ISP1582_BASE + 0x14))
-
-#define ISP1582_EPINDEX (*(volatile unsigned char *)(ISP1582_BASE + 0x2c))
-#define ISP1582_CTRLFUN (*(volatile unsigned char *)(ISP1582_BASE + 0x28))
-#define ISP1582_DATA (*(volatile unsigned short *)(ISP1582_BASE + 0x20))
-#define ISP1582_BUFLEN (*(volatile unsigned short *)(ISP1582_BASE + 0x1c))
-#define ISP1582_BUFSTAT (*(volatile unsigned char *)(ISP1582_BASE + 0x1e))
-#define ISP1582_MAXPKSZ (*(volatile unsigned short *)(ISP1582_BASE + 0x04))
-#define ISP1582_EPTYPE (*(volatile unsigned short *)(ISP1582_BASE + 0x08))
-
-#define ISP1582_INT (*(volatile unsigned long *)(ISP1582_BASE + 0x18))
-#define ISP1582_CHIPID (*(volatile unsigned long *)(ISP1582_BASE + 0x70))
-#define ISP1582_FRAMENO (*(volatile unsigned short *)(ISP1582_BASE + 0x74))
-#define ISP1582_UNLOCK (*(volatile unsigned short *)(ISP1582_BASE + 0x7c))
-
-#define ISP1582_UNLOCK_CODE 0xaa37
-
-#define TYPE_BULK 2
-
-#define STATE_DEFAULT 0
-#define STATE_ADDRESS 1
-#define STATE_CONFIGURED 2
-
-#define N_ENDPOINTS 2
-
-struct usb_endpoint
-{
- unsigned char *out_buf;
- short out_len;
- short out_ptr;
- void (*out_done)(int, unsigned char *, int);
- unsigned char out_in_progress;
-
- unsigned char *in_buf;
- short in_min_len;
- short in_max_len;
- short in_ptr;
- void (*in_done)(int, unsigned char *, int);
- unsigned char in_ack;
-
- unsigned char halt[2];
- unsigned char enabled[2];
- short max_pkt_size[2];
-};
-
-static char usb_connect_state;
-
-static struct usb_endpoint endpoints[N_ENDPOINTS];
-
-static unsigned char setup_pkt_buf[8];
-static unsigned char setup_out_buf[8];
-static unsigned char usb_state;
-static unsigned char usb_remote_wakeup;
-
-#ifdef LCD_DEBUG
-static unsigned char int_count[32];
-
-static int log_pos_x = 0;
-static int log_pos_y = 3;
-#endif
-
-static void nop_f(void)
-{
-}
-
-#ifdef LCD_DEBUG
-static void log_char(char c)
-{
- char s[2];
-
- s[0] = c;
- s[1] = 0;
-
- lcd_puts(log_pos_x, log_pos_y, s);
- lcd_update();
- log_pos_x++;
- if (log_pos_x >= 16)
- {
- log_pos_x = 0;
- log_pos_y++;
- if (log_pos_y > 5)
- log_pos_y = 3;
- }
-}
-#else
-#define log_char(c)
-#endif
-
-#define SERIAL_BUF_SIZE 1024
-
-struct serial_fifo
-{
- unsigned char buf[SERIAL_BUF_SIZE];
- short head, tail;
-};
-
-static struct serial_fifo serial_in_fifo;
-static struct serial_fifo serial_out_fifo;
-static unsigned char serial_in_pkt[64];
-
-static unsigned char device_descriptor[18] = {
- 0x12, /* length */
- 0x01, /* descriptor type */
- 0x10, 0x01, /* USB version (1.1) */
- 0xff, 0xff, /* class and subclass */
- 0xff, /* protocol */
- 0x40, /* max packet size 0 */
- 0x02, 0x41, /* vendor (iRiver) */
- 0x07, 0xee, /* product (0xee07) */
- 0x01, 0x00, /* device version */
- 0x01, /* manufacturer string */
- 0x02, /* product string */
- 0x00, /* serial number string */
- 0x01 /* number of configurations */
-};
-
-static unsigned char cfg_descriptor[32] = {
- 0x09, /* length */
- 0x02, /* descriptor type */
- 0x20, 0x00, /* total length */
- 0x01, /* number of interfaces */
- 0x01, /* configuration value */
- 0x00, /* configuration string */
- 0x80, /* attributes (none) */
- 0x32, /* max power (100 mA) */
- /* interface descriptor */
- 0x09, /* length */
- 0x04, /* descriptor type */
- 0x00, /* interface number */
- 0x00, /* alternate setting */
- 0x02, /* number of endpoints */
- 0xff, /* interface class */
- 0xff, /* interface subclass */
- 0xff, /* interface protocol */
- 0x00, /* interface string */
- /* endpoint IN */
- 0x07, /* length */
- 0x05, /* descriptor type */
- 0x81, /* endpoint 1 IN */
- 0x02, /* attributes (bulk) */
- 0x40, 0x00, /* max packet size */
- 0x00, /* interval */
- /* endpoint OUT */
- 0x07, /* length */
- 0x05, /* descriptor type */
- 0x01, /* endpoint 1 IN */
- 0x02, /* attributes (bulk) */
- 0x40, 0x00, /* max packet size */
- 0x00 /* interval */
-};
-
-static unsigned char lang_descriptor[4] = {
- 0x04, /* length */
- 0x03, /* descriptor type */
- 0x09, 0x04 /* English (US) */
-};
-
-#define N_STRING_DESCRIPTORS 2
-
-static unsigned char string_descriptor_vendor[] = {
- 0x2e, 0x03,
- 'i', 0, 'R', 0, 'i', 0, 'v', 0, 'e', 0, 'r', 0, ' ', 0, 'L', 0,
- 't', 0, 'd', 0, ' ', 0, 'a', 0, 'n', 0, 'd', 0, ' ', 0, 'R', 0,
- 'o', 0, 'c', 0, 'k', 0, 'b', 0, 'o', 0, 'x', 0};
-
-static unsigned char string_descriptor_product[] = {
- 0x1c, 0x03,
- 'i', 0, 'R', 0, 'i', 0, 'v', 0, 'e', 0, 'r', 0, ' ', 0, 'i', 0,
- 'F', 0, 'P', 0, '7', 0, '0', 0, '0', 0};
-
-static unsigned char *string_descriptor[N_STRING_DESCRIPTORS] = {
- string_descriptor_vendor,
- string_descriptor_product
-};
-
-static inline int ep_index(int n, int dir)
-{
- return (n << 1) | dir;
-}
-
-static inline int epidx_dir(int idx)
-{
- return idx & 1;
-}
-
-static inline int epidx_n(int idx)
-{
- return idx >> 1;
-}
-
-int usb_connected(void)
-{
- return GPIO7_READ & 1;
-}
-
-static inline void usb_select_endpoint(int idx)
-{
- ISP1582_EPINDEX = idx;
-}
-
-static inline void usb_select_setup_endpoint(void)
-{
- ISP1582_EPINDEX = 0x20;
-}
-
-static void usb_setup_endpoint(int idx, int max_pkt_size, int type)
-{
- struct usb_endpoint *ep;
-
- usb_select_endpoint(idx);
- ISP1582_MAXPKSZ = max_pkt_size;
- /* |= is in the original firmware */
- ISP1582_EPTYPE |= 0x1c | type;
- /* clear buffer */
- ISP1582_CTRLFUN |= 0x10;
- ISP1582_INTEN |= (1 << (10 + idx));
-
- ep = &(endpoints[epidx_n(idx)]);
- ep->halt[epidx_dir(idx)] = 0;
- ep->enabled[epidx_dir(idx)] = 1;
- ep->out_in_progress = 0;
- ep->in_min_len = -1;
- ep->in_ack = 0;
- ep->max_pkt_size[epidx_dir(idx)] = max_pkt_size;
-}
-
-static void usb_disable_endpoint(int idx)
-{
- usb_select_endpoint(idx);
- ISP1582_EPTYPE &= 8;
- ISP1582_INTEN &= ~(1 << (10 + idx));
- endpoints[epidx_n(idx)].enabled[epidx_dir(idx)] = 1;
-}
-
-void usb_reconnect(void)
-{
- int i;
- ISP1582_MODE &= ~1; /* SOFTCT off */
- for (i = 0; i < 10000; i++)
- nop_f();
- ISP1582_MODE |= 1; /* SOFTCT on */
-}
-
-static void usb_cleanup(void)
-{
- ISP1582_MODE &= ~1; /* SOFTCT off */
-}
-
-static void usb_setup(int reset)
-{
- int i;
-
- for (i = 0; i < N_ENDPOINTS; i++)
- endpoints[i].enabled[0] = endpoints[i].enabled[1] = 0;
-
- ISP1582_UNLOCK = ISP1582_UNLOCK_CODE;
- if (!reset)
- ISP1582_MODE = 0x88; /* CLKAON | GLINTENA */
- ISP1582_INTCONF = 0x57;
- ISP1582_INTEN = 0xd39;
-
- ISP1582_ADDRESS = reset ? 0x80: 0;
-
- usb_setup_endpoint(ep_index(0, DIR_RX), 64, 0);
- usb_setup_endpoint(ep_index(0, DIR_TX), 64, 0);
-
- ISP1582_MODE |= 1; /* SOFTCT on */
-
- usb_state = STATE_DEFAULT;
- usb_remote_wakeup = 0;
-}
-
-static int usb_get_packet(unsigned char *buf, int max_len)
-{
- int len, i;
- len = ISP1582_BUFLEN;
-
- if (max_len < 0 || max_len > len)
- max_len = len;
-
- i = 0;
- while (i < len)
- {
- unsigned short d = ISP1582_DATA;
- if (i < max_len)
- buf[i] = d & 0xff;
- i++;
- if (i < max_len)
- buf[i] = (d >> 8) & 0xff;
- i++;
- }
- return max_len;
-}
-
-static void usb_receive(int n)
-{
- int len;
-
- if (endpoints[n].halt[DIR_RX]
- || !endpoints[n].enabled[DIR_RX]
- || endpoints[n].in_min_len < 0
- || !endpoints[n].in_ack)
- return;
-
- endpoints[n].in_ack = 0;
-
- usb_select_endpoint(ep_index(n, DIR_RX));
-
- len = usb_get_packet(endpoints[n].in_buf + endpoints[n].in_ptr,
- endpoints[n].in_max_len - endpoints[n].in_ptr);
- endpoints[n].in_ptr += len;
- if (endpoints[n].in_ptr >= endpoints[n].in_min_len) {
- endpoints[n].in_min_len = -1;
- if (endpoints[n].in_done)
- (*(endpoints[n].in_done))(n, endpoints[n].in_buf,
- endpoints[n].in_ptr);
- }
-}
-
-static int usb_out_buffer_full(int ep)
-{
- usb_select_endpoint(ep_index(ep, DIR_TX));
- if (ISP1582_EPTYPE & 4)
- return (ISP1582_BUFSTAT & 3) == 3;
- else
- return (ISP1582_BUFSTAT & 3) != 0;
-}
-
-static void usb_send(int n)
-{
- int max_pkt_size, len;
- int i;
- unsigned char *p;
-
-#ifdef LCD_DEBUG
- if (endpoints[n].halt[DIR_TX])
- log_char('H');
- if (!endpoints[n].out_in_progress)
- log_char('$');
-#endif
-
- if (endpoints[n].halt[DIR_TX]
- || !endpoints[n].enabled[DIR_TX]
- || !endpoints[n].out_in_progress)
- return;
-
- if (endpoints[n].out_ptr < 0)
- {
- endpoints[n].out_in_progress = 0;
- if (endpoints[n].out_done)
- (*(endpoints[n].out_done))(n, endpoints[n].out_buf,
- endpoints[n].out_len);
- return;
- }
-
- if (usb_out_buffer_full(n))
- {
- log_char('F');
- return;
- }
-
- usb_select_endpoint(ep_index(n, DIR_TX));
- max_pkt_size = endpoints[n].max_pkt_size[DIR_TX];
- len = endpoints[n].out_len - endpoints[n].out_ptr;
- if (len > max_pkt_size)
- len = max_pkt_size;
-
- log_char('0' + (len % 10));
- ISP1582_BUFLEN = len;
- p = endpoints[n].out_buf + endpoints[n].out_ptr;
- i = 0;
- while (len - i >= 2) {
- ISP1582_DATA = p[i] | (p[i + 1] << 8);
- i += 2;
- }
- if (i < len)
- ISP1582_DATA = p[i];
-
- endpoints[n].out_ptr += len;
-
-/*
- if (endpoints[n].out_ptr == endpoints[n].out_len
- && len < max_pkt_size)
-*/
- if (endpoints[n].out_ptr == endpoints[n].out_len)
- endpoints[n].out_ptr = -1;
-}
-
-static void usb_stall_endpoint(int idx)
-{
- usb_select_endpoint(idx);
- ISP1582_CTRLFUN |= 1;
- endpoints[epidx_n(idx)].halt[epidx_dir(idx)] = 1;
-}
-
-static void usb_unstall_endpoint(int idx)
-{
- usb_select_endpoint(idx);
- ISP1582_CTRLFUN &= ~1;
- ISP1582_EPTYPE &= ~8;
- ISP1582_EPTYPE |= 8;
- ISP1582_CTRLFUN |= 0x10;
- if (epidx_dir(idx) == DIR_TX)
- endpoints[epidx_n(idx)].out_in_progress = 0;
- else
- {
- endpoints[epidx_n(idx)].in_min_len = -1;
- endpoints[epidx_n(idx)].in_ack = 0;
- }
- endpoints[epidx_n(idx)].halt[epidx_dir(idx)] = 0;
-}
-
-static void usb_status_ack(int dir)
-{
- log_char(dir ? '@' : '#');
- usb_select_endpoint(ep_index(0, dir));
- ISP1582_CTRLFUN |= 2;
-}
-
-static void usb_set_address(int adr)
-{
- ISP1582_ADDRESS = adr | 0x80;
-}
-
-static void usb_data_stage_enable(int dir)
-{
- usb_select_endpoint(ep_index(0, dir));
- ISP1582_CTRLFUN |= 4;
-}
-
-static void usb_request_error(void)
-{
- usb_stall_endpoint(ep_index(0, DIR_TX));
- usb_stall_endpoint(ep_index(0, DIR_RX));
-}
-
-static void usb_receive_block(unsigned char *buf, int min_len,
- int max_len,
- void (*in_done)(int, unsigned char *, int),
- int ep)
-{
- endpoints[ep].in_done = in_done;
- endpoints[ep].in_buf = buf;
- endpoints[ep].in_max_len = max_len;
- endpoints[ep].in_min_len = min_len;
- endpoints[ep].in_ptr = 0;
- usb_receive(ep);
-}
-
-static void usb_send_block(unsigned char *buf, int len,
- void (*done)(int, unsigned char *, int),
- int ep)
-{
- endpoints[ep].out_done = done;
- endpoints[ep].out_buf = buf;
- endpoints[ep].out_len = len;
- endpoints[ep].out_ptr = 0;
- endpoints[ep].out_in_progress = 1;
- usb_send(ep);
-}
-
-static void out_send_status(int n, unsigned char *buf, int len)
-{
- (void)n;
- (void)buf;
- (void)len;
- usb_status_ack(DIR_RX);
-}
-
-static void usb_send_block_and_status(unsigned char *buf, int len, int ep)
-{
- usb_send_block(buf, len, out_send_status, ep);
-}
-
-static void usb_setup_set_address(int adr)
-{
- usb_set_address(adr);
- usb_state = adr ? STATE_ADDRESS : STATE_DEFAULT;
- usb_status_ack(DIR_TX);
-}
-
-static void usb_send_descriptor(unsigned char *device_descriptor,
- int descriptor_len, int buffer_len)
-{
- int len = descriptor_len < buffer_len ? descriptor_len : buffer_len;
- usb_send_block_and_status(device_descriptor, len, 0);
-}
-
-static void usb_setup_get_descriptor(int type, int index, int lang, int len)
-{
- (void)lang;
- usb_data_stage_enable(DIR_TX);
- switch (type)
- {
- case 1:
- if (index == 0)
- usb_send_descriptor(device_descriptor,
- sizeof(device_descriptor), len);
- else
- usb_request_error();
- break;
- case 2:
- if (index == 0)
- usb_send_descriptor(cfg_descriptor,
- sizeof(cfg_descriptor), len);
- else
- usb_request_error();
- break;
- case 3:
- if (index == 0)
- usb_send_descriptor(lang_descriptor,
- sizeof(lang_descriptor), len);
- else if (index <= N_STRING_DESCRIPTORS)
- usb_send_descriptor(string_descriptor[index - 1],
- string_descriptor[index - 1][0],
- len);
- else
- usb_request_error();
- break;
- default:
- usb_request_error();
- }
-}
-
-static void usb_setup_get_configuration(void)
-{
- setup_out_buf[0] = (usb_state == STATE_CONFIGURED) ? 1 : 0;
- usb_data_stage_enable(DIR_TX);
- usb_send_block_and_status(setup_out_buf, 1, 0);
-}
-
-static void usb_setup_interface(void)
-{
- usb_setup_endpoint(ep_index(1, DIR_RX), 64, TYPE_BULK);
- usb_setup_endpoint(ep_index(1, DIR_TX), 64, TYPE_BULK);
-}
-
-static void usb_setup_set_configuration(int value)
-{
- switch (value)
- {
- case 0:
- usb_disable_endpoint(ep_index(1, DIR_RX));
- usb_disable_endpoint(ep_index(1, DIR_TX));
- usb_state = STATE_ADDRESS;
- usb_status_ack(DIR_TX);
- break;
- case 1:
- usb_setup_interface();
- usb_state = STATE_CONFIGURED;
- usb_status_ack(DIR_TX);
- break;
- default:
- usb_request_error();
- }
-}
-
-static void usb_send_status(void)
-{
- usb_data_stage_enable(DIR_TX);
- usb_send_block_and_status(setup_out_buf, 2, 0);
-}
-
-static void usb_setup_get_device_status(void)
-{
- setup_out_buf[0] = (usb_remote_wakeup != 0) ? 2 : 0;
- setup_out_buf[1] = 0;
- usb_send_status();
-}
-
-static void usb_setup_clear_device_feature(int feature)
-{
- if (feature == 1) {
- usb_remote_wakeup = 0;
- usb_status_ack(DIR_TX);
- } else
- usb_request_error();
-}
-
-static void usb_setup_set_device_feature(int feature)
-{
- if (feature == 1) {
- usb_remote_wakeup = 1;
- usb_status_ack(DIR_TX);
- } else
- usb_request_error();
-}
-
-static void usb_setup_clear_endpoint_feature(int endpoint, int feature)
-{
- if (usb_state != STATE_CONFIGURED || feature != 0)
- usb_request_error();
- else if ((endpoint & 0xf) == 1)
- {
- usb_unstall_endpoint(ep_index(endpoint & 0xf, endpoint >> 7));
- usb_status_ack(DIR_TX);
- }
- else
- usb_request_error();
-}
-
-static void usb_setup_set_endpoint_feature(int endpoint, int feature)
-{
- if (usb_state != STATE_CONFIGURED || feature != 0)
- usb_request_error();
- else if ((endpoint & 0xf) == 1)
- {
- usb_stall_endpoint(ep_index(endpoint & 0xf, endpoint >> 7));
- usb_status_ack(DIR_TX);
- }
- else
- usb_request_error();
-}
-
-static void usb_setup_get_interface_status(int interface)
-{
- if (usb_state != STATE_CONFIGURED || interface != 0)
- usb_request_error();
- else
- {
- setup_out_buf[0] = setup_out_buf[1] = 0;
- usb_send_status();
- }
-}
-
-static void usb_setup_get_endpoint_status(int endpoint)
-{
- if ((usb_state == STATE_CONFIGURED && (endpoint & 0xf) <= 1)
- || (usb_state == STATE_ADDRESS && (endpoint & 0xf) == 0))
- {
- setup_out_buf[0] = endpoints[endpoint & 0xf].halt[endpoint >> 7];
- setup_out_buf[1] = 0;
- usb_send_status();
- }
- else
- usb_request_error();
-}
-
-static void usb_setup_get_interface(int interface)
-{
- if (usb_state != STATE_CONFIGURED || interface != 0)
- usb_request_error();
- else
- {
- setup_out_buf[0] = 0;
- usb_data_stage_enable(DIR_TX);
- usb_send_block_and_status(setup_out_buf, 1, 0);
- }
-}
-
-static void usb_setup_set_interface(int interface, int setting)
-{
- if (usb_state != STATE_CONFIGURED || interface != 0 || setting != 0)
- usb_request_error();
- else
- {
- usb_setup_interface();
- usb_status_ack(DIR_TX);
- }
-}
-
-static void usb_handle_setup_pkt(unsigned char *pkt)
-{
- switch ((pkt[0] << 8) | pkt[1])
- {
- case 0x0005:
- log_char('A');
- usb_setup_set_address(pkt[2]);
- break;
- case 0x8006:
- log_char('D');
- usb_setup_get_descriptor(pkt[3], pkt[2], (pkt[5] << 8) | pkt[4],
- (pkt[7] << 8) | pkt[6]);
- break;
- case 0x8008:
- usb_setup_get_configuration();
- break;
- case 0x0009:
- usb_setup_set_configuration(pkt[2]);
- break;
- case 0x8000:
- usb_setup_get_device_status();
- break;
- case 0x8100:
- usb_setup_get_interface_status(pkt[4]);
- break;
- case 0x8200:
- usb_setup_get_endpoint_status(pkt[4]);
- break;
- case 0x0001:
- usb_setup_clear_device_feature(pkt[2]);
- break;
- case 0x0201:
- usb_setup_clear_endpoint_feature(pkt[4], pkt[2]);
- break;
- case 0x0003:
- usb_setup_set_device_feature(pkt[2]);
- break;
- case 0x0203:
- usb_setup_set_endpoint_feature(pkt[4], pkt[2]);
- break;
- case 0x810a:
- usb_setup_get_interface(pkt[4]);
- break;
- case 0x010b:
- usb_setup_set_interface(pkt[4], pkt[2]);
- break;
- case 0x0103:
- /* set interface feature */
- case 0x0101:
- /* clear interface feature */
- case 0x0007:
- /* set descriptor */
- case 0x820c:
- /* synch frame */
- default:
- usb_request_error();
- }
-}
-
-static void usb_handle_setup_rx(void)
-{
- int len;
-#ifdef LCD_DEBUG
- char s[20];
- int i;
-#endif
- usb_select_setup_endpoint();
- len = usb_get_packet(setup_pkt_buf, 8);
-
- if (len == 8)
- usb_handle_setup_pkt(setup_pkt_buf);
-
-#ifdef LCD_DEBUG
-/*
- snprintf(s, 10, "l%02x", len);
- lcd_puts(0, 5, s);
-*/
- for (i = 0; i < 8; i++)
- snprintf(s + i * 2, 3, "%02x", setup_pkt_buf[i]);
- lcd_puts(0, 0, s);
- lcd_update();
-#endif
-}
-
-static void usb_handle_data_int(int ep, int dir)
-{
- if (dir == DIR_TX)
- usb_send(ep);
- else
- {
- endpoints[ep].in_ack = 1;
- usb_receive(ep);
- }
-}
-
-static void usb_handle_int(int i)
-{
-#ifdef LCD_DEBUG
-/*
- char s[10];
- snprintf(s, sizeof(s), "%02d", i);
- lcd_puts(0, 2, s);
- lcd_update();
-*/
- int_count[i]++;
- if (i == 10)
- log_char('o');
- if (i == 11)
- log_char('i');
- if (i == 12)
- log_char('O');
- if (i == 13)
- log_char('I');
-#endif
-
- if (i >= 10)
- usb_handle_data_int((i - 10) / 2, i % 2);
- else
- {
- switch (i)
- {
- case 0:
- log_char('r');
- usb_setup(1);
- break;
- case 8:
- log_char('s');
- usb_handle_setup_rx();
- break;
- }
- }
-
-}
-
-static void usb_handle_interrupts(void)
-{
-#ifdef LCD_DEBUG
- char s[20];
-#endif
-
- while (1)
- {
- unsigned long ints;
- int i;
-
-#ifdef LCD_DEBUG
- /*
- snprintf(s, sizeof(s), "i%08lx", ISP1582_INT);
- lcd_puts(0, 2, s);
- */
-#endif
-
- ints = ISP1582_INT & ISP1582_INTEN;
- if (!ints) break;
-
- i = 0;
- while (!(ints & (1 << i)))
- i++;
- ISP1582_INT = 1 << i;
- usb_handle_int(i);
-
-#ifdef LCD_DEBUG
- for (i = 0; i < 8; i++)
- snprintf(s + i * 2, 3, "%02x", int_count[i]);
- lcd_puts(0, 6, s);
- for (i = 0; i < 8; i++)
- snprintf(s + i * 2, 3, "%02x", int_count[i + 8]);
- lcd_puts(0, 7, s);
-#endif
- }
-#ifdef LCD_DEBUG
-/*
- lcd_puts(0, 3, usb_connected() ? "C" : "N");
- lcd_update();
-*/
-#endif
-}
-
-static inline int fifo_mod(int n)
-{
- return (n >= SERIAL_BUF_SIZE) ? n - SERIAL_BUF_SIZE : n;
-}
-
-static void fifo_init(struct serial_fifo *fifo)
-{
- fifo->head = fifo->tail = 0;
-}
-
-static int fifo_empty(struct serial_fifo *fifo)
-{
- return fifo->head == fifo->tail;
-}
-
-static int fifo_full(struct serial_fifo *fifo)
-{
- return fifo_mod(fifo->head + 1) == fifo->tail;
-}
-
-static void fifo_remove(struct serial_fifo *fifo, int n)
-{
- fifo->tail = fifo_mod(fifo->tail + n);
-}
-
-/*
- Not used:
-static void fifo_add(struct serial_fifo *fifo, int n)
-{
- fifo->head = fifo_mod(fifo->head + n);
-}
-
-static void fifo_free_block(struct serial_fifo *fifo,
- unsigned char **ptr, int *len)
-{
- *ptr = fifo->buf + fifo->head;
- if (fifo->head >= fifo->tail)
- {
- int l = SERIAL_BUF_SIZE - fifo->head;
- if (fifo->tail == 0)
- l--;
- *len = l;
- }
- else
- *len = fifo->tail - fifo->head - 1;
-}
-*/
-
-static int fifo_free_space(struct serial_fifo *fifo)
-{
- if (fifo->head >= fifo->tail)
- return SERIAL_BUF_SIZE - (fifo->head - fifo->tail) - 1;
- else
- return fifo->tail - fifo->head - 1;
-}
-
-static int fifo_get_byte(struct serial_fifo *fifo)
-{
- int r = fifo->buf[fifo->tail];
- fifo->tail = fifo_mod(fifo->tail + 1);
- return r;
-}
-
-static void fifo_put_byte(struct serial_fifo *fifo, int b)
-{
- fifo->buf[fifo->head] = b;
- fifo->head = fifo_mod(fifo->head + 1);
-}
-
-static void fifo_full_block(struct serial_fifo *fifo,
- unsigned char **ptr, int *len)
-{
- *ptr = fifo->buf + fifo->tail;
- if (fifo->head >= fifo->tail)
- *len = fifo->head - fifo->tail;
- else
- *len = SERIAL_BUF_SIZE - fifo->tail;
-}
-
-static void serial_fill_in_fifo(int ep, unsigned char *buf, int len);
-static void serial_free_out_fifo(int ep, unsigned char *buf, int len);
-
-static void serial_restart_input(int ep)
-{
- if (fifo_free_space(&serial_in_fifo) >= 64)
- usb_receive_block(serial_in_pkt, 1, 64, serial_fill_in_fifo, ep);
-}
-
-static void serial_fill_in_fifo(int ep, unsigned char *buf, int len)
-{
- int i;
- for (i = 0; i < len; i++)
- fifo_put_byte(&serial_in_fifo, buf[i]);
- serial_restart_input(ep);
-}
-
-static void serial_restart_output(int ep)
-{
- unsigned char *block;
- int blen;
- fifo_full_block(&serial_out_fifo, &block, &blen);
- if (blen)
- {
-#ifdef LCD_DEBUG
- lcd_putsf(0, 2, "o%03lx/%03x", block - serial_out_fifo.buf, blen);
- lcd_update();
-#endif
- usb_send_block(block, blen, serial_free_out_fifo, ep);
- }
-}
-
-static void serial_free_out_fifo(int ep, unsigned char *buf, int len)
-{
- (void)buf;
- fifo_remove(&serial_out_fifo, len);
- serial_restart_output(ep);
-}
-
-static void usb_serial_handle(void)
-{
-#ifdef BUTTONS
- static int t = 0;
-
- t++;
- if (t >= 1000)
- {
- int b;
- t = 0;
- yield();
- b = button_get(false);
- if (b == BUTTON_PLAY)
- system_reboot();
- else if (b & BUTTON_REL)
- usb_reconnect();
- }
-#endif
-
-
- if (!usb_connect_state)
- {
- if (usb_connected())
- {
- int i;
- GPIO3_SET = 4;
- (*(volatile unsigned long *)0x80005004) = 2;
- (*(volatile unsigned long *)0x80005008) = 0;
- for (i = 0; i < 100000; i++)
- nop_f();
- usb_setup(0);
- usb_connect_state = 1;
- }
- }
- else
- {
- if (!usb_connected())
- {
- usb_connect_state = 0;
- usb_cleanup();
- }
- else
- {
- usb_handle_interrupts();
-
- if (usb_state == STATE_CONFIGURED)
- {
- if (endpoints[1].in_min_len < 0)
- serial_restart_input(1);
- if (!endpoints[1].out_in_progress)
- serial_restart_output(1);
- }
- }
- }
-}
-
-
-/*
- Not used:
-static int usb_serial_in_empty(void)
-{
- return fifo_empty(&serial_in_fifo);
-}
-*/
-
-int usb_serial_get_byte(void)
-{
- while (fifo_empty(&serial_in_fifo))
- usb_serial_handle();
- return fifo_get_byte(&serial_in_fifo);
-}
-
-int usb_serial_try_get_byte(void)
-{
- int r;
- if (fifo_empty(&serial_in_fifo))
- r = -1;
- else
- r = fifo_get_byte(&serial_in_fifo);
- usb_serial_handle();
- return r;
-}
-
-/*
- Not used:
-static int usb_serial_out_full(void)
-{
- return fifo_full(&serial_out_fifo);
-}
-*/
-
-void usb_serial_put_byte(int b)
-{
- while (fifo_full(&serial_out_fifo))
- usb_serial_handle();
- fifo_put_byte(&serial_out_fifo, b);
- usb_serial_handle();
-}
-
-int usb_serial_try_put_byte(int b)
-{
- int r = -1;
- if (!fifo_full(&serial_out_fifo))
- {
- fifo_put_byte(&serial_out_fifo, b);
- r = 0;
- }
- usb_serial_handle();
- return r;
-}
-
-void usb_serial_init(void)
-{
- fifo_init(&serial_in_fifo);
- fifo_init(&serial_out_fifo);
- usb_connect_state = 0;
-}
diff --git a/firmware/include/crc32-mi4.h b/firmware/include/crc32-mi4.h
deleted file mode 100644
index 431757271a..0000000000
--- a/firmware/include/crc32-mi4.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id: crc32.h 10464 2006-08-05 20:19:10Z miipekk $
- *
- * Copyright (C) 2007 Barry Wardell
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _CRC32_MI4_H
-#define _CRC32_MI4_H
-
-unsigned int chksum_crc32 (unsigned char *block, unsigned int length);
-#endif
diff --git a/firmware/include/crc32.h b/firmware/include/crc32.h
index 8e1f868988..adf7e2bc6e 100644
--- a/firmware/include/crc32.h
+++ b/firmware/include/crc32.h
@@ -24,6 +24,7 @@
#define _CRC32_H
uint32_t crc_32(const void *src, uint32_t len, uint32_t crc32);
+uint32_t crc_32r(const void *src, uint32_t len, uint32_t crc32);
#endif
diff --git a/firmware/include/timefuncs.h b/firmware/include/timefuncs.h
index 4c5f0fbb42..c72508e862 100644
--- a/firmware/include/timefuncs.h
+++ b/firmware/include/timefuncs.h
@@ -31,6 +31,7 @@ int set_time(const struct tm *tm);
#if CONFIG_RTC
bool valid_time(const struct tm *tm);
void set_day_of_week(struct tm *tm);
+void set_day_of_year(struct tm *tm);
#endif
#endif /* _TIMEFUNCS_H_ */
diff --git a/firmware/rolo.c b/firmware/rolo.c
index 622110576a..5f936c95f4 100644
--- a/firmware/rolo.c
+++ b/firmware/rolo.c
@@ -40,7 +40,6 @@
#include "loader_strerror.h"
#if defined(MI4_FORMAT)
-#include "crc32-mi4.h"
#include "mi4-loader.h"
#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
#include "bootdata.h"
@@ -65,8 +64,9 @@ extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume
#include "ascodec.h"
#endif
-#if !defined(IRIVER_IFP7XX_SERIES)
-/* FIX: this doesn't work on iFP */
+#if defined(FIIO_M3K)
+#include "backlight-target.h"
+#endif
#define IRQ0_EDGE_TRIGGER 0x80
@@ -292,6 +292,12 @@ int rolo_load(const char* filename)
lcd_remote_puts(0, 1, "Executing");
lcd_remote_update();
#endif
+
+#if defined(FIIO_M3K)
+ /* Avoids the LCD backlight ramping down & up weirdly */
+ backlight_hw_off();
+#endif
+
adc_close();
#if CONFIG_CPU == AS3525v2
/* Set CVDD1 power supply to default*/
@@ -321,13 +327,3 @@ int rolo_load(const char* filename)
/* never reached */
return 0;
}
-
-#else /* !defined(IRIVER_IFP7XX_SERIES) */
-int rolo_load(const char* filename)
-{
- /* dummy */
- (void)filename;
- return 0;
-}
-
-#endif /* !defined(IRIVER_IFP7XX_SERIES) */
diff --git a/firmware/target/arm/ata-nand-telechips.c b/firmware/target/arm/ata-nand-telechips.c
index 73d92a5215..55f6b1f3f7 100644
--- a/firmware/target/arm/ata-nand-telechips.c
+++ b/firmware/target/arm/ata-nand-telechips.c
@@ -48,7 +48,7 @@ static long next_yield = 0;
static struct mutex ata_mtx SHAREDBSS_ATTR;
-#if defined(COWON_D2) || defined(IAUDIO_7)
+#if defined(COWON_D2)
#define FTL_V2
#define MAX_WRITE_CACHES 8
#else
@@ -906,13 +906,6 @@ int nand_init(void)
mutex_init(&ata_mtx);
-#ifdef CPU_TCC77X
- CSCFG2 = 0x018a8010 | tcc77x_cscfg_bw(TCC77X_CSCFG_BW8);
-
- GPIOC_FUNC &= ~(CS_GPIO_BIT | WE_GPIO_BIT);
- GPIOC_FUNC |= 0x1;
-#endif
-
/* Set GPIO direction for chip select & write protect */
NAND_GPIO_OUT_EN(CS_GPIO_BIT | WE_GPIO_BIT);
diff --git a/firmware/target/arm/lcd-ssd1815.c b/firmware/target/arm/lcd-ssd1815.c
index 891d4ef64d..028362f91c 100644
--- a/firmware/target/arm/lcd-ssd1815.c
+++ b/firmware/target/arm/lcd-ssd1815.c
@@ -144,81 +144,6 @@ void lcd_init_device(void)
lcd_write_command(LCD_SET_NORMAL_DISPLAY);
}
-
-#elif defined(CPU_TCC77X)
-
-/* TCC77x specific defines */
-#define LCD_BASE 0x50000000
-#define LCD_CMD *(volatile unsigned char*)(LCD_BASE)
-#define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1)
-
-void lcd_write_command(int byte)
-{
- LCD_CMD = byte;
-
- asm volatile (
- "nop \n\t"
- "nop \n\t"
- "nop \n\t"
- );
-}
-
-void lcd_write_data(const fb_data* p_bytes, int count)
-{
- while (count--)
- {
- LCD_DATA = *(p_bytes++);
-
- asm volatile (
- "nop \n\t"
- "nop \n\t"
- "nop \n\t"
- );
- }
-}
-
-/* LCD init */
-void lcd_init_device(void)
-{
- uint32_t bus_width;
-
- /* Telechips init the same as the original firmware */
- CSCFG1 &= 0xc3ffc000;
- CSCFG1 |= 0x3400101a;
- CSCFG1 |= (1 << 21);
- CSCFG1 &= ~(1 << 21);
-
- bus_width = ((MCFG >> 11) & 0x3) ^ 3;
-
- CSCFG1 = (bus_width << 28) |
- (3 << 26) | /* MTYPE = 3 */
- ((LCD_BASE >> 28) << 22) | /* CSBASE = 0x5 */
- (1 << 20) | /* Unknown */
- (3 << 11) | /* Setup time = 3 cycles */
- (3 << 3) | /* Pulse width = 3+1 cycles */
- (1 << 0); /* Hold time = 1 cycle */
-
- /* SSD1815 inits like the original firmware */
- lcd_write_command(LCD_SET_DISPLAY_OFF);
- lcd_set_flip(false);
- lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO | 5);
- lcd_set_contrast(lcd_default_contrast());
- lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER | 7);
- /* power control register: op-amp=1, regulator=1, booster=1 */
- lcd_write_command(LCD_SET_BIAS_TC_OSC);
-
- /* 0xc2 = 110 000 10: Osc. Freq 110 - ???
- TC value 000 - "-0.01%/C (TC0, POR)"
- Bias ratio 10 - "1/9, 1/7 (POR)"
- */
- lcd_write_command(0xc2);
- lcd_write_command(LCD_SET_DISPLAY_ON);
-
- lcd_clear_display();
- lcd_update();
-}
-
-/* End of TCC77x specific defines */
#endif
diff --git a/firmware/target/arm/pcm-telechips.c b/firmware/target/arm/pcm-telechips.c
index 68bae1b0a9..ff550b14d6 100644
--- a/firmware/target/arm/pcm-telechips.c
+++ b/firmware/target/arm/pcm-telechips.c
@@ -82,19 +82,6 @@ void pcm_play_dma_init(void)
/* Enable DAI block in Master mode, 256fs->32fs, 16bit LSB */
DAMR = 0x3c8e80;
-#elif defined(IAUDIO_7)
- BCLKCTR &= ~DEV_DAI;
- PCLK_DAI = (0x800a << 16) | (PCLK_DAI & 0xffff);
- BCLKCTR |= DEV_DAI;
-
- /* Master mode, 256->64fs, 16bit LSB*/
- DAMR = 0x3cce20;
-#elif defined(LOGIK_DAX)
- /* TODO */
-#elif defined(SANSA_M200)
- /* TODO */
-#elif defined(SANSA_C100)
- /* TODO */
#else
#error "Target isn't supported"
#endif
@@ -228,7 +215,7 @@ const void * pcm_rec_dma_get_peak_buffer(void)
}
#endif
-#if defined(CPU_TCC77X) || defined(CPU_TCC780X)
+#if defined(CPU_TCC780X)
void fiq_handler(void) ICODE_ATTR __attribute__((naked));
void fiq_handler(void)
{
@@ -245,9 +232,6 @@ void fiq_handler(void)
#if defined(CPU_TCC780X)
"mov r8, #0xc000 \n" /* DAI_TX_IRQ_MASK | DAI_RX_IRQ_MASK */
"ldr r9, =0xf3001004 \n" /* CREQ */
-#elif defined(CPU_TCC77X)
- "mov r8, #0x0030 \n" /* DAI_TX_IRQ_MASK | DAI_RX_IRQ_MASK */
- "ldr r9, =0x80000104 \n" /* CREQ */
#endif
"str r8, [r9] \n" /* clear DAI IRQs */
"ldmia r11, { r8-r9 } \n" /* r8 = p, r9 = size */
diff --git a/firmware/target/arm/pnx0101/app.lds b/firmware/target/arm/pnx0101/app.lds
deleted file mode 100644
index f14ef90129..0000000000
--- a/firmware/target/arm/pnx0101/app.lds
+++ /dev/null
@@ -1,144 +0,0 @@
-#include "config.h"
-
-ENTRY(start)
-
-OUTPUT_FORMAT(elf32-littlearm)
-OUTPUT_ARCH(arm)
-STARTUP(target/arm/pnx0101/crt0-pnx0101.o)
-
-#define PLUGINSIZE PLUGIN_BUFFER_SIZE
-#define CODECSIZE CODEC_SIZE
-
-#ifdef DEBUG
-#define STUBOFFSET 0x10000
-#else
-#define STUBOFFSET 0
-#endif
-
-#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - STUBOFFSET - CODECSIZE
-
-#define DRAMORIG 0xc00000 + STUBOFFSET
-#define IRAM0ORIG 0x000000
-#define IRAM0SIZE 0x7000
-#define IRAMORIG 0x400000
-#define IRAMSIZE 0x7000
-
-/* End of the audio buffer, where the codec buffer starts */
-#define ENDAUDIOADDR (DRAMORIG + DRAMSIZE)
-
-/* Where the codec buffer ends, and the plugin buffer starts */
-#define ENDADDR (ENDAUDIOADDR + CODECSIZE)
-
-MEMORY
-{
- DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE
- IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE
- IRAM0 : ORIGIN = IRAM0ORIG, LENGTH = IRAM0SIZE
-}
-
-SECTIONS
-{
- .text :
- {
- loadaddress = .;
- _loadaddress = .;
- . = ALIGN(0x200);
- *(.init.text)
- *(.text*)
- *(.glue_7)
- *(.glue_7t)
- . = ALIGN(0x4);
- } > DRAM
-
- .rodata :
- {
- *(.rodata) /* problems without this, dunno why */
- *(.rodata*)
- *(.rodata.str1.1)
- *(.rodata.str1.4)
- . = ALIGN(0x4);
- } > DRAM
-
- .data :
- {
- *(.data*)
- . = ALIGN(0x4);
- } > DRAM
-
- /DISCARD/ :
- {
- *(.eh_frame)
- }
-
- .vectors 0x0 :
- {
- _vectorsstart = .;
- KEEP(*(.vectors));
- _vectorsend = .;
- *(.dmabuf)
- } >IRAM0 AT> DRAM
-
- _vectorscopy = LOADADDR(.vectors);
-
- .iram IRAMORIG + SIZEOF(.vectors) :
- {
- _iramstart = .;
- *(.icode)
- *(.irodata)
- *(.idata)
- . = ALIGN(0x4);
- _iramend = .;
- } > IRAM AT> DRAM
-
- _iramcopy = LOADADDR(.iram);
-
- .ibss (NOLOAD) :
- {
- _iedata = .;
- *(.ibss)
- . = ALIGN(0x4);
- _iend = .;
- } > IRAM
-
- .stack :
- {
- *(.stack)
- stackbegin = .;
- . += 0x2000;
- stackend = .;
- } > IRAM
-
- .bss ADDR(.data) + SIZEOF(.data) + SIZEOF(.iram) + SIZEOF(.vectors):
- {
- _edata = .;
- *(.bss*)
- *(COMMON)
- . = ALIGN(0x4);
- _end = .;
- } > DRAM
-
- .audiobuf ALIGN(4) :
- {
- _audiobuffer = .;
- audiobuffer = .;
- } > DRAM
-
- .audiobufend ENDAUDIOADDR:
- {
- audiobufend = .;
- _audiobufend = .;
- } > DRAM
-
- .codec ENDAUDIOADDR:
- {
- codecbuf = .;
- _codecbuf = .;
- }
-
- .plugin ENDADDR:
- {
- _pluginbuf = .;
- pluginbuf = .;
- }
-}
-
diff --git a/firmware/target/arm/pnx0101/backlight-target.h b/firmware/target/arm/pnx0101/backlight-target.h
deleted file mode 100644
index 7ebe85d66f..0000000000
--- a/firmware/target/arm/pnx0101/backlight-target.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id: backlight-target.h 13136 2007-04-12 22:12:13Z amiconn $
- *
- * Copyright (C) 2006 by Barry Wardell
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef BACKLIGHT_TARGET_H
-#define BACKLIGHT_TARGET_H
-
-#define backlight_hw_init() true
-void backlight_hw_on(void);
-void backlight_hw_off(void);
-
-#endif
diff --git a/firmware/target/arm/pnx0101/crt0-pnx0101.S b/firmware/target/arm/pnx0101/crt0-pnx0101.S
deleted file mode 100644
index 51be8c72a3..0000000000
--- a/firmware/target/arm/pnx0101/crt0-pnx0101.S
+++ /dev/null
@@ -1,225 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id: crt0.S 11850 2006-12-29 02:49:12Z markun $
- *
- * Copyright (C) 2002 by Linus Nielsen Feltzing
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#define ASM /* do not include structure definitions from pnx0101.h */
-
-#include "config.h"
-#include "cpu.h"
-
- .section .init.text,"ax",%progbits
-
- .global start
-start:
-
-/* Arm bootloader and startup code based on startup.s from the iPodLinux loader
- *
- * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
- * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
- *
- */
-
- msr cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ */
-
-#ifndef BOOTLOADER
-#ifndef DEBUG
- ldr r0, =0x80105000
- mov r1, #1
- str r1, [r0, #4]
- mov r1, #0
- str r1, [r0, #4]
-1: ldr r1, [r0]
- cmp r1, #0
- bne 1b
- mov r1, #0x74
- str r1, [r0, #8]
- mov r1, #2
- str r1, [r0, #0x18]
- mov r1, #2
- str r1, [r0, #0x20]
- mov r1, #82
- str r1, [r0, #0x28]
- mov r1, #100
- str r1, [r0, #0x2c]
- mov r1, #0x120
- str r1, [r0, #0x30]
- mov r1, #6
- str r1, [r0, #4]
- ldr r0, =1f
- mov r15, r0
-1:
-#endif /* !DEBUG */
-
-#ifndef DEBUG
- /* Copy exception handler code to address 0 */
- ldr r2, =_vectorsstart
- ldr r3, =_vectorsend
- ldr r4, =_vectorscopy
-1:
- cmp r3, r2
- ldrhi r5, [r4], #4
- strhi r5, [r2], #4
- bhi 1b
-#else
- ldr r1, =vectors
- ldr r0, =irq_handler
- str r0, [r1, #24]
- ldr r0, =fiq_handler
- str r0, [r1, #28]
-#endif
-
-#ifndef STUB
- /* Zero out IBSS */
- ldr r2, =_iedata
- ldr r3, =_iend
- mov r4, #0
-1:
- cmp r3, r2
- strhi r4, [r2], #4
- bhi 1b
-
- /* Copy the IRAM */
- ldr r2, =_iramcopy
- ldr r3, =_iramstart
- ldr r4, =_iramend
-1:
- cmp r4, r3
- ldrhi r5, [r2], #4
- strhi r5, [r3], #4
- bhi 1b
-#endif /* !STUB */
-#endif /* !BOOTLOADER */
-
- /* Initialise bss section to zero */
- ldr r2, =_edata
- ldr r3, =_end
- mov r4, #0
-1:
- cmp r3, r2
- strhi r4, [r2], #4
- bhi 1b
-
- /* Set up stack for IRQ mode */
- msr cpsr_c, #0xd2
- ldr sp, =irq_stack
- /* Set up stack for FIQ mode */
- msr cpsr_c, #0xd1
- ldr sp, =fiq_stack
-
- /* Let svc, abort and undefined modes use irq stack */
- msr cpsr_c, #0xd3
- ldr sp =irq_stack
- msr cpsr_c, #0xd7
- ldr sp, =irq_stack
- msr cpsr_c, #0xdb
- ldr sp, =irq_stack
-
- /* Switch to sys mode */
- msr cpsr_c, #0xdf
-
- /* Set up some stack and munge it with 0xdeadbeef */
- ldr sp, =stackend
- mov r3, sp
- ldr r2, =stackbegin
- ldr r4, =0xdeadbeef
-1:
- cmp r3, r2
- strhi r4, [r2], #4
- bhi 1b
-
- bl main
- /* main() should never return */
-
-/* Exception handlers. Will be copied to address 0 after memory remapping */
- .section .vectors,"aw"
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
-
- /* Exception vectors */
- .global vectors
-vectors:
- .word start
- .word undef_instr_handler
- .word software_int_handler
- .word prefetch_abort_handler
- .word data_abort_handler
- .word reserved_handler
- .word irq_handler
- .word fiq_handler
-
- .text
-
-/* All illegal exceptions call into UIE with exception address as first
- parameter. This is calculated differently depending on which exception
- we're in. Second parameter is exception number, used for a string lookup
- in UIE.
- */
-undef_instr_handler:
- sub r0, lr, #4
- mov r1, #0
- b UIE
-
-/* We run sys mode most of the time, and should never see a software
- exception being thrown. Make it illegal and call UIE.
- */
-software_int_handler:
-reserved_handler:
- sub r0, lr, #4
- mov r1, #4
- b UIE
-
-prefetch_abort_handler:
- sub r0, lr, #4
- mov r1, #1
- b UIE
-
-fiq_handler:
- @ Branch straight to FIQ handler in pcm_playback.c. This also handles the
- @ the correct return sequence.
- stmfd sp!, {r0-r7, r12, lr}
- bl fiq
- ldmfd sp!, {r0-r7, r12, lr}
- subs pc, lr, #4
-
-irq_handler:
-#ifndef STUB
- stmfd sp!, {r0-r11, r12, lr}
- bl irq
- ldmfd sp!, {r0-r11, r12, lr}
-#endif
- subs pc, lr, #4
-
-#ifdef STUB
-UIE:
- b UIE
-#endif
-
-/* 256 words of IRQ stack */
- .space 256*4
-irq_stack:
-
-/* 256 words of FIQ stack */
- .space 256*4
-fiq_stack:
diff --git a/firmware/target/arm/pnx0101/debug-pnx0101.c b/firmware/target/arm/pnx0101/debug-pnx0101.c
deleted file mode 100644
index 8dae2e4925..0000000000
--- a/firmware/target/arm/pnx0101/debug-pnx0101.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <stdbool.h>
-bool dbg_ports()
-{
- return false;
-}
diff --git a/firmware/target/arm/pnx0101/i2c-pnx0101.c b/firmware/target/arm/pnx0101/i2c-pnx0101.c
deleted file mode 100644
index eaf1e79500..0000000000
--- a/firmware/target/arm/pnx0101/i2c-pnx0101.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2005 by Tomasz Malesinski
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-void i2c_init(void)
-{
-}
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/adc-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/adc-ifp7xx.c
deleted file mode 100644
index 0f306f9986..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/adc-ifp7xx.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2006 by Barry Wardell
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include "system.h"
-#include "kernel.h"
-#include "thread.h"
-#include "adc.h"
-
-static unsigned short adcdata[NUM_ADC_CHANNELS];
-
-unsigned short adc_read(int channel)
-{
- return adcdata[channel];
-}
-
-static void adc_tick(void)
-{
- if (ADCST & 0x10) {
- adcdata[0] = ADCCH0 & 0x3ff;
- adcdata[1] = ADCCH1 & 0x3ff;
- adcdata[2] = ADCCH2 & 0x3ff;
- adcdata[3] = ADCCH3 & 0x3ff;
- adcdata[4] = ADCCH4 & 0x3ff;
- ADCST = 0xa;
- }
-}
-
-void adc_init(void)
-{
- ADCR24 = 0xaaaaa;
- ADCR28 = 0;
- ADCST = 2;
- ADCST = 0xa;
-
- while (!(ADCST & 0x10));
- adc_tick();
-
- tick_add_task(adc_tick);
-}
-
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/adc-target.h b/firmware/target/arm/pnx0101/iriver-ifp7xx/adc-target.h
deleted file mode 100644
index a18aa77c7e..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/adc-target.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2006 by Barry Wardell
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _ADC_TARGET_H_
-#define _ADC_TARGET_H_
-
-#define NUM_ADC_CHANNELS 5
-
-#define ADC_BUTTONS 0
-#define ADC_BATTERY 1
-#define ADC_BUTTON_PLAY 2
-#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
-
-#endif
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/backlight-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/backlight-ifp7xx.c
deleted file mode 100644
index 8be7a59de2..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/backlight-ifp7xx.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2006 by Barry Wardell
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include "system.h"
-#include "backlight.h"
-#include "lcd.h"
-
-void backlight_hw_on(void)
-{
- GPIO3_SET = 1;
-}
-
-void backlight_hw_off(void)
-{
- GPIO3_CLR = 1;
-}
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/button-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/button-ifp7xx.c
deleted file mode 100644
index 45f9fae478..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/button-ifp7xx.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2006 by Barry Wardell
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-
-#include <stdlib.h>
-#include "config.h"
-#include "cpu.h"
-#include "system.h"
-#include "button.h"
-#include "kernel.h"
-#include "backlight.h"
-#include "adc.h"
-
-
-void button_init_device(void)
-{
-
-}
-
-bool button_hold(void)
-{
- return (GPIO5_READ & 4) ? false : true;
-}
-
-/*
- * Get button pressed from hardware
- */
-int button_read_device(void)
-{
- int btn = BUTTON_NONE;
- int data;
- static bool hold_button = false;
- bool hold_button_old;
-
- /* normal buttons */
- hold_button_old = hold_button;
- hold_button = button_hold();
-
- if (hold_button != hold_button_old)
- backlight_hold_changed(hold_button);
-
- if (!button_hold())
- {
- data = adc_read(ADC_BUTTONS);
- if (data < 0x35c)
- {
- if (data < 0x151)
- if (data < 0xc7)
- if (data < 0x41)
- btn = BUTTON_LEFT;
- else
- btn = BUTTON_RIGHT;
- else
- btn = BUTTON_SELECT;
- else
- if (data < 0x268)
- if (data < 0x1d7)
- btn = BUTTON_UP;
- else
- btn = BUTTON_DOWN;
- else
- if (data < 0x2f9)
- btn = BUTTON_EQ;
- else
- btn = BUTTON_MODE;
- }
-
- if (adc_read(ADC_BUTTON_PLAY) < 0x64)
- btn |= BUTTON_PLAY;
- }
- return btn;
-}
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/button-target.h b/firmware/target/arm/pnx0101/iriver-ifp7xx/button-target.h
deleted file mode 100644
index 6932b8956f..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/button-target.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2006 by Barry Wardell
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-/* Custom written for the ifp7xx */
-
-#ifndef _BUTTON_TARGET_H_
-#define _BUTTON_TARGET_H_
-
-#define HAS_BUTTON_HOLD
-
-/* iriver IFP7XX specific button codes */
-
-#define BUTTON_PLAY 0x00000001
-#define BUTTON_SELECT 0x00000002
-
-#define BUTTON_LEFT 0x00000004
-#define BUTTON_RIGHT 0x00000008
-#define BUTTON_UP 0x00000010
-#define BUTTON_DOWN 0x00000020
-
-#define BUTTON_MODE 0x00000040
-#define BUTTON_EQ 0x00000080
-
-#define BUTTON_MAIN (BUTTON_PLAY|BUTTON_SELECT\
- |BUTTON_LEFT|BUTTON_RIGHT|BUTTON_UP|BUTTON_DOWN\
- |BUTTON_MODE|BUTTON_EQ)
-
-#define POWEROFF_BUTTON BUTTON_PLAY
-#define POWEROFF_COUNT 40
-
-#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/lcd-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/lcd-ifp7xx.c
deleted file mode 100644
index 1ad604d50c..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/lcd-ifp7xx.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Alan Korr
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-
-#include "kernel.h"
-#include "lcd.h"
-#include "system.h"
-
-/*** definitions ***/
-
-#define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
-#define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
-#define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20)
-#define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28)
-#define LCD_SET_DISPLAY_START_LINE ((char)0x40)
-#define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
-#define LCD_SET_SEGMENT_REMAP ((char)0xA0)
-#define LCD_SET_LCD_BIAS ((char)0xA2)
-#define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
-#define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
-#define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
-#define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
-#define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
-#define LCD_SET_BIAS_TC_OSC ((char)0xA9)
-#define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA)
-#define LCD_SET_INDICATOR_OFF ((char)0xAC)
-#define LCD_SET_INDICATOR_ON ((char)0xAD)
-#define LCD_SET_DISPLAY_OFF ((char)0xAE)
-#define LCD_SET_DISPLAY_ON ((char)0xAF)
-#define LCD_SET_PAGE_ADDRESS ((char)0xB0)
-#define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
-#define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2)
-#define LCD_SET_DISPLAY_OFFSET ((char)0xD3)
-#define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0)
-#define LCD_SOFTWARE_RESET ((char)0xE2)
-#define LCD_NOP ((char)0xE3)
-#define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE)
-
-/* LCD command codes */
-#define LCD_CNTL_RESET 0xe2 /* Software reset */
-#define LCD_CNTL_POWER 0x2f /* Power control */
-#define LCD_CNTL_CONTRAST 0x81 /* Contrast */
-#define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
-#define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
-#define LCD_CNTL_DISPON 0xaf /* Display on */
-
-#define LCD_CNTL_PAGE 0xb0 /* Page address */
-#define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
-#define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
-
-/*** driver routines ***/
-
-void lcd_write_command(int cmd)
-{
- while ((LCDSTAT & 3) != 3);
- LCDCMD = cmd;
-}
-
-void lcd_write_data( const unsigned char* data, int count )
-{
- int i;
- for (i=0; i < count; i++) {
- while ((LCDSTAT & 3) != 3);
- LCDDATA = data[i];
- }
-}
-
-/*** hardware configuration ***/
-
-int lcd_default_contrast(void)
-{
- return 45;
-}
-
-void lcd_set_contrast(int val)
-{
- lcd_write_command(LCD_CNTL_CONTRAST);
- lcd_write_command(val);
-}
-
-void lcd_set_invert_display(bool yesno)
-{
- if (yesno)
- lcd_write_command(LCD_SET_REVERSE_DISPLAY);
- else
- lcd_write_command(LCD_SET_NORMAL_DISPLAY);
-}
-
-/* turn the display upside down (call lcd_update() afterwards) */
-void lcd_set_flip(bool yesno)
-{
- if (yesno)
- {
- lcd_write_command(LCD_SET_SEGMENT_REMAP);
- lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION);
- }
- else
- {
- lcd_write_command(LCD_SET_SEGMENT_REMAP | 0x01);
- lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION | 0x08);
- }
-}
-
-void lcd_init_device(void)
-{
- LCDREG10 = 0xf;
- LCDREG04 = 0x4084;
-
- /* inits like the original firmware */
- lcd_write_command(LCD_SOFTWARE_RESET);
- lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO + 4);
- lcd_write_command(LCD_SET_LCD_BIAS);
- lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER + 7);
- /* power control register: op-amp=1, regulator=1, booster=1 */
- lcd_write_command(LCD_SET_DISPLAY_ON);
- lcd_write_command(LCD_SET_NORMAL_DISPLAY);
- lcd_set_flip(false);
- lcd_write_command(LCD_SET_DISPLAY_START_LINE + 0);
- lcd_set_contrast(lcd_default_contrast());
- lcd_write_command(LCD_SET_PAGE_ADDRESS);
- lcd_write_command(LCD_SET_LOWER_COLUMN_ADDRESS + 0);
- lcd_write_command(LCD_SET_HIGHER_COLUMN_ADDRESS + 0);
-
- lcd_clear_display();
- lcd_update();
-}
-
-/*** Update functions ***/
-
-/* Performance function that works with an external buffer
- note that by and bheight are in 8-pixel units! */
-void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
- int bheight, int stride)
-{
- /* Copy display bitmap to hardware */
- while (bheight--)
- {
- lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
- lcd_write_command (LCD_CNTL_HIGHCOL | (((x+4)>>4) & 0xf));
- lcd_write_command (LCD_CNTL_LOWCOL | ((x+4) & 0xf));
-
- lcd_write_data(data, width);
- data += stride;
- }
-}
-
-
-/* Performance function that works with an external buffer
- note that by and bheight are in 8-pixel units! */
-void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
- int x, int by, int width, int bheight, int stride)
-{
- (void)values;
- (void)phases;
- (void)x;
- (void)by;
- (void)width;
- (void)bheight;
- (void)stride;
-}
-
-/* Update the display.
- This must be called after all other LCD functions that change the display. */
-void lcd_update(void) ICODE_ATTR;
-void lcd_update(void)
-{
- int y;
-
- /* Copy display bitmap to hardware */
- for (y = 0; y < LCD_FBHEIGHT; y++)
- {
- lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
- lcd_write_command (LCD_CNTL_HIGHCOL);
- lcd_write_command (LCD_CNTL_LOWCOL | 4);
-
- lcd_write_data (FBADDR(0, y), LCD_WIDTH);
- }
-}
-
-/* Update a fraction of the display. */
-void lcd_update_rect(int, int, int, int) ICODE_ATTR;
-void lcd_update_rect(int x, int y, int width, int height)
-{
- int ymax;
-
- /* The Y coordinates have to work on even 8 pixel rows */
- ymax = (y + height-1) >> 3;
- y >>= 3;
-
- if(x + width > LCD_WIDTH)
- width = LCD_WIDTH - x;
- if (width <= 0)
- return; /* nothing left to do, 0 is harmful to lcd_write_data() */
- if(ymax >= LCD_FBHEIGHT)
- ymax = LCD_FBHEIGHT-1;
-
- /* Copy specified rectange bitmap to hardware */
- for (; y <= ymax; y++)
- {
- lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
- lcd_write_command (LCD_CNTL_HIGHCOL | (((x+4) >> 4) & 0xf));
- lcd_write_command (LCD_CNTL_LOWCOL | ((x+4) & 0xf));
-
- lcd_write_data (FBADDR(x,y), width);
- }
-}
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c
deleted file mode 100644
index 1fd9d68028..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Linus Nielsen Feltzing
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include <stdbool.h>
-#include "kernel.h"
-#include "system.h"
-#include "power.h"
-#include "logf.h"
-#include "usb.h"
-
-#if CONFIG_TUNER
-
-bool tuner_power(bool status)
-{
- (void)status;
- return true;
-}
-
-#endif /* #if CONFIG_TUNER */
-
-#ifndef SIMULATOR
-
-void power_init(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
- /* no ide controller */
-}
-
-bool ide_powered(void)
-{
- return true; /* pretend always powered if not controlable */
-}
-
-void power_off(void)
-{
- disable_interrupt(IRQ_FIQ_STATUS);
- GPIO1_CLR = 1 << 16;
- GPIO2_SET = 1;
- while(1);
-}
-
-#else
-
-void power_off(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#endif /* SIMULATOR */
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c
deleted file mode 100644
index 4ce90a4c4f..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
- * Revisions copyright (C) 2005 by Gerald Van Baren
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "adc.h"
-#include "powermgmt.h"
-
-const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
-{
- 1050, 1150
-};
-
-const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
-{
- 1050, 1150 /* FIXME: just copied from above, was missing in powermgmt.c */
-};
-
-/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
-const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
-{
- /* These values are the same as for Ondio divided by 3. */
- /* May need recalibration. */
- { 930, 1080, 1140, 1180, 1210, 1250, 1280, 1320, 1360, 1420, 1580 }, /* alkaline */
- { 1030, 1180, 1210, 1230, 1240, 1250, 1260, 1270, 1280, 1290, 1350 } /* NiMH */
-};
-
-/* TODO: only roughly correct */
-#define BATTERY_SCALE_FACTOR 3072
-/* full-scale ADC readout (2^10) in millivolt */
-
-/* Returns battery voltage from ADC [millivolts] */
-int _battery_voltage(void)
-{
- return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
-}
-
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/system-target.h b/firmware/target/arm/pnx0101/iriver-ifp7xx/system-target.h
deleted file mode 100644
index 9aad4a7b74..0000000000
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/system-target.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Alan Korr
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef SYSTEM_TARGET_H
-#define SYSTEM_TARGET_H
-
-#include "system-arm.h"
-
-#define CPUFREQ_DEFAULT 12000000
-#define CPUFREQ_NORMAL 48000000
-#define CPUFREQ_MAX 60000000
-
-typedef void (*interrupt_handler_t)(void);
-
-void irq_set_int_handler(int n, interrupt_handler_t handler);
-void irq_enable_int(int n);
-void irq_disable_int(int n);
-
-#endif /* SYSTEM_TARGET_H */
diff --git a/firmware/target/arm/pnx0101/kernel-pnx0101.c b/firmware/target/arm/pnx0101/kernel-pnx0101.c
deleted file mode 100644
index db0f1b0d7f..0000000000
--- a/firmware/target/arm/pnx0101/kernel-pnx0101.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Tomasz Malesinski
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "system.h"
-#include "kernel.h"
-
-void timer_handler(void)
-{
- /* Run through the list of tick tasks */
- call_tick_tasks();
-
- TIMER0.clr = 0;
-}
-
-void tick_start(unsigned int interval_in_ms)
-{
- TIMER0.ctrl &= ~0x80; /* Disable the counter */
- TIMER0.ctrl |= 0x40; /* Reload after counting down to zero */
- TIMER0.load = 3000000 * interval_in_ms / 1000;
- TIMER0.ctrl &= ~0xc; /* No prescaler */
- TIMER0.clr = 1; /* Clear the interrupt request */
-
- irq_set_int_handler(IRQ_TIMER0, timer_handler);
- irq_enable_int(IRQ_TIMER0);
-
- TIMER0.ctrl |= 0x80; /* Enable the counter */
-}
diff --git a/firmware/target/arm/pnx0101/pcm-pnx0101.c b/firmware/target/arm/pnx0101/pcm-pnx0101.c
deleted file mode 100644
index 6099dcb7ef..0000000000
--- a/firmware/target/arm/pnx0101/pcm-pnx0101.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2006 by Tomek Malesinski
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "system.h"
-#include "audio.h"
-#include "string.h"
-#include "pcm-internal.h"
-
-#define DMA_BUF_SAMPLES 0x100
-
-short __attribute__((section(".dmabuf"))) dma_buf_left[DMA_BUF_SAMPLES];
-short __attribute__((section(".dmabuf"))) dma_buf_right[DMA_BUF_SAMPLES];
-
-const int16_t* p IBSS_ATTR;
-size_t p_size IBSS_ATTR;
-
-void pcm_play_lock(void)
-{
-}
-
-void pcm_play_unlock(void)
-{
-}
-
-void pcm_play_dma_start(const void *addr, size_t size)
-{
- p = addr;
- p_size = size;
-}
-
-void pcm_play_dma_stop(void)
-{
-}
-
-static inline void fill_dma_buf(int offset)
-{
- short *l, *r, *lend;
-
- l = dma_buf_left + offset;
- lend = l + DMA_BUF_SAMPLES / 2;
- r = dma_buf_right + offset;
-
- if (pcm_playing)
- {
- bool new_buffer =false;
-
- do
- {
- int count;
- const int16_t *tmp_p;
- count = MIN(p_size / 4, (size_t)(lend - l));
- tmp_p = p;
- p_size -= count * 4;
-
- if ((int)l & 3)
- {
- *l++ = *tmp_p++;
- *r++ = *tmp_p++;
- count--;
- }
- while (count >= 4)
- {
- asm("ldmia %0!, {r0, r1, r2, r3}\n\t"
- "and r4, r0, %3\n\t"
- "orr r4, r4, r1, lsl #16\n\t"
- "and r5, r2, %3\n\t"
- "orr r5, r5, r3, lsl #16\n\t"
- "stmia %1!, {r4, r5}\n\t"
- "bic r4, r1, %3\n\t"
- "orr r4, r4, r0, lsr #16\n\t"
- "bic r5, r3, %3\n\t"
- "orr r5, r5, r2, lsr #16\n\t"
- "stmia %2!, {r4, r5}"
- : "+r" (tmp_p), "+r" (l), "+r" (r)
- : "r" (0xffff)
- : "r0", "r1", "r2", "r3", "r4", "r5", "memory");
- count -= 4;
- }
- while (count > 0)
- {
- *l++ = *tmp_p++;
- *r++ = *tmp_p++;
- count--;
- }
- p = tmp_p;
-
- if (new_buffer)
- {
- new_buffer = false;
- pcm_play_dma_status_callback(PCM_DMAST_STARTED);
- }
-
- if (l >= lend)
- return;
-
- new_buffer = pcm_play_dma_complete_callback(PCM_DMAST_OK,
- &p, &p_size);
- }
- while (p_size);
- }
-
- if (l < lend)
- {
- memset(l, 0, sizeof(short) * (lend - l));
- memset(r, 0, sizeof(short) * (lend - l));
- }
-}
-
-static void audio_irq(void)
-{
- unsigned long st = DMAINTSTAT & ~DMAINTEN;
- int i;
- for (i = 0; i < 2; i++)
- if (st & (1 << i))
- {
- fill_dma_buf((i == 1) ? 0 : DMA_BUF_SAMPLES / 2);
- DMAINTSTAT = 1 << i;
- }
-}
-
-unsigned long physical_address(void *p)
-{
- unsigned long adr = (unsigned long)p;
- return (MMUBLOCK((adr >> 21) & 0xf) << 21) | (adr & ((1 << 21) - 1));
-}
-
-void pcm_init(void)
-{
- int i;
-
- memset(dma_buf_left, 0, sizeof(dma_buf_left));
- memset(dma_buf_right, 0, sizeof(dma_buf_right));
-
- for (i = 0; i < 8; i++)
- {
- DMASRC(i) = 0;
- DMADEST(i) = 0;
- DMALEN(i) = 0x1ffff;
- DMAR0C(i) = 0;
- DMAR10(i) = 0;
- DMAR1C(i) = 0;
- }
-
- DMAINTSTAT = 0xc000ffff;
- DMAINTEN = 0xc000ffff;
-
- DMASRC(0) = physical_address(dma_buf_left);
- DMADEST(0) = 0x80200280;
- DMALEN(0) = 0xff;
- DMAR1C(0) = 0;
- DMAR0C(0) = 0x40408;
-
- DMASRC(1) = physical_address(dma_buf_right);
- DMADEST(1) = 0x80200284;
- DMALEN(1) = 0xff;
- DMAR1C(1) = 0;
- DMAR0C(1) = 0x40409;
-
- irq_set_int_handler(0x1b, audio_irq);
- irq_enable_int(0x1b);
-
- DMAINTSTAT = 1;
- DMAINTSTAT = 2;
- DMAINTEN &= ~3;
- DMAR10(0) |= 1;
- DMAR10(1) |= 1;
-}
-
-void pcm_play_dma_postinit(void)
-{
- audiohw_postinit();
-}
-
-void pcm_dma_apply_settings(void)
-{
-}
-
-const void * pcm_play_dma_get_peak_buffer(int *count)
-{
- unsigned long addr = (unsigned long)p;
- size_t cnt = p_size;
- *count = cnt >> 2;
- return (void *)((addr + 2) & ~3);
-}
-
-void audiohw_set_volume(int value)
-{
- int tmp = (60 - value * 4) & 0xff;
- CODECVOL = tmp | (tmp << 8);
-}
diff --git a/firmware/target/arm/pnx0101/system-pnx0101.c b/firmware/target/arm/pnx0101/system-pnx0101.c
deleted file mode 100644
index 63720d11be..0000000000
--- a/firmware/target/arm/pnx0101/system-pnx0101.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id: $
- *
- * Copyright (C) 2007 by Tomasz Malesinski
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include <stdlib.h>
-#include "pnx0101.h"
-#include "system.h"
-
-static struct
-{
- unsigned char freq;
- unsigned char sys_mult;
- unsigned char sys_div;
-}
-perf_modes[3] ICONST_ATTR =
-{
- {12, 4, 4},
- {48, 4, 1},
- {60, 5, 1}
-};
-
-static int performance_mode, bus_divider;
-
-static void cgu_set_sel_stage_input(int clock, int input)
-{
- int s = CGU.base_ssr[clock];
- if (s & 1)
- CGU.base_fs2[clock] = input;
- else
- CGU.base_fs1[clock] = input;
- CGU.base_scr[clock] = (s & 3) ^ 3;
-}
-
-static void cgu_reset_sel_stage_clocks(int first_esr, int n_esr,
- int first_div, int n_div)
-{
- int i;
- for (i = 0; i < n_esr; i++)
- CGU.clk_esr[first_esr + i] = 0;
- for (i = 0; i < n_div; i++)
- CGU.base_fdc[first_div + i] = 0;
-}
-
-static void cgu_configure_div(int div, int n, int m)
-{
- int msub, madd, div_size, max_n;
- unsigned long cfg;
-
- if (n == m)
- {
- CGU.base_fdc[div] = CGU.base_fdc[div] & ~1;
- return;
- }
-
- msub = -n;
- madd = m - n;
- div_size = (div == PNX0101_HIPREC_FDC) ? 10 : 8;
- max_n = 1 << div_size;
- while ((madd << 1) < max_n && (msub << 1) >= -max_n)
- {
- madd <<= 1;
- msub <<= 1;
- }
- cfg = (((msub << div_size) | madd) << 3) | 4;
- CGU.base_fdc[div] = CGU.base_fdc[div] & ~1;
- CGU.base_fdc[div] = cfg | 2;
- CGU.base_fdc[div] = cfg;
- CGU.base_fdc[div] = cfg | 1;
-}
-
-static void cgu_connect_div_to_clock(int rel_div, int esr)
-{
- CGU.clk_esr[esr] = (rel_div << 1) | 1;
-}
-
-static void cgu_enable_clock(int clock)
-{
- CGU.clk_pcr[clock] |= 1;
-}
-
-static void cgu_start_sel_stage_dividers(int bcr)
-{
- CGU.base_bcr[bcr] = 1;
-}
-
-/* Convert a pointer that points to IRAM (0x4xxxx) to a pointer that
- points to the uncached page (0x0xxxx) that is also mapped to IRAM. */
-static inline void *noncached(void *p)
-{
- return (void *)(((unsigned long)p) & 0xffff);
-}
-
-/* To avoid SRAM accesses while changing memory controller settings we
- run this routine from uncached copy of IRAM. All times are in CPU
- cycles. At CPU frequencies lower than 60 MHz we could use faster
- settings, but since DMA may access SRAM at any time, changing
- memory timings together with CPU frequency would be tricky. */
-static void do_set_mem_timings(void) ICODE_ATTR;
-static void do_set_mem_timings(void)
-{
- int old_irq = disable_irq_save();
- while ((EMC.status & 3) != 0);
- EMC.control = 5;
- EMCSTATIC0.waitrd = 6;
- EMCSTATIC0.waitwr = 5;
- EMCSTATIC1.waitrd = 5;
- EMCSTATIC1.waitwr = 4; /* OF uses 5 here */
- EMCSTATIC2.waitrd = 4;
- EMCSTATIC2.waitwr = 3;
- EMCSTATIC0.waitoen = 1;
- EMCSTATIC1.waitoen = 1;
- EMCSTATIC2.waitoen = 1;
- /* Enable write buffers for SRAM. */
-#ifndef DEBUG
- EMCSTATIC1.config = 0x80081;
-#endif
- EMC.control = 1;
- restore_irq(old_irq);
-}
-
-static void emc_set_mem_timings(void)
-{
- void (*f)(void) = noncached(do_set_mem_timings);
- (*f)();
-}
-
-static void cgu_set_sys_mult(int i)
-{
- cgu_set_sel_stage_input(PNX0101_SEL_STAGE_SYS, PNX0101_MAIN_CLOCK_FAST);
- cgu_set_sel_stage_input(PNX0101_SEL_STAGE_APB3, PNX0101_MAIN_CLOCK_FAST);
-
- PLL.lppdn = 1;
- PLL.lpfin = 1;
- PLL.lpmbyp = 0;
- PLL.lpdbyp = 0;
- PLL.lppsel = 1;
- PLL.lpmsel = i - 1;
- PLL.lppdn = 0;
- while (!PLL.lplock);
-
- cgu_configure_div(PNX0101_FIRST_DIV_SYS + 1, 1, (i == 5) ? 15 : 12);
- cgu_connect_div_to_clock(1, 0x11);
- cgu_enable_clock(0x11);
- cgu_start_sel_stage_dividers(PNX0101_BCR_SYS);
-
- cgu_set_sel_stage_input(PNX0101_SEL_STAGE_SYS,
- PNX0101_MAIN_CLOCK_MAIN_PLL);
- cgu_set_sel_stage_input(PNX0101_SEL_STAGE_APB3,
- PNX0101_MAIN_CLOCK_MAIN_PLL);
-}
-
-static void pnx0101_set_performance_mode(int mode)
-{
- int old = performance_mode;
- if (perf_modes[old].sys_mult != perf_modes[mode].sys_mult)
- cgu_set_sys_mult(perf_modes[mode].sys_mult);
- if (perf_modes[old].sys_div != perf_modes[mode].sys_div)
- cgu_configure_div(bus_divider, 1, perf_modes[mode].sys_div);
- performance_mode = mode;
-}
-
-static void pnx0101_init_clocks(void)
-{
- bus_divider = PNX0101_FIRST_DIV_SYS + (CGU.clk_esr[0] >> 1);
- performance_mode = 0;
- emc_set_mem_timings();
- pnx0101_set_performance_mode(2);
-
- cgu_set_sel_stage_input(PNX0101_SEL_STAGE_APB1,
- PNX0101_MAIN_CLOCK_FAST);
- cgu_reset_sel_stage_clocks(PNX0101_FIRST_ESR_APB1, PNX0101_N_ESR_APB1,
- PNX0101_FIRST_DIV_APB1, PNX0101_N_DIV_APB1);
- cgu_configure_div(PNX0101_FIRST_DIV_APB1, 1, 4);
- cgu_connect_div_to_clock(0, PNX0101_ESR_APB1);
- cgu_connect_div_to_clock(0, PNX0101_ESR_T0);
- cgu_connect_div_to_clock(0, PNX0101_ESR_T1);
- cgu_connect_div_to_clock(0, PNX0101_ESR_I2C);
- cgu_enable_clock(PNX0101_CLOCK_APB1);
- cgu_enable_clock(PNX0101_CLOCK_T0);
- cgu_enable_clock(PNX0101_CLOCK_T1);
- cgu_enable_clock(PNX0101_CLOCK_I2C);
-}
-
-#ifdef HAVE_ADJUSTABLE_CPU_FREQ
-void set_cpu_frequency(long frequency)
-{
- switch (frequency)
- {
- case CPUFREQ_MAX:
- pnx0101_set_performance_mode(2);
- cpu_frequency = CPUFREQ_MAX;
- break;
- case CPUFREQ_NORMAL:
- pnx0101_set_performance_mode(1);
- cpu_frequency = CPUFREQ_NORMAL;
- break;
- case CPUFREQ_DEFAULT:
- default:
- pnx0101_set_performance_mode(0);
- cpu_frequency = CPUFREQ_DEFAULT;
- break;
- }
-
-}
-#endif
-
-interrupt_handler_t interrupt_vector[0x1d] __attribute__ ((section(".idata")));
-
-#define IRQ_READ(reg, dest) \
- do { unsigned long v2; \
- do { \
- dest = (reg); \
- v2 = (reg); \
- } while ((dest != v2)); \
- } while (0);
-
-#define IRQ_WRITE_WAIT(reg, val, cond) \
- do { unsigned long v, v2; \
- do { \
- (reg) = (val); \
- v = (reg); \
- v2 = (reg); \
- } while ((v != v2) || !(cond)); \
- } while (0);
-
-static void undefined_int(void)
-{
-}
-
-void irq(void)
-{
- unsigned long n;
- IRQ_READ(INTVECTOR[0], n)
- (*(interrupt_vector[n >> 3]))();
-}
-
-void fiq(void)
-{
-}
-
-void irq_enable_int(int n)
-{
- IRQ_WRITE_WAIT(INTREQ[n], INTREQ_WEENABLE | INTREQ_ENABLE, v & 0x10000);
-}
-
-void irq_disable_int(int n)
-{
- IRQ_WRITE_WAIT(INTREQ[n], INTREQ_WEENABLE, (v & 0x10000) == 0);
-}
-
-void irq_set_int_handler(int n, interrupt_handler_t handler)
-{
- interrupt_vector[n] = handler;
-}
-
-void system_init(void)
-{
- int i;
-
- /* turn off watchdog */
- (*(volatile unsigned long *)0x80002804) = 0;
-
- /*
- IRQ_WRITE_WAIT(INTVECTOR[0], 0, v == 0);
- IRQ_WRITE_WAIT(INTVECTOR[1], 0, v == 0);
- IRQ_WRITE_WAIT(INTPRIOMASK[0], 0, v == 0);
- IRQ_WRITE_WAIT(INTPRIOMASK[1], 0, v == 0);
- */
-
- for (i = 1; i <= 0x1c; i++)
- {
- IRQ_WRITE_WAIT(INTREQ[i],
- INTREQ_WEPRIO | INTREQ_WETARGET |
- INTREQ_WEENABLE | INTREQ_WEACTVLO | 1,
- (v & 0x3010f) == 1);
- IRQ_WRITE_WAIT(INTREQ[i], INTREQ_WEENABLE, (v & 0x10000) == 0);
- IRQ_WRITE_WAIT(INTREQ[i], INTREQ_WEPRIO | 1, (v & 0xf) == 1);
- interrupt_vector[i] = undefined_int;
- }
- interrupt_vector[0] = undefined_int;
- pnx0101_init_clocks();
-}
-
-
-void system_reboot(void)
-{
- (*(volatile unsigned long *)0x80002804) = 1;
- while (1);
-}
-
-void system_exception_wait(void)
-{
- while (1);
-}
-
-int system_memory_guard(int newmode)
-{
- (void)newmode;
- return 0;
-}
diff --git a/firmware/target/arm/pnx0101/timer-pnx0101.c b/firmware/target/arm/pnx0101/timer-pnx0101.c
deleted file mode 100644
index 1ec1d2871f..0000000000
--- a/firmware/target/arm/pnx0101/timer-pnx0101.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/***************************************************************************
-* __________ __ ___.
-* Open \______ \ ____ ____ | | _\_ |__ _______ ___
-* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
-* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
-* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
-* \/ \/ \/ \/ \/
-* $Id$
-*
-* Copyright (C) 2007 Tomasz Malesinski
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
-* KIND, either express or implied.
-*
-****************************************************************************/
-
-#include "system.h"
-#include "timer.h"
-
-static long cycles_new = 0;
-
-void TIMER1_ISR(void)
-{
- if (cycles_new > 0)
- {
- TIMER1.load = cycles_new - 1;
- cycles_new = 0;
- }
- if (pfn_timer != NULL)
- {
- cycles_new = -1;
- /* "lock" the variable, in case timer_set_period()
- * is called within pfn_timer() */
- pfn_timer();
- cycles_new = 0;
- }
- TIMER1.clr = 1; /* clear the interrupt */
-}
-
-bool timer_set(long cycles, bool start)
-{
- if (start)
- {
- if (pfn_unregister != NULL)
- {
- pfn_unregister();
- pfn_unregister = NULL;
- }
- TIMER1.ctrl &= ~0x80; /* disable the counter */
- TIMER1.ctrl |= 0x40; /* reload after counting down to zero */
- TIMER1.ctrl &= ~0xc; /* no prescaler */
- TIMER1.clr = 1; /* clear an interrupt event */
- }
- if (start || (cycles_new == -1)) /* within isr, cycles_new is "locked" */
- { /* enable timer */
- TIMER1.load = cycles - 1;
- TIMER1.ctrl |= 0x80; /* enable the counter */
- }
- else
- cycles_new = cycles;
-
- return true;
-}
-
-bool timer_start(void)
-{
- irq_set_int_handler(IRQ_TIMER1, TIMER1_ISR);
- irq_enable_int(IRQ_TIMER1);
- return true;
-}
-
-void timer_stop(void)
-{
- TIMER1.ctrl &= ~0x80; /* disable timer 1 */
- irq_disable_int(IRQ_TIMER1);
-}
diff --git a/firmware/target/arm/pp/mi4-loader.c b/firmware/target/arm/pp/mi4-loader.c
index 31b0065888..0104496e9d 100644
--- a/firmware/target/arm/pp/mi4-loader.c
+++ b/firmware/target/arm/pp/mi4-loader.c
@@ -27,12 +27,11 @@
#include "config.h"
#include "mi4-loader.h"
#include "loader_strerror.h"
-#include "crc32-mi4.h"
+#include "crc32.h"
#include "file.h"
#if defined(HAVE_BOOTDATA)
#include "system.h"
#include "bootdata.h"
-#include "crc32.h"
/* Write bootdata into location in FIRMWARE marked by magic header
* Assumes buffer is already loaded with the firmware image
@@ -293,7 +292,7 @@ static int load_mi4_filename(unsigned char* buf,
return EREAD_IMAGE_FAILED;
/* Check CRC32 to see if we have a valid file */
- sum = chksum_crc32 (buf, mi4header.mi4size - MI4_HEADER_SIZE);
+ sum = crc_32r (buf, mi4header.mi4size - MI4_HEADER_SIZE, 0);
if(sum != mi4header.crc32)
return EBAD_CHKSUM;
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
index 6f6b58ca35..a14bffb81c 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/rtc-nano2g.c
@@ -45,9 +45,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return 0;
}
diff --git a/firmware/target/arm/s5l8702/ipod6g/rtc-6g.c b/firmware/target/arm/s5l8702/ipod6g/rtc-6g.c
index 384cded758..bf1b18035a 100644
--- a/firmware/target/arm/s5l8702/ipod6g/rtc-6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/rtc-6g.c
@@ -45,9 +45,9 @@ int rtc_read_datetime(struct tm *tm)
tm->tm_mday = buf[4];
tm->tm_mon = buf[5] - 1;
tm->tm_year = buf[6] + 100;
- tm->tm_yday = 0; /* Not implemented for now */
set_day_of_week(tm);
+ set_day_of_year(tm);
return 0;
}
diff --git a/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c b/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c
index 36d119aff3..72c7cc78c7 100644
--- a/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c
@@ -30,11 +30,26 @@
#include "s5l8702.h"
#include "led.h"
-
#ifndef ATA_RETRIES
#define ATA_RETRIES 3
#endif
+#define CMD_READ_SECTORS 0x20
+#define CMD_READ_DMA_EXT 0x25
+#define CMD_READ_MULTIPLE_EXT 0x29
+#define CMD_WRITE_SECTORS 0x30
+#define CMD_WRITE_DMA_EXT 0x35
+#define CMD_WRITE_MULTIPLE_EXT 0x39
+#ifdef HAVE_ATA_SMART
+#define CMD_SMART 0xB0
+#endif
+#define CMD_READ_MULTIPLE 0xC4
+#define CMD_WRITE_MULTIPLE 0xC5
+#define CMD_READ_DMA 0xC8
+#define CMD_WRITE_DMA 0xCA
+#define CMD_STANDBY_IMMEDIATE 0xE0
+#define CMD_IDENTIFY 0xEC
+#define CMD_SET_FEATURES 0xEF
#define CEATA_POWERUP_TIMEOUT 20000000
#define CEATA_COMMAND_TIMEOUT 1000000
@@ -482,7 +497,7 @@ static int ata_identify(uint16_t* buf)
if (ceata)
{
memset(ceata_taskfile, 0, 16);
- ceata_taskfile[0xf] = 0xec;
+ ceata_taskfile[0xf] = CMD_IDENTIFY;
PASS_RC(ceata_wait_idle(), 2, 0);
PASS_RC(ceata_write_multiple_register(0, ceata_taskfile, 16), 2, 1);
PASS_RC(ceata_rw_multiple_block(false, buf, 1, CEATA_COMMAND_TIMEOUT * HZ / 1000000), 2, 2);
@@ -491,7 +506,7 @@ static int ata_identify(uint16_t* buf)
{
PASS_RC(ata_wait_for_not_bsy(10000000), 1, 0);
ata_write_cbr(&ATA_PIO_DVR, 0);
- ata_write_cbr(&ATA_PIO_CSD, 0xec);
+ ata_write_cbr(&ATA_PIO_CSD, CMD_IDENTIFY);
PASS_RC(ata_wait_for_start_of_transfer(10000000), 1, 1);
for (i = 0; i < 0x100; i++) buf[i] = ata_read_cbr(&ATA_PIO_DTR);
}
@@ -515,7 +530,7 @@ static int ata_set_feature(uint32_t feature, uint32_t param)
memset(ceata_taskfile, 0, 16);
ceata_taskfile[0x1] = feature;
ceata_taskfile[0x2] = param;
- ceata_taskfile[0xf] = 0xef;
+ ceata_taskfile[0xf] = CMD_SET_FEATURES;
PASS_RC(ceata_wait_idle(), 2, 0);
PASS_RC(ceata_write_multiple_register(0, ceata_taskfile, 16), 2, 1);
PASS_RC(ceata_wait_idle(), 2, 2);
@@ -526,7 +541,7 @@ static int ata_set_feature(uint32_t feature, uint32_t param)
ata_write_cbr(&ATA_PIO_DVR, 0);
ata_write_cbr(&ATA_PIO_FED, feature);
ata_write_cbr(&ATA_PIO_SCR, param);
- ata_write_cbr(&ATA_PIO_CSD, 0xef);
+ ata_write_cbr(&ATA_PIO_CSD, CMD_SET_FEATURES);
PASS_RC(ata_wait_for_rdy(2000000), 2, 1);
}
return 0;
@@ -690,7 +705,7 @@ static void ata_power_down(void)
if (ceata)
{
memset(ceata_taskfile, 0, 16);
- ceata_taskfile[0xf] = 0xe0;
+ ceata_taskfile[0xf] = CMD_STANDBY_IMMEDIATE;
ceata_wait_idle();
ceata_write_multiple_register(0, ceata_taskfile, 16);
ceata_wait_idle();
@@ -701,7 +716,7 @@ static void ata_power_down(void)
{
ata_wait_for_rdy(1000000);
ata_write_cbr(&ATA_PIO_DVR, 0);
- ata_write_cbr(&ATA_PIO_CSD, 0xe0);
+ ata_write_cbr(&ATA_PIO_CSD, CMD_STANDBY_IMMEDIATE);
ata_wait_for_rdy(1000000);
sleep(HZ / 30);
ATA_CONTROL = 0;
@@ -730,7 +745,7 @@ static int ata_rw_chunk_internal(uint64_t sector, uint32_t cnt, void* buffer, bo
ceata_taskfile[0xb] = sector << 3;
ceata_taskfile[0xc] = sector >> 5;
ceata_taskfile[0xd] = sector >> 13;
- ceata_taskfile[0xf] = write ? 0x35 : 0x25;
+ ceata_taskfile[0xf] = write ? CMD_WRITE_DMA_EXT : CMD_READ_DMA_EXT;
PASS_RC(ceata_wait_idle(), 2, 0);
PASS_RC(ceata_write_multiple_register(0, ceata_taskfile, 16), 2, 1);
PASS_RC(ceata_rw_multiple_block(write, buffer, cnt << 3, CEATA_COMMAND_TIMEOUT * HZ / 1000000), 2, 2);
@@ -750,8 +765,10 @@ static int ata_rw_chunk_internal(uint64_t sector, uint32_t cnt, void* buffer, bo
ata_write_cbr(&ATA_PIO_LMR, (sector >> 5) & 0xff);
ata_write_cbr(&ATA_PIO_LLR, (sector << 3) & 0xff);
ata_write_cbr(&ATA_PIO_DVR, BIT(6));
- if (write) ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0x35 : 0x39);
- else ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0x25 : 0x29);
+ if (write)
+ ata_write_cbr(&ATA_PIO_CSD, ata_dma ? CMD_WRITE_DMA_EXT : CMD_WRITE_MULTIPLE_EXT);
+ else
+ ata_write_cbr(&ATA_PIO_CSD, ata_dma ? CMD_READ_DMA_EXT : CMD_READ_MULTIPLE_EXT);
}
else
{
@@ -760,8 +777,10 @@ static int ata_rw_chunk_internal(uint64_t sector, uint32_t cnt, void* buffer, bo
ata_write_cbr(&ATA_PIO_LMR, (sector >> 5) & 0xff);
ata_write_cbr(&ATA_PIO_LLR, (sector << 3) & 0xff);
ata_write_cbr(&ATA_PIO_DVR, BIT(6) | ((sector >> 21) & 0xf));
- if (write) ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0xca : 0x30);
- else ata_write_cbr(&ATA_PIO_CSD, ata_dma ? 0xc8 : 0xc4);
+ if (write)
+ ata_write_cbr(&ATA_PIO_CSD, ata_dma ? CMD_WRITE_DMA : CMD_WRITE_SECTORS);
+ else
+ ata_write_cbr(&ATA_PIO_CSD, ata_dma ? CMD_READ_DMA : CMD_READ_MULTIPLE);
}
if (ata_dma)
{
@@ -1017,7 +1036,7 @@ static int ata_smart(uint16_t* buf)
ceata_taskfile[0xc] = 0x4f;
ceata_taskfile[0xd] = 0xc2;
ceata_taskfile[0xe] = BIT(6);
- ceata_taskfile[0xf] = 0xb0;
+ ceata_taskfile[0xf] = CMD_SMART;
PASS_RC(ceata_wait_idle(), 3, 1);
if (((uint8_t*)ata_identify_data)[54] != 'A') /* Model != aAmsung */
{
@@ -1037,7 +1056,7 @@ static int ata_smart(uint16_t* buf)
ata_write_cbr(&ATA_PIO_LMR, 0x4f);
ata_write_cbr(&ATA_PIO_LHR, 0xc2);
ata_write_cbr(&ATA_PIO_DVR, BIT(6));
- ata_write_cbr(&ATA_PIO_CSD, 0xb0);
+ ata_write_cbr(&ATA_PIO_CSD, CMD_SMART);
PASS_RC(ata_wait_for_start_of_transfer(10000000), 3, 7);
for (i = 0; i < 0x100; i++) buf[i] = ata_read_cbr(&ATA_PIO_DTR);
}
diff --git a/firmware/target/arm/system-arm.h b/firmware/target/arm/system-arm.h
index e5d3f35001..af16346b51 100644
--- a/firmware/target/arm/system-arm.h
+++ b/firmware/target/arm/system-arm.h
@@ -382,7 +382,7 @@ static inline uint32_t swaw32_hw(uint32_t value)
}
-#if defined(CPU_TCC780X) || defined(CPU_TCC77X) /* Single core only for now */ \
+#if defined(CPU_TCC780X) /* Single core only for now */ \
|| CONFIG_CPU == IMX31L || CONFIG_CPU == DM320 || CONFIG_CPU == AS3525 \
|| CONFIG_CPU == S3C2440 || CONFIG_CPU == S5L8701 || CONFIG_CPU == AS3525v2 \
|| CONFIG_CPU == S5L8702
diff --git a/firmware/target/arm/tcc77x/adc-tcc77x.c b/firmware/target/arm/tcc77x/adc-tcc77x.c
deleted file mode 100644
index f48528639e..0000000000
--- a/firmware/target/arm/tcc77x/adc-tcc77x.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include "system.h"
-#include "kernel.h"
-#include "thread.h"
-#include "string.h"
-#include "adc.h"
-
-/**************************************************************************
- ** The A/D conversion is done every tick, in three steps:
- **
- ** 1) On the tick interrupt, the conversion of channels 0-3 is started, and
- ** the A/D interrupt is enabled.
- **
- ** 2) After the conversion is done, an interrupt
- ** is generated at level 1, which is the same level as the tick interrupt
- ** itself. This interrupt will be pending until the tick interrupt is
- ** finished.
- ** When the A/D interrupt is finally served, it will read the results
- ** from the first conversion and start the conversion of channels 4-7.
- **
- ** 3) When the conversion of channels 4-7 is finished, the interrupt is
- ** triggered again, and the results are read. This time, no new
- ** conversion is started, it will be done in the next tick interrupt.
- **
- ** Thus, each channel will be updated HZ times per second.
- **
- *************************************************************************/
-
-static int channel_group;
-static unsigned short adcdata[8];
-
-/* Tick task */
-static void adc_tick(void)
-{
- /* Start a conversion of channels 0-3. This will trigger an interrupt,
- and the interrupt handler will take care of channels 4-7. */
-
- int i;
-
- PCLKCFG6 |= (1<<15); /* Enable ADC clock */
-
- channel_group = 0;
-
- /* Start converting the first 4 channels */
- for (i = 0; i < 4; i++)
- ADCCON = i;
-
-}
-
-/* IRQ handler */
-void ADC(void)
-{
- int num;
- int i;
- uint32_t adc_status;
-
- do
- {
- adc_status = ADCSTATUS;
- num = (adc_status>>24) & 7;
- if (num) adcdata[(adc_status >> 16) & 0x7] = adc_status & 0x3ff;
- } while (num);
-
-
- if (channel_group == 0)
- {
- /* Start conversion of channels 4-7 */
- for (i = 4; i < 8; i++)
- ADCCON = i;
-
- channel_group = 1;
- }
- else
- {
- PCLKCFG6 &= ~(1<<15); /* Disable ADC clock */
- }
-}
-
-unsigned short adc_read(int channel)
-{
- return adcdata[channel];
-}
-
-void adc_init(void)
-{
- /* Initialize ADC clocks */
- PCLKCFG6 = (PCLKCFG6 & 0xffff0000) | 4004;
-
- ADCCON = (1<<4); /* Leave standby mode */
-
- /* IRQ enable, auto power-down, single-mode */
- ADCCFG |= (1<<3) | (1<<1) | (1<<0);
-
- /* Unmask ADC IRQ */
- IEN |= ADC_IRQ_MASK;
-
- tick_add_task(adc_tick);
-
- sleep(2); /* Ensure adc_data[] contains data before returning */
-}
diff --git a/firmware/target/arm/tcc77x/app.lds b/firmware/target/arm/tcc77x/app.lds
deleted file mode 100644
index 991b7156fe..0000000000
--- a/firmware/target/arm/tcc77x/app.lds
+++ /dev/null
@@ -1,99 +0,0 @@
-#include "config.h"
-
-ENTRY(start)
-OUTPUT_FORMAT(elf32-littlearm)
-OUTPUT_ARCH(arm)
-STARTUP(target/arm/tcc77x/crt0.o)
-
-#define PLUGINSIZE PLUGIN_BUFFER_SIZE
-#define CODECSIZE CODEC_SIZE
-
-#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGINSIZE - CODECSIZE
-
-#define DRAMORIG 0x20000000
-#define IRAMORIG 0x00000000
-#define IRAMSIZE 64K
-
-
-/* End of the audio buffer, where the codec buffer starts */
-#define ENDAUDIOADDR (DRAMORIG + DRAMSIZE)
-
-/* Where the codec buffer ends, and the plugin buffer starts */
-#define ENDADDR (ENDAUDIOADDR + CODECSIZE)
-
-
-MEMORY
-{
-#ifdef TCCBOOT
- DRAM : ORIGIN = DRAMORIG + DRAMSIZE - 0x100000, LENGTH = 0x100000
-#else
- DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE
-#endif
- IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE
-}
-
-SECTIONS
-{
- .text : {
- loadaddress = .;
- _loadaddress = .;
- . = ALIGN(0x200);
- *(.init.text)
- *(.text)
- *(.text*)
- *(.glue_7)
- *(.glue_7t)
- } > DRAM
-
- .data : {
- *(.icode)
- *(.irodata)
- *(.idata)
- *(.data*)
- *(.rodata.*)
- *(.rodata)
- . = ALIGN(0x4);
- _dataend = . ;
- } > DRAM
-
- .stack :
- {
- *(.stack)
- _stackbegin = .;
- stackbegin = .;
- . += 0x2000;
- _stackend = .;
- stackend = .;
- } > DRAM
-
- .bss : {
- _edata = .;
- *(.bss*);
- *(.ibss);
- *(COMMON)
- _end = .;
- } > DRAM
- .audiobuf ALIGN(4) :
- {
- _audiobuffer = .;
- audiobuffer = .;
- } > DRAM
-
- .audiobufend ENDAUDIOADDR:
- {
- audiobufend = .;
- _audiobufend = .;
- } > DRAM
-
- .codec ENDAUDIOADDR:
- {
- codecbuf = .;
- _codecbuf = .;
- }
-
- .plugin ENDADDR:
- {
- _pluginbuf = .;
- pluginbuf = .;
- }
-}
diff --git a/firmware/target/arm/tcc77x/ata-nand-target.h b/firmware/target/arm/tcc77x/ata-nand-target.h
deleted file mode 100644
index 93139a16d5..0000000000
--- a/firmware/target/arm/tcc77x/ata-nand-target.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef ATA_TARGET_H
-#define ATA_TARGET_H
-
-/* GPIOs */
-
-#define NAND_GPIO_SET(n) GPIOC |= n
-#define NAND_GPIO_CLEAR(n) GPIOC &= (~n)
-#define NAND_GPIO_OUT_EN(n) GPIOC_DIR |= n
-
-#define CS_GPIO_BIT (1<<24) /* Chip Select */
-#define WE_GPIO_BIT (1<<25) /* Write Enable */
-
-#endif
diff --git a/firmware/target/arm/tcc77x/boot.lds b/firmware/target/arm/tcc77x/boot.lds
deleted file mode 100644
index 6303de0c34..0000000000
--- a/firmware/target/arm/tcc77x/boot.lds
+++ /dev/null
@@ -1,63 +0,0 @@
-#include "config.h"
-
-ENTRY(start)
-OUTPUT_FORMAT(elf32-littlearm)
-OUTPUT_ARCH(arm)
-STARTUP(target/arm/tcc77x/crt0.o)
-
-#define DRAMSIZE (MEMORYSIZE * 0x100000)
-
-#define DRAMORIG 0x20000000
-#define IRAMORIG 0x00000000
-#define IRAMSIZE 64K
-
-
-MEMORY
-{
-#ifdef TCCBOOT
- DRAM : ORIGIN = DRAMORIG + DRAMSIZE - 0x100000, LENGTH = 0x100000
-#else
- DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE
-#endif
- IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE
-}
-
-SECTIONS
-{
- .text : {
- *(.init.text)
- *(.text)
- *(.text*)
- *(.glue_7)
- *(.glue_7t)
- } > DRAM
-
- .data : {
- *(.icode)
- *(.irodata)
- *(.idata)
- *(.data*)
- *(.rodata.*)
- *(.rodata)
- . = ALIGN(0x4);
- _dataend = . ;
- } > DRAM
-
- .stack (NOLOAD) :
- {
- *(.stack)
- _stackbegin = .;
- stackbegin = .;
- . += 0x2000;
- _stackend = .;
- stackend = .;
- } > DRAM
-
- .bss (NOLOAD) : {
- _edata = .;
- *(.bss*);
- *(.ibss);
- *(COMMON)
- _end = .;
- } > DRAM
-}
diff --git a/firmware/target/arm/tcc77x/c100/adc-target.h b/firmware/target/arm/tcc77x/c100/adc-target.h
deleted file mode 100644
index 0990d4d62d..0000000000
--- a/firmware/target/arm/tcc77x/c100/adc-target.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _ADC_TARGET_H_
-#define _ADC_TARGET_H_
-
-#define NUM_ADC_CHANNELS 8
-
-#endif /* _ADC_TARGET_H_ */
diff --git a/firmware/target/arm/tcc77x/c100/backlight-target.h b/firmware/target/arm/tcc77x/c100/backlight-target.h
deleted file mode 100644
index 7ae71022f0..0000000000
--- a/firmware/target/arm/tcc77x/c100/backlight-target.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef BACKLIGHT_TARGET_H
-#define BACKLIGHT_TARGET_H
-
-#include "tcc77x.h"
-
-#define backlight_hw_init() true
-
-static inline void backlight_hw_on(void)
-{
- /* Enable backlight */
- GPIOE |= 0x2;
-}
-
-static inline void backlight_hw_off(void)
-{
- /* Disable backlight */
- GPIOE &= ~0x2;
-}
-
-#endif
diff --git a/firmware/target/arm/tcc77x/c100/button-c100.c b/firmware/target/arm/tcc77x/c100/button-c100.c
deleted file mode 100644
index 47b004eb61..0000000000
--- a/firmware/target/arm/tcc77x/c100/button-c100.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "cpu.h"
-#include "button.h"
-
-void button_init_device(void)
-{
- GPIOA_DIR |= 0xC;
-}
-
-int button_read_device(void)
-{
- int btn = BUTTON_NONE;
-
- if (!button_hold())
- {
- GPIOA |= 0x4;
- GPIOA &= ~0x8;
-
- int i=20; while (i--);
-
- if (GPIOA & 0x10) btn |= BUTTON_UP;
- if (GPIOA & 0x20) btn |= BUTTON_RIGHT;
- if (GPIOA & 0x40) btn |= BUTTON_LEFT;
-
- GPIOA |= 0x8;
- GPIOA &= ~0x4;
-
- i=20; while (i--);
-
- if (GPIOA & 0x10) btn |= BUTTON_VOLUP;
- if (GPIOA & 0x20) btn |= BUTTON_VOLDOWN;
- if (GPIOA & 0x40) btn |= BUTTON_DOWN;
-
- if (GPIOA & 0x80) btn |= BUTTON_SELECT;
- if (GPIOA & 0x100) btn |= BUTTON_POWER;
- }
- return btn;
-}
-
-bool button_hold(void)
-{
- return (GPIOA & 0x2);
-}
diff --git a/firmware/target/arm/tcc77x/c100/button-target.h b/firmware/target/arm/tcc77x/c100/button-target.h
deleted file mode 100644
index 0e8b7e8f1c..0000000000
--- a/firmware/target/arm/tcc77x/c100/button-target.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#ifndef _BUTTON_TARGET_H_
-#define _BUTTON_TARGET_H_
-
-#define HAS_BUTTON_HOLD
-
-/* Main unit's buttons */
-#define BUTTON_POWER 0x00000001
-#define BUTTON_VOLUP 0x00000002
-#define BUTTON_VOLDOWN 0x00000004
-#define BUTTON_UP 0x00000008
-#define BUTTON_DOWN 0x00000010
-#define BUTTON_LEFT 0x00000020
-#define BUTTON_RIGHT 0x00000040
-#define BUTTON_SELECT 0x00000080
-
-#define BUTTON_MAIN (BUTTON_POWER|BUTTON_VOLUP|BUTTON_VOLDOWN\
- |BUTTON_UP|BUTTON_DOWN|BUTTON_LEFT\
- |BUTTON_RIGHT|BUTTON_SELECT)
-
-/* Software power-off */
-#define POWEROFF_BUTTON BUTTON_POWER
-#define POWEROFF_COUNT 40
-
-#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/tcc77x/c100/lcd-S6B33B2.c b/firmware/target/arm/tcc77x/c100/lcd-S6B33B2.c
deleted file mode 100644
index c53aadaf30..0000000000
--- a/firmware/target/arm/tcc77x/c100/lcd-S6B33B2.c
+++ /dev/null
@@ -1,286 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Mark Arigo
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include "lcd.h"
-#include "kernel.h"
-#include "system.h"
-
-/* Display status */
-static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
-
-/* LCD command set for Samsung S6B33B2 */
-#define R_NOP 0x00
-#define R_OSCILLATION_MODE 0x02
-#define R_DRIVER_OUTPUT_MODE 0x10
-#define R_DCDC_SET 0x20
-#define R_BIAS_SET 0x22
-#define R_DCDC_CLOCK_DIV 0x24
-#define R_DCDC_AMP_ONOFF 0x26
-#define R_TEMP_COMPENSATION 0x28
-#define R_CONTRAST_CONTROL1 0x2a
-#define R_CONTRAST_CONTROL2 0x2b
-#define R_STANDBY_OFF 0x2c
-#define R_STANDBY_ON 0x2d
-#define R_DDRAM_BURST_OFF 0x2e
-#define R_DDRAM_BURST_ON 0x2f
-#define R_ADDRESSING_MODE 0x30
-#define R_ROW_VECTOR_MODE 0x32
-#define R_N_LINE_INVERSION 0x34
-#define R_FRAME_FREQ_CONTROL 0x36
-#define R_RED_PALETTE 0x38
-#define R_GREEN_PALETTE 0x3a
-#define R_BLUE_PALETTE 0x3c
-#define R_ENTRY_MODE 0x40
-#define R_X_ADDR_AREA 0x42
-#define R_Y_ADDR_AREA 0x43
-#define R_RAM_SKIP_AREA 0x45
-#define R_DISPLAY_OFF 0x50
-#define R_DISPLAY_ON 0x51
-#define R_SPEC_DISPLAY_PATTERN 0x53
-#define R_PARTIAL_DISPLAY_MODE 0x55
-#define R_PARTIAL_START_LINE 0x56
-#define R_PARTIAL_END_LINE 0x57
-#define R_AREA_SCROLL_MODE 0x59
-#define R_SCROLL_START_LINE 0x5a
-#define R_DATA_FORMAT_SELECT 0x60
-
-/* TCC77x specific defines */
-#define LCD_BASE 0x50000000
-#define LCD_CMD *(volatile unsigned char*)(LCD_BASE)
-#define LCD_DATA *(volatile unsigned char*)(LCD_BASE+1)
-
-static void lcd_send_command(unsigned cmd)
-{
- LCD_CMD = cmd;
-
- asm volatile (
- "nop \n\t"
- "nop \n\t"
- "nop \n\t"
- );
-}
-
-static void lcd_send_data(unsigned data)
-{
- LCD_DATA = (data & 0xff00) >> 8;
- LCD_DATA = (data & 0x00ff);
-}
-
-/* End of TCC77x specific defines */
-
-/* LCD init */
-void lcd_init_device(void)
-{
- uint32_t bus_width;
-
- /* Telechips init the same as the original firmware */
- bus_width = ((MCFG >> 11) & 0x3) ^ 3;
-
- CSCFG1 = (bus_width << 28) |
- (3 << 26) | /* MTYPE = 3 */
- ((LCD_BASE >> 28) << 22) | /* CSBASE = 0x5 */
- (1 << 20) | /* Unknown */
- (2 << 11) | /* Setup time = 2 cycles */
- (2 << 3) | /* Pulse width = 2+1 cycles */
- (2 << 0); /* Hold time = 2 cycle */
-
- GPIOE &= ~0x8;
- sleep(HZ/100); /* 10ms */
-
- GPIOE |= 0x08;
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_STANDBY_OFF);
- sleep(HZ/20); /* 50ms */
-
- lcd_send_command(R_OSCILLATION_MODE);
- lcd_send_command(0x01);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_DCDC_AMP_ONOFF);
- lcd_send_command(0x01);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_DCDC_AMP_ONOFF);
- lcd_send_command(0x09);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_DCDC_AMP_ONOFF);
- lcd_send_command(0x0b);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_DCDC_AMP_ONOFF);
- lcd_send_command(0x0f);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_DCDC_SET);
- lcd_send_command(0x01);
- sleep(HZ/100); /* 10ms */
- sleep(HZ/10); /* 100ms */
-
- lcd_send_command(R_TEMP_COMPENSATION);
- lcd_send_command(0x01);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_DRIVER_OUTPUT_MODE);
- lcd_send_command(0x03);
-
- lcd_send_command(R_ENTRY_MODE);
- lcd_send_command(0x81);
-
- lcd_send_command(R_N_LINE_INVERSION);
- lcd_send_command(0x04);
- lcd_send_command(0xfa);
- lcd_send_command(0x5f);
-
- lcd_set_contrast(0x28);
-
- lcd_send_command(R_SPEC_DISPLAY_PATTERN);
- lcd_send_command(0x0);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_ADDRESSING_MODE);
- lcd_send_command(0x0);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_PARTIAL_DISPLAY_MODE);
- lcd_send_command(0x0);
- sleep(HZ/100); /* 10ms */
-
- lcd_send_command(R_X_ADDR_AREA);
- lcd_send_command(0);
- lcd_send_command(0x80);
-
- lcd_send_command(R_Y_ADDR_AREA);
- lcd_send_command(0x0);
- lcd_send_command(0x80);
-
- lcd_send_command(R_DISPLAY_ON);
-
- lcd_send_command(R_SPEC_DISPLAY_PATTERN);
- lcd_send_command(0x0);
-
- /* Rockbox init */
- lcd_clear_display();
- lcd_update();
-}
-
-/*** hardware configuration ***/
-int lcd_default_contrast(void)
-{
- return 0x28;
-}
-
-void lcd_set_contrast(int val)
-{
- //val &= 0xFF;
- lcd_send_command(R_CONTRAST_CONTROL1);
- lcd_send_command(val);
-}
-
-void lcd_set_invert_display(bool yesno)
-{
- /* TODO: Implement lcd_set_invert_display() */
- (void)yesno;
-}
-
-/* turn the display upside down (call lcd_update() afterwards) */
-void lcd_set_flip(bool yesno)
-{
- lcd_send_command(R_DRIVER_OUTPUT_MODE);
- lcd_send_command(yesno ? 0x02 : 0x07);
-}
-
-/*** update functions ***/
-void lcd_yuv_set_options(unsigned options)
-{
- lcd_yuv_options = options;
-}
-
-/* TODO: implement me */
-void lcd_blit_yuv(unsigned char *const src[3],
- int src_x, int src_y, int stride,
- int x, int y, int width, int height)
-{
- (void) src;
- (void) src_x;
- (void) src_y;
- (void) stride;
- (void) x;
- (void) y;
-
- return;
-
-}
-
-/* Update the display.
- This must be called after all other LCD functions that change the display. */
-void lcd_update(void)
-{
- lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
-}
-
-/* Update a fraction of the display. */
-void lcd_update_rect(int x, int y, int width, int height)
-{
- const fb_data *addr;
-
- if (x + width >= LCD_WIDTH)
- width = LCD_WIDTH - x;
- if (y + height >= LCD_HEIGHT)
- height = LCD_HEIGHT - y;
-
- if ((width <= 0) || (height <= 0))
- return; /* Nothing left to do. */
-
- addr = FBADDR(x,y);
-
- if (width <= 1) {
- lcd_send_command(R_ENTRY_MODE); /* The X end address must be larger */
- lcd_send_command(0x80); /* that the X start address, so we */
- lcd_send_command(R_X_ADDR_AREA); /* switch to vertical mode for */
- lcd_send_command(x); /* single column updates and set */
- lcd_send_command(x + 1); /* the window width to 2 */
- } else {
- lcd_send_command(R_ENTRY_MODE);
- lcd_send_command(0x82);
- lcd_send_command(R_X_ADDR_AREA);
- lcd_send_command(x);
- lcd_send_command(x + width - 1);
- }
-
- lcd_send_command(R_Y_ADDR_AREA);
- lcd_send_command(y);
- lcd_send_command(y + height - 1);
-
- /* NOP needed because on some c200s, the previous lcd_send_command is
- interpreted as a separate command instead of part of R_Y_ADDR_AREA. */
- lcd_send_command(R_NOP);
-
- do {
- int w = width;
- do {
- lcd_send_data(*addr++);
- } while (--w > 0);
- addr += LCD_WIDTH - width;
- } while (--height > 0);
-}
diff --git a/firmware/target/arm/tcc77x/c100/power-c100.c b/firmware/target/arm/tcc77x/c100/power-c100.c
deleted file mode 100644
index e84ff1c852..0000000000
--- a/firmware/target/arm/tcc77x/c100/power-c100.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include <stdbool.h>
-#include "kernel.h"
-#include "system.h"
-#include "power.h"
-
-void power_init(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
-}
-
-bool ide_powered(void)
-{
- return true;
-}
-
-void power_off(void)
-{
-}
diff --git a/firmware/target/arm/tcc77x/crt0.S b/firmware/target/arm/tcc77x/crt0.S
deleted file mode 100644
index aebd8974da..0000000000
--- a/firmware/target/arm/tcc77x/crt0.S
+++ /dev/null
@@ -1,230 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2002 by Linus Nielsen Feltzing
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-/* Arm bootloader and startup code based on startup.s from the iPodLinux loader
- *
- * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
- * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
- *
- */
-
-#include "config.h"
-#include "cpu.h"
-
- .section .init.text,"ax",%progbits
-
- .extern irq
- .extern fiq
- .extern UIE
- .extern main
-
- .global start
-
-/* Telechips firmware files start with a 32-byte header, as part of the code. */
-
-start:
-#ifdef TCCBOOT
- /* Add -DTCCBOOT to EXTRA_DEFINES in the bootloader Makefile to
- enable building the bootloader to be appended to the end of the
- original firmware, dual-booting based on a key-press.
-
- The following two values are filled in by mktccboot.
- */
-of_entrypoint: .word 0 /* Saved entrypoint of original firmware*/
-bl_entrypoint: .word 0 /* Location in RAM of the start of our bootloader */
-
-#else
-// ldr pc, =start_loc /* jump to the main entry point */
- b start_loc
-
- .word 0xffff0601 /* Unknown magic */
- .word 0x3a726556 /* "Ver:" */
- .word 0x31373030 /* "0071" */
- .word 0 /* First CRC32 */
- .word 0 /* Unknown - always 0 */
- .word 0 /* Second CRC32 */
- .word 0 /* length of firmware file */
-
-#if defined(LOGIK_DAX) || defined(SANSA_C100)
- /* Some original firmwares have 0x40 bytes of zeroes here - we
- don't know why, but err on the side of caution and include it
- here. */
- .space 0x40
-#endif
-#endif
-
-start_loc:
-
-#ifdef BOOTLOADER
-
-/*
- If we are appended to the OF (i.e. dual-booting), do a simple GPIO
- button check, and branch to the OF's entry point (saved by mktccboot)
- if not active
-*/
-
-#ifdef TCCBOOT
- mov r0, #0x80000000
-#if defined(LOGIK_DAX) || defined(SANSA_C100)
- ldr r0, [r0, #0x300] /* Hold button is GPIO A, pin 0x2 */
- tst r0, #0x2
-#elif defined(SANSA_M200)
- ldr r0, [r0, #0x310] /* Hold button is GPIO B, pin 0x200 */
- tst r0, #0x200
-#elif defined(IAUDIO_7)
- ldr r0, [r0, #0x300] /* Hold button is !GPIO A, pin 0x2 */
- tst r0, #0x2
-#else
- #error No bootup key detection implemented for this target
-#endif
-
- ldrne pc, of_entrypoint /* Jump to OF if HOLD button not pressed */
-#endif /* TCCBOOT */
-
-/* We are now definitely executing the bootloader, so we relocate to the
- linked address (see boot.lds) - 1MB from the end of DRAM.
-*/
-
-#ifdef TCCBOOT
- ldr r0, bl_entrypoint
-#else
- mov r0, #0x20000000 /* Otherwise, load address is the start of DRAM */
-#endif
- mov r1, #0x20000000 /* Destination: 1MB from end of DRAM */
- add r1, r1, #((MEMORYSIZE - 1) * 0x100000)
-
- ldr r2, =_dataend
-1:
- cmp r2, r1
- ldrhi r3, [r0], #4
- strhi r3, [r1], #4
- bhi 1b
-
- ldr pc, =copied_start /* jump to the relocated start_loc: */
-copied_start:
-#endif /* BOOTLOADER */
-
- /* Set up stack for IRQ mode */
- mov r0,#0xd2
- msr cpsr, r0
- ldr sp, =irq_stack
-
- /* Set up stack for FIQ mode */
- mov r0,#0xd1
- msr cpsr, r0
- ldr sp, =fiq_stack
-
-#ifndef BOOTLOADER
- /* Load the banked FIQ mode registers with useful values here.
- These values will be used in the FIQ handler in pcm-telechips.c */
- .equ DADO_BASE, 0x80000020
-
- ldr r10, =DADO_BASE
- ldr r11, =dma_play_data
-#endif
-
- /* Let svc, abort and undefined modes use irq stack */
- msr cpsr, #0xd3
- ldr sp, =irq_stack
- msr cpsr, #0xd7
- ldr sp, =irq_stack
- msr cpsr, #0xdb
- ldr sp, =irq_stack
-
- /* Switch to sys mode */
- mov r0,#0xdf
- msr cpsr, r0
- ldr sp, =stackend
-
- /* Copy exception handler code to address 0 */
- mov r2, #0x0
- ldr r3, =vectors_start
- ldr r4, =vectors_end
-1:
- cmp r4, r3
- ldrhi r5, [r3], #4
- strhi r5, [r2], #4
- bhi 1b
-
- /* Initialise bss section to zero */
- ldr r2, =_edata
- ldr r3, =_end
- mov r4, #0
-1:
- cmp r3, r2
- strhi r4, [r2], #4
- bhi 1b
-
- /* Set up some stack and munge it with 0xdeadbeef */
- ldr sp, =stackend
- mov r3, sp
- ldr r2, =stackbegin
- ldr r4, =0xdeadbeef
-1:
- cmp r3, r2
- strhi r4, [r2], #4
- bhi 1b
-
- bl main
- /* main() should never return */
-
-/* Exception handlers. Will be copied to address 0 after memory remapping */
-vectors_start:
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
- ldr pc, [pc, #24]
-
- /* Exception vectors */
- .global vectors
-vectors:
- .word start
- .word undef_instr_handler
- .word software_int_handler
- .word prefetch_abort_handler
- .word data_abort_handler
- .word reserved_handler
- .word irq_handler
- .word fiq_handler
-vectors_end:
-
- .text
-
-irq_handler:
- stmfd sp!, {r0-r3, r12, lr}
- bl irq
- ldmfd sp!, {r0-r3, r12, lr}
- subs pc, lr, #4
-
-/* Align stacks to cache line boundary */
- .balign 16
-
-/* 256 words of IRQ stack */
- .space 256*4
-irq_stack:
-
-/* 256 words of FIQ stack */
- .space 256*4
-fiq_stack:
diff --git a/firmware/target/arm/tcc77x/debug-tcc77x.c b/firmware/target/arm/tcc77x/debug-tcc77x.c
deleted file mode 100644
index 5a97706722..0000000000
--- a/firmware/target/arm/tcc77x/debug-tcc77x.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Rob Purchase
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "cpu.h"
-#include "system.h"
-#include "string.h"
-#include <stdio.h>
-#include <stdbool.h>
-#include "button.h"
-#include "lcd.h"
-#include "font.h"
-#include "adc.h"
-
-bool dbg_ports(void)
-{
- return false;
-}
-
-bool dbg_hw_info(void)
-{
- int line = 0, i, button, oldline;
- bool done=false;
-
- lcd_setfont(FONT_SYSFIXED);
- lcd_clear_display();
-
- /* Put all the static text before the while loop */
- lcd_puts(0, line++, "[Hardware info]");
-
- line++;
- oldline=line;
- while(!done)
- {
- line = oldline;
- button = button_get(false);
-
- button &= ~BUTTON_REPEAT;
-#ifdef BUTTON_SELECT
- if (button == BUTTON_SELECT)
-#else
- if (button == BUTTON_STOP)
-#endif
- done=true;
-
- lcd_putsf(0, line++, "current tick: %08lx Seconds running: %08ld",
- current_tick, current_tick/HZ);
-
- lcd_putsf(0, line++, "GPIOA: 0x%08lx GPIOB: 0x%08lx", GPIOA, GPIOB);
- lcd_putsf(0, line++, "GPIOC: 0x%08lx GPIOD: 0x%08lx", GPIOC, GPIOD);
- lcd_putsf(0, line++, "GPIOE: 0x%08lx", GPIOE);
-
- for (i = 0; i<4; i++)
- lcd_putsf(0, line++, "ADC%d: 0x%04x", i, adc_read(i));
-
- lcd_update();
- }
- return false;
-}
diff --git a/firmware/target/arm/tcc77x/i2c-target.h b/firmware/target/arm/tcc77x/i2c-target.h
deleted file mode 100644
index 9b9a74b4d2..0000000000
--- a/firmware/target/arm/tcc77x/i2c-target.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 by Rob Purchase
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef I2C_TARGET_H
-#define I2C_TARGET_H
-
-/* Definitions for the TCC77X I2C bus */
-
-#define SDA_BIT (1<<10)
-#define SCL_BIT (1<<11)
-
-#define SCL (GPIOB & SCL_BIT)
-#define SCL_HI GPIOB |= SCL_BIT
-#define SCL_LO GPIOB &= ~SCL_BIT
-
-#define SDA (GPIOB & SDA_BIT)
-#define SDA_HI GPIOB |= SDA_BIT
-#define SDA_LO GPIOB &= ~SDA_BIT
-#define SDA_INPUT GPIOB_DIR &= ~SDA_BIT
-#define SDA_OUTPUT GPIOB_DIR |= SDA_BIT
-
-#endif /* I2C_TARGET_H */
diff --git a/firmware/target/arm/tcc77x/iaudio7/adc-target.h b/firmware/target/arm/tcc77x/iaudio7/adc-target.h
deleted file mode 100644
index 1916d93598..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/adc-target.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _ADC_TARGET_H_
-#define _ADC_TARGET_H_
-
-#define NUM_ADC_CHANNELS 8
-
-#define ADC_BUTTONS 0
-
-#endif /* _ADC_TARGET_H_ */
diff --git a/firmware/target/arm/tcc77x/iaudio7/ata2501.c b/firmware/target/arm/tcc77x/iaudio7/ata2501.c
deleted file mode 100644
index f7526b2b9a..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/ata2501.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 Vitja Makarov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "system.h"
-#include "cpu.h"
-#include "button.h"
-
-#include "ata2501.h"
-
-#define STB (1<<5)
-#define SDATA (1<<4)
-#define RESET (1<<6)
-#define SIFMD (1<<7)
-#define STB_DELAY 200
-
-static inline void ndelay(unsigned long nsecs)
-{
- nsecs /= 8;
- while (nsecs)
- nsecs--;
-}
-
-/*
- TODO: sensitivity
-*/
-void ata2501_init(void)
-{
- GPIOD_DIR |= (RESET | STB | SIFMD | (1 << 8) | (1 << 9));
- GPIOD_DIR &= ~SDATA;
-
- GPIOD &= ~STB;
- GPIOD |= (1 << 8) | SIFMD | (1 << 9);
-
- GPIOD &= ~RESET;
- ndelay(1000);
- GPIOD |= RESET;
-}
-
-unsigned short ata2501_read(void)
-{
- unsigned short ret = 0;
- int i;
-
- for (i = 0; i < 12; i++) {
- GPIOD |= STB;
- ndelay(100);
- ret <<= 1;
- if (GPIOD & SDATA)
- ret |= 1;
- GPIOD &= ~STB;
- ndelay(100);
- }
-
- return ret;
-}
-
-//#define ATA2501_TEST
-#ifdef ATA2501_TEST
-#include "lcd.h"
-
-static
-void bits(char *str, unsigned short val)
-{
- int i;
-
- for (i = 0; i < 12; i++)
- str[i] = (val & (1 << i)) ? '1' : '0';
- str[i] = 0;
-}
-
-void ata2501_test(void)
-{
- char buf[100];
- ata2501_init();
-
- while (1) {
- unsigned short data;
- int line = 0;
-
- data = ata2501_read();
- lcd_clear_display();
- lcd_puts(0, line++, "ATA2501 test");
-
- bits(buf, data);
- lcd_puts(0, line++, buf);
-
- lcd_update();
- sleep(HZ/10);
- }
-}
-#endif
diff --git a/firmware/target/arm/tcc77x/iaudio7/ata2501.h b/firmware/target/arm/tcc77x/iaudio7/ata2501.h
deleted file mode 100644
index 465d0b199c..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/ata2501.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 Vitja Makarov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _ATA2501_H_
-#define _ATA2501_H_
-
-void ata2501_init(void);
-unsigned short ata2501_read(void);
-
-#endif /* _ATA2501_H_ */
diff --git a/firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c
deleted file mode 100644
index bcb6843286..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/audio-iaudio7.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Michael Sevakis
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "system.h"
-#include "cpu.h"
-#include "audio.h"
-#include "sound.h"
-
-int audio_channels = 2;
-int audio_output_source = AUDIO_SRC_PLAYBACK;
-
-void audio_set_output_source(int source)
-{
- int oldmode = set_fiq_status(FIQ_DISABLED);
-
- if ((unsigned)source >= AUDIO_NUM_SOURCES)
- source = AUDIO_SRC_PLAYBACK;
-
- audio_output_source = source;
- set_fiq_status(oldmode);
-}
-
-void audio_input_mux(int source, unsigned flags)
-{
- static int last_source = AUDIO_SRC_PLAYBACK;
- static bool last_recording = false;
- bool recording = flags & SRCF_RECORDING;
-
- switch (source)
- {
- default: /* playback - no recording */
- source = AUDIO_SRC_PLAYBACK;
- case AUDIO_SRC_PLAYBACK:
- audio_channels = 2;
- if (source != last_source)
- {
- audiohw_set_monitor(false);
- /* audiohw_disable_recording();*/
- }
- break;
-
- case AUDIO_SRC_MIC: /* recording only */
- GPIOD |= 0x1;
-
- audio_channels = 1;
- if (source != last_source)
- {
- /*audiohw_set_monitor(false);
- audiohw_enable_recording(true); /. source mic */
- }
- break;
-
- case AUDIO_SRC_FMRADIO: /* recording and playback */
- GPIOD &= ~0x1;
-
- audio_channels = 2;
-
- if (source == last_source && recording == last_recording)
- break;
-
- last_recording = recording;
-
- if (recording)
- {
- /*audiohw_set_monitor(false);
- audiohw_enable_recording(false);*/
- }
- else
- {
- /*audiohw_disable_recording(); */
- audiohw_set_monitor(true); /* line 1 analog audio path */
- }
- break;
- } /* end switch */
-
- last_source = source;
-} /* audio_input_mux */
diff --git a/firmware/target/arm/tcc77x/iaudio7/backlight-target.h b/firmware/target/arm/tcc77x/iaudio7/backlight-target.h
deleted file mode 100644
index 0b227cd11c..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/backlight-target.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 Vitja Makarov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef BACKLIGHT_TARGET_H
-#define BACKLIGHT_TARGET_H
-
-#include <stdbool.h>
-#include "tcc77x.h"
-
-void power_touch_panel(bool on);
-
-static inline bool backlight_hw_init(void)
-{
- GPIOD_DIR |= 0x2;
- /* set backlight on by default, since the screen is unreadable without it */
- GPIOD |= 0x2;
- return true;
-}
-
-static inline void backlight_hw_on(void)
-{
- GPIOD |= 0x2;
- power_touch_panel(true);
-}
-
-static inline void backlight_hw_off(void)
-{
- GPIOD &= ~0x2;
- power_touch_panel(false);
-}
-#endif /* BACKLIGHT_TARGET_H */
diff --git a/firmware/target/arm/tcc77x/iaudio7/button-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/button-iaudio7.c
deleted file mode 100644
index abf31b4feb..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/button-iaudio7.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 Vitja Makarov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include "button.h"
-#include "backlight.h"
-#include "adc.h"
-
-#include "button-target.h"
-#include "ata2501.h"
-
-void button_init_device(void)
-{
- ata2501_init();
-}
-
-/*
- touchpad:
- 0: stop
- 1-8: between next & prev
- 9: play
- 10: next
- 11: prev
-*/
-
-int button_read_device(void)
-{
- static bool hold_button = false;
- bool hold_button_old;
-
- int btn = BUTTON_NONE;
- int adc;
- int sensor;
-
- hold_button_old = hold_button;
- hold_button = button_hold();
-
-#ifndef BOOTLOADER
- if (hold_button != hold_button_old)
- backlight_hold_changed(hold_button);
-#endif
-
- if (button_hold())
- return BUTTON_NONE;
-
- adc = adc_read(0);
- sensor = ata2501_read();
-
- if (0 == (GPIOA & 4))
- btn |= BUTTON_POWER;
-
- /* seems they can't be hold together */
- if (adc < 0x120)
- btn |= BUTTON_VOLUP;
- else if (adc < 0x270)
- btn |= BUTTON_VOLDOWN;
- else if (adc < 0x300)
- btn |= BUTTON_MENU;
-
- if (sensor & (1 << 0))
- btn |= BUTTON_STOP;
- if (sensor & (1 << 9))
- btn |= BUTTON_PLAY;
- if (sensor & ((1 << 10) | 0x1c0))
- btn |= BUTTON_RIGHT;
- if (sensor & ((1 << 11) | 0xe))
- btn |= BUTTON_LEFT;
-
- return btn;
-}
-
-bool button_hold(void)
-{
- return !(GPIOA & 0x2);
-}
diff --git a/firmware/target/arm/tcc77x/iaudio7/button-target.h b/firmware/target/arm/tcc77x/iaudio7/button-target.h
deleted file mode 100644
index 9d232d9ae8..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/button-target.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 Vitja Makarov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _IAUDIO7_BUTTON_TARGET_H_
-#define _IAUDIO7_BUTTON_TARGET_H_
-
-#define HAS_BUTTON_HOLD
-
-/* Main unit's buttons */
-#define BUTTON_POWER 0x00000001
-#define BUTTON_VOLUP 0x00000002
-#define BUTTON_VOLDOWN 0x00000004
-#define BUTTON_MENU 0x00000008
-
-#define BUTTON_LEFT 0x00000010
-#define BUTTON_RIGHT 0x00000020
-#define BUTTON_PLAY 0x00000040
-#define BUTTON_STOP 0x00000080
-
-#define BUTTON_ON BUTTON_POWER
-
-#define BUTTON_MAIN (BUTTON_POWER|BUTTON_VOLUP|BUTTON_VOLDOWN| \
- BUTTON_MENU|BUTTON_LEFT|BUTTON_RIGHT| \
- BUTTON_PLAY|BUTTON_STOP)
-
-/* Software power-off */
-#define POWEROFF_BUTTON BUTTON_POWER
-#define POWEROFF_COUNT 10
-
-#endif /* _IAUDIO7_BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c
deleted file mode 100644
index e681e1eff7..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/lcd-iaudio7.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2004 by Linus Nielsen Feltzing
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-/*
- Thanks Hein-Pieter van Braam for initial work.
-
- Mostly based on lcd-h300.c, adapted for the iaudio 7 by Vitja Makarov
- */
-
-#include <config.h>
-
-#include <kernel.h>
-#include <cpu.h>
-#include <lcd.h>
-#include <system-target.h>
-#include <panic.h>
-
-#include "hd66789r.h"
-
-static bool display_on = false; /* is the display turned on? */
-
-static inline void lcd_write_reg(int reg, int data)
-{
- GPIOA &= ~0x400;
- outw(0, 0x50010000);
- outw(reg << 1, 0x50010000);
- GPIOA |= 0x400;
-
- outw((data & 0xff00) >> 7, 0x50010008);
- outw((data << 24) >> 23, 0x50010008);
-}
-
-static void lcd_write_cmd(int reg)
-{
- GPIOA &= ~0x400;
- outw(0, 0x50010000);
- outw(reg << 1, 0x50010000);
- GPIOA |= 0x400;
-}
-
-/* Do what OF do */
-static void lcd_delay(int x)
-{
- int i;
-
- x *= 0xc35;
- for (i = 0; i < x * 8; i++) {
- }
-}
-
-
-static void _display_on(void)
-{
- GPIOA_DIR |= 0x8000 | 0x400;
- GPIOA |= 0x8000;
-
- /* power setup */
- lcd_write_reg(R_START_OSC, 0x0001);
- lcd_delay(0xf);
- lcd_write_reg(R_DISP_CONTROL1, 0x000);
- lcd_delay(0xa);
- lcd_write_reg(R_POWER_CONTROL2, 0x0002);
- lcd_write_reg(R_POWER_CONTROL3, 0x000a);
- lcd_write_reg(R_POWER_CONTROL4, 0xc5a);
- lcd_write_reg(R_POWER_CONTROL1, 0x0004);
- lcd_write_reg(R_POWER_CONTROL1, 0x0134);
- lcd_write_reg(R_POWER_CONTROL2, 0x0111);
- lcd_write_reg(R_POWER_CONTROL3, 0x001c);
- lcd_delay(0x28);
- lcd_write_reg(R_POWER_CONTROL4, 0x2c40);
- lcd_write_reg(R_POWER_CONTROL1, 0x0510);
- lcd_delay(0x3c);
-
- /* lcd init 2 */
- lcd_write_reg(R_DRV_OUTPUT_CONTROL, 0x0113);
- lcd_write_reg(R_DRV_WAVEFORM_CONTROL, 0x0700);
- lcd_write_reg(R_ENTRY_MODE, 0x1038);
- lcd_write_reg(R_DISP_CONTROL2, 0x0508); // 0x3c8, TMM
- lcd_write_reg(R_DISP_CONTROL3, 0x0000);
- lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0003);
- lcd_write_reg(R_RAM_ADDR_SET, 0x0000);
- lcd_write_reg(R_GAMMA_FINE_ADJ_POS1, 0x0406);
- lcd_write_reg(R_GAMMA_FINE_ADJ_POS2, 0x0303);
- lcd_write_reg(R_GAMMA_FINE_ADJ_POS3, 0x0000);
- lcd_write_reg(R_GAMMA_GRAD_ADJ_POS, 0x0305);
- lcd_write_reg(R_GAMMA_FINE_ADJ_NEG1, 0x0404);
- lcd_write_reg(R_GAMMA_FINE_ADJ_NEG2, 0x0000);
- lcd_write_reg(R_GAMMA_FINE_ADJ_NEG3, 0x0000);
- lcd_write_reg(R_GAMMA_GRAD_ADJ_NEG, 0x0503);
- lcd_write_reg(R_GAMMA_AMP_ADJ_RES_POS, 0x1d05);
- lcd_write_reg(R_GAMMA_AMP_AVG_ADJ_RES_NEG, 0x1d05);
- lcd_write_reg(R_VERT_SCROLL_CONTROL, 0x0000);
- lcd_write_reg(R_1ST_SCR_DRV_POS, 0x9f00);
- lcd_write_reg(R_2ND_SCR_DRV_POS, 0x9f00);
- lcd_write_reg(R_HORIZ_RAM_ADDR_POS, 0x7f00);
- lcd_write_reg(R_VERT_RAM_ADDR_POS, 0x9f00);
-
- /* lcd init 3 */
- lcd_write_reg(R_POWER_CONTROL1, 0x4510);
- lcd_write_reg(R_DISP_CONTROL1, 0x0005);
- lcd_delay(0x28);
- lcd_write_reg(R_DISP_CONTROL1, 0x0025);
- lcd_write_reg(R_DISP_CONTROL1, 0x0027);
- lcd_delay(0x28);
- lcd_write_reg(R_DISP_CONTROL1, 0x0037);
-
- display_on = true;
-}
-
-void lcd_init_device(void)
-{
- /* Configure external memory banks */
- CSCFG1 = 0x0d500023 | tcc77x_cscfg_bw(TCC77X_CSCFG_BW16);
-
- /* may be reset */
- GPIOA |= 0x8000;
-
- _display_on();
-}
-
-void lcd_enable(bool on)
-{
- if (display_on == on)
- return;
-
- if (on) {
- _display_on();
- send_event(LCD_EVENT_ACTIVATION, NULL);
- } else {
- /** Off sequence according to datasheet, p. 130 **/
- lcd_write_reg(R_FRAME_CYCLE_CONTROL, 0x0002); /* EQ=0, 18 clks/line */
- lcd_write_reg(R_DISP_CONTROL1, 0x0036); /* GON=1, DTE=1, REV=1, D1-0=10 */
- sleep(2);
-
- lcd_write_reg(R_DISP_CONTROL1, 0x0026); /* GON=1, DTE=0, REV=1, D1-0=10 */
- sleep(2);
-
- lcd_write_reg(R_DISP_CONTROL1, 0x0000); /* GON=0, DTE=0, D1-0=00 */
-
- lcd_write_reg(R_POWER_CONTROL1, 0x0000); /* SAP2-0=000, AP2-0=000 */
- lcd_write_reg(R_POWER_CONTROL3, 0x0000); /* PON=0 */
- lcd_write_reg(R_POWER_CONTROL4, 0x0000); /* VCOMG=0 */
-
- /* datasheet p. 131 */
- lcd_write_reg(R_POWER_CONTROL1, 0x0001); /* STB=1: standby mode */
-
- display_on = false;
- }
-}
-
-bool lcd_active(void)
-{
- return display_on;
-}
-
-
-#define RGB(r,g,b) ((((r)&0x3f) << 12)|(((g)&0x3f) << 6)|(((b)&0x3f)))
-
-
-void lcd_update(void)
-{
- lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
-}
-
-/* todo: need tests */
-void lcd_update_rect(int sx, int sy, int width, int height)
-{
- int x, y;
-
- if (!display_on)
- return;
-
- if (width <= 0 || height <= 0) /* nothing to do */
- return;
-
- width += sx;
- height += sy;
-
- if (width > LCD_WIDTH)
- width = LCD_WIDTH;
- if (height > LCD_HEIGHT)
- height = LCD_HEIGHT;
-
- lcd_write_reg(R_ENTRY_MODE, 0x1028);
- /* set update window */
- lcd_write_reg(R_HORIZ_RAM_ADDR_POS, (LCD_HEIGHT - 1) << 8);
- lcd_write_reg(R_VERT_RAM_ADDR_POS, ((width - 1) << 8) | sx);
- lcd_write_reg(R_RAM_ADDR_SET, (sx << 8) | (LCD_HEIGHT - sy - 1));
- lcd_write_cmd(R_WRITE_DATA_2_GRAM);
-
- for (y = sy; y < height; y++) {
- for (x = sx; x < width; x++) {
- fb_data c;
- unsigned long color;
-
- c = *FBADDR(x,y);
- color =
- ((c & 0x1f) << 1) | ((c & 0x7e0) << 1) | ((c & 0xf800) <<
- 2);
-
- /* TODO: our color is 18-bit */
- outw((color >> 9) & 0x1ff, 0x50010008);
- outw((color) & 0x1ff, 0x50010008);
- }
- }
-}
-
-void lcd_set_contrast(int val)
-{
- (void) val;
-}
-
-void lcd_set_invert_display(bool yesno)
-{
- (void) yesno;
-}
-
-void lcd_set_flip(bool yesno)
-{
- (void) yesno;
-}
-
-/* TODO: implement me */
-void lcd_blit_yuv(unsigned char *const src[3],
- int src_x, int src_y, int stride,
- int x, int y, int width, int height)
-{
- (void) src;
- (void) src_x;
- (void) src_y;
- (void) stride;
- (void) x;
- (void) y;
-
- if (!display_on)
- return;
-
- width &= ~1; /* stay on the safe side */
- height &= ~1;
-
- panicf("%s", __func__);
-}
diff --git a/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c
deleted file mode 100644
index baf93b73aa..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 Vitja Makarov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include <stdbool.h>
-
-#include "config.h"
-#include "cpu.h"
-#include "kernel.h"
-#include "system.h"
-#include "power.h"
-#include "backlight-target.h"
-
-#include "pcf50606.h"
-
-void power_init(void)
-{
- pcf50606_write(PCF5060X_DCDC1, 0x90);
- pcf50606_write(PCF5060X_DCDC2, 0x48);
- pcf50606_write(PCF5060X_DCDC3, 0xfc);
- pcf50606_write(PCF5060X_DCDC4, 0xb1);
-
- pcf50606_write(PCF5060X_IOREGC, 0xe9);
- /* 3.3V, touch-panel */
- pcf50606_write(PCF5060X_D1REGC1, 0xf8);
- pcf50606_write(PCF5060X_D2REGC1, 0xf2);
- pcf50606_write(PCF5060X_D3REGC1, 0xf5);
-
- pcf50606_write(PCF5060X_LPREGC1, 0x00);
- pcf50606_write(PCF5060X_LPREGC2, 0x02);
-
- pcf50606_write(PCF5060X_DCUDC1, 0xe6);
- pcf50606_write(PCF5060X_DCUDC2, 0x30);
-
- pcf50606_write(PCF5060X_DCDEC1, 0xe7);
- pcf50606_write(PCF5060X_DCDEC2, 0x02);
-
- pcf50606_write(PCF5060X_INT1M, 0x5b);
- pcf50606_write(PCF5060X_INT1M, 0xaf);
- pcf50606_write(PCF5060X_INT1M, 0x8f);
-
- pcf50606_write(PCF5060X_OOCC1, 0x40);
- pcf50606_write(PCF5060X_OOCC2, 0x05);
-
- pcf50606_write(PCF5060X_MBCC3, 0x3a);
- pcf50606_write(PCF5060X_GPOC1, 0x00);
- pcf50606_write(PCF5060X_BBCC, 0xf8);
-}
-
-/* Control leds on ata2501 board */
-void power_touch_panel(bool on)
-{
- if (on)
- pcf50606_write(PCF5060X_D1REGC1, 0xf8);
- else
- pcf50606_write(PCF5060X_D1REGC1, 0x00);
-}
-
-void ide_power_enable(bool on)
-{
- (void) on;
-}
-
-bool ide_powered(void)
-{
- return true;
-}
-
-void power_off(void)
-{
- /* Forcibly cut power to SoC & peripherals by putting the PCF to sleep */
- pcf50606_write(PCF5060X_OOCC1, GOSTDBY | CHGWAK | EXTONWAK);
-}
-
-#if CONFIG_TUNER
-#include "tuner.h"
-
-/** Tuner **/
-static bool powered = false;
-
-#define TUNNER_CLK (1 << 5)
-#define TUNNER_DATA (1 << 6)
-#define TUNNER_NR_W (1 << 7)
-
-bool tuner_power(bool status)
-{
- bool old_status;
- lv24020lp_lock();
-
- old_status = powered;
-
- if (status != old_status)
- {
- if (status)
- {
- /* When power up, host should initialize the 3-wire bus
- in host read mode: */
-
- /* 1. Set direction of the DATA-line to input-mode. */
- GPIOA_DIR &= ~TUNNER_DATA;
-
- /* 2. Drive NR_W low */
- GPIOA &= ~TUNNER_NR_W;
- GPIOA_DIR |= TUNNER_NR_W;
-
- /* 3. Drive CLOCK high */
- GPIOA |= TUNNER_CLK;
- GPIOA_DIR |= TUNNER_CLK;
-
- lv24020lp_power(true);
- }
- else
- {
- lv24020lp_power(false);
-
- /* set all as inputs */
- GPIOC_DIR &= ~(TUNNER_CLK | TUNNER_DATA | TUNNER_NR_W);
- }
-
- powered = status;
- }
-
- lv24020lp_unlock();
- return old_status;
-}
-
-#endif /* CONFIG_TUNER */
-
-unsigned int power_input_status(void)
-{
- return (GPIOA & 0x1) ?
- POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
-}
diff --git a/firmware/target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c
deleted file mode 100644
index bc7ead61f0..0000000000
--- a/firmware/target/arm/tcc77x/iaudio7/powermgmt-iaudio7.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id: powermgmt-cowond2.c 17847 2008-06-28 18:10:04Z bagder $
- *
- * Copyright (C) 2007 by Karl Kurbjun
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "adc.h"
-#include "powermgmt.h"
-#include "kernel.h"
-#include "pcf50606.h"
-
-unsigned short current_voltage = 5150;
-
-const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
-{
- /* FIXME: calibrate value */
- 4400
-};
-
-const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
-{
- /* FIXME: calibrate value */
- 4600
-};
-
-/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
-const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
-{
- /* FIXME: calibrate values. Table is "inherited" from iPod-PCF / H100 */
- { 4500, 4810, 4910, 4970, 5030, 5070, 5120, 5140, 5170, 5250, 5400 }
-};
-
-#if CONFIG_CHARGING
-/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
-const unsigned short percent_to_volt_charge[11] =
-{
- /* FIXME: calibrate values. Table is "inherited" from iPod-PCF / H100 */
- 4760, 5440, 5510, 5560, 5610, 5640, 5660, 5760, 5820, 5840, 5850 /* NiMH */
-};
-#endif /* CONFIG_CHARGING */
-
-#define BATTERY_SCALE_FACTOR 6000
-/* full-scale ADC readout (2^10) in millivolt */
-
-/* Returns battery voltage from ADC [millivolts] */
-int _battery_voltage(void)
-{
- static unsigned last_tick = 0;
-
- if (0 == last_tick || TIME_BEFORE(last_tick+HZ, current_tick))
- {
- int adc_val, irq_status;
- unsigned char buf[2];
-
- irq_status = disable_irq_save();
- pcf50606_write(PCF5060X_ADCC2, 0x1);
- pcf50606_read_multiple(PCF5060X_ADCS1, buf, 2);
- restore_interrupt(irq_status);
-
- adc_val = (buf[0]<<2) | (buf[1] & 3); //ADCDAT1H+ADCDAT1L
- current_voltage = (adc_val * BATTERY_SCALE_FACTOR) >> 10;
-
- last_tick = current_tick;
- }
-
- return current_voltage;
-}
-
diff --git a/firmware/target/arm/tcc77x/kernel-tcc77x.c b/firmware/target/arm/tcc77x/kernel-tcc77x.c
deleted file mode 100644
index bbfc29d915..0000000000
--- a/firmware/target/arm/tcc77x/kernel-tcc77x.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/***************************************************************************
-* __________ __ ___.
-* Open \______ \ ____ ____ | | _\_ |__ _______ ___
-* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
-* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
-* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
-* \/ \/ \/ \/ \/
-* $Id$
-*
-* Copyright (C) 2008 by Rob Purchase
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
-* KIND, either express or implied.
-*
-****************************************************************************/
-
-#include "config.h"
-#include "system.h"
-#include "kernel.h"
-#include "timer.h"
-#include "thread.h"
-
-void tick_start(unsigned int interval_in_ms)
-{
- /* configure Timer T-Clock to 2Mhz (clock source 4 (Xin) divided by 6) */
- PCLKCFG4 = (1 << 31) | (4 << 28) | (5 << 16);
-
- /* disable Timer0 */
- TCFG0 &= ~1;
-
- /* set counter reference value based on 1Mhz tick */
- TREF0 = interval_in_ms * 1000;
-
- /* Timer0 = reset to 0, divide=2, IRQ enable, enable (continuous) */
- TCFG0 = (1<<8) | (0<<4) | (1<<3) | 1;
-
- /* Unmask timer IRQ */
- IEN |= TIMER0_IRQ_MASK;
-}
-
-/* NB: Since we are using a single timer IRQ, tick tasks are dispatched as
- part of the central timer IRQ processing in timer-tcc77x.c */
diff --git a/firmware/target/arm/tcc77x/logikdax/adc-target.h b/firmware/target/arm/tcc77x/logikdax/adc-target.h
deleted file mode 100644
index 1916d93598..0000000000
--- a/firmware/target/arm/tcc77x/logikdax/adc-target.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _ADC_TARGET_H_
-#define _ADC_TARGET_H_
-
-#define NUM_ADC_CHANNELS 8
-
-#define ADC_BUTTONS 0
-
-#endif /* _ADC_TARGET_H_ */
diff --git a/firmware/target/arm/tcc77x/logikdax/audio-logikdax.c b/firmware/target/arm/tcc77x/logikdax/audio-logikdax.c
deleted file mode 100644
index 90c9a68827..0000000000
--- a/firmware/target/arm/tcc77x/logikdax/audio-logikdax.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Michael Sevakis
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "system.h"
-#include "cpu.h"
-#include "audio.h"
-#include "sound.h"
-
-int audio_channels = 2;
-int audio_output_source = AUDIO_SRC_PLAYBACK;
-
-#if INPUT_SRC_CAPS != 0
-void audio_set_output_source(int source)
-{
- (void)source;
-}
-
-void audio_input_mux(int source, unsigned flags)
-{
- (void)source;
- (void)flags;
-}
-#endif
diff --git a/firmware/target/arm/tcc77x/logikdax/backlight-target.h b/firmware/target/arm/tcc77x/logikdax/backlight-target.h
deleted file mode 100644
index 202e118606..0000000000
--- a/firmware/target/arm/tcc77x/logikdax/backlight-target.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef BACKLIGHT_TARGET_H
-#define BACKLIGHT_TARGET_H
-
-#include "tcc77x.h"
-
-#define backlight_hw_init() true
-
-static inline void backlight_hw_on(void)
-{
- /* Enable backlight */
- GPIOD |= 0x10;
-}
-
-static inline void backlight_hw_off(void)
-{
- /* Disable backlight */
- GPIOD &= ~0x10;
-}
-
-#endif
diff --git a/firmware/target/arm/tcc77x/logikdax/button-logikdax.c b/firmware/target/arm/tcc77x/logikdax/button-logikdax.c
deleted file mode 100644
index abf939753a..0000000000
--- a/firmware/target/arm/tcc77x/logikdax/button-logikdax.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "cpu.h"
-#include "button.h"
-#include "adc.h"
-
-/*
-
-Results of button testing:
-
-HOLD: GPIOA & 0x0002 (0=pressed, 0x0002 = released)
-POWER: GPIOA & 0x8000 (0=pressed, 0x8000 = released)
-
-ADC[0]: (approx values)
-
-RIGHT - 0x37
-LEFT - 0x7f
-JOYSTICK PRESS - 0xc7
-UP - 0x11e
-DOWN - 0x184
-MODE - 0x1f0/0x1ff
-PRESET - 0x268/0x269
-REC - 0x2dd
-
-Values of ADC[0] tested in OF disassembly: 0x50, 0x96, 0xdc, 0x208, 0x384
-
-*/
-
-void button_init_device(void)
-{
- /* Nothing to do */
-}
-
-int button_read_device(void)
-{
- int btn = BUTTON_NONE;
- int adc;
-
- adc = adc_read(ADC_BUTTONS);
-
- if (adc < 0x384) {
- if (adc < 0x140) {
- if (adc < 0x96) {
- if (adc < 0x50) {
- btn |= BUTTON_RIGHT; /* 0x00..0x4f */
- } else {
- btn |= BUTTON_LEFT; /* 0x50..0x95 */
- }
- } else {
- if (adc < 0xe0) {
- btn |= BUTTON_SELECT; /* 0x96..0xdf */
- } else {
- btn |= BUTTON_UP; /* 0xe0..0x13f */
- }
- }
- } else {
- if (adc < 0x208) {
- if (adc < 0x1b0) {
- btn |= BUTTON_DOWN; /* 0x140..0x1af */
- } else {
- btn |= BUTTON_MODE; /* 0x1b0..0x207 */
- }
- } else {
- if (adc < 0x290) {
- btn |= BUTTON_PRESET; /* 0x208..0x28f */
- } else {
- btn |= BUTTON_REC; /* 0x290..0x383 */
- }
- }
- }
- }
-
- if (!(GPIOA & 0x2))
- btn |= BUTTON_HOLD;
-
- if (!(GPIOA & 0x8000))
- btn |= BUTTON_POWERPLAY;
-
- return btn;
-}
diff --git a/firmware/target/arm/tcc77x/logikdax/button-target.h b/firmware/target/arm/tcc77x/logikdax/button-target.h
deleted file mode 100644
index 505fe438ed..0000000000
--- a/firmware/target/arm/tcc77x/logikdax/button-target.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#ifndef _BUTTON_TARGET_H_
-#define _BUTTON_TARGET_H_
-
-/* Main unit's buttons */
-#define BUTTON_POWERPLAY 0x00000001
-#define BUTTON_MODE 0x00000002
-#define BUTTON_HOLD 0x00000004
-#define BUTTON_REC 0x00000008
-#define BUTTON_PRESET 0x00000010
-#define BUTTON_LEFT 0x00000020
-#define BUTTON_RIGHT 0x00000040
-#define BUTTON_UP 0x00000080
-#define BUTTON_DOWN 0x00000100
-#define BUTTON_SELECT 0x00000200
-
-#define BUTTON_MAIN (BUTTON_POWERPLAY|BUTTON_MODE|BUTTON_HOLD\
- |BUTTON_REC|BUTTON_PRESET|BUTTON_LEFT\
- |BUTTON_RIGHT|BUTTON_UP|BUTTON_DOWN|BUTTON_SELECT)
-
-/* Software power-off */
-#define POWEROFF_BUTTON BUTTON_POWERPLAY
-#define POWEROFF_COUNT 40
-
-#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/tcc77x/logikdax/power-logikdax.c b/firmware/target/arm/tcc77x/logikdax/power-logikdax.c
deleted file mode 100644
index 840b02a2a5..0000000000
--- a/firmware/target/arm/tcc77x/logikdax/power-logikdax.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include <stdbool.h>
-#include "kernel.h"
-#include "system.h"
-#include "power.h"
-
-void power_init(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-bool ide_powered(void)
-{
- return true;
-}
-
-void power_off(void)
-{
-}
diff --git a/firmware/target/arm/tcc77x/m200/adc-target.h b/firmware/target/arm/tcc77x/m200/adc-target.h
deleted file mode 100644
index e9640cc9da..0000000000
--- a/firmware/target/arm/tcc77x/m200/adc-target.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef _ADC_TARGET_H_
-#define _ADC_TARGET_H_
-
-#define NUM_ADC_CHANNELS 8
-
-#define ADC_BUTTONS 1
-
-#endif /* _ADC_TARGET_H_ */
diff --git a/firmware/target/arm/tcc77x/m200/audio-m200.c b/firmware/target/arm/tcc77x/m200/audio-m200.c
deleted file mode 100644
index 107b2743ae..0000000000
--- a/firmware/target/arm/tcc77x/m200/audio-m200.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Michael Sevakis
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "system.h"
-#include "cpu.h"
-#include "audio.h"
-#include "sound.h"
-
-int audio_channels = 2;
-int audio_output_source = AUDIO_SRC_PLAYBACK;
-
-void audio_set_output_source(int source)
-{
- (void)source;
-}
-
-void audio_input_mux(int source, unsigned flags)
-{
- (void)source;
- (void)flags;
-}
diff --git a/firmware/target/arm/tcc77x/m200/backlight-target.h b/firmware/target/arm/tcc77x/m200/backlight-target.h
deleted file mode 100644
index d73ac78852..0000000000
--- a/firmware/target/arm/tcc77x/m200/backlight-target.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2008 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef BACKLIGHT_TARGET_H
-#define BACKLIGHT_TARGET_H
-
-#include "tcc77x.h"
-
-static inline bool backlight_hw_init(void)
-{
- GPIOA_DIR |= 0x40;
- return true;
-}
-
-static inline void backlight_hw_on(void)
-{
- /* Enable backlight */
- GPIOA |= 0x40;
-}
-
-static inline void backlight_hw_off(void)
-{
- /* Disable backlight */
- GPIOA &= ~0x40;
-}
-
-#endif
diff --git a/firmware/target/arm/tcc77x/m200/button-m200.c b/firmware/target/arm/tcc77x/m200/button-m200.c
deleted file mode 100644
index a37fe1302c..0000000000
--- a/firmware/target/arm/tcc77x/m200/button-m200.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "cpu.h"
-#include "button.h"
-#include "adc.h"
-
-/*
-
-Results of button testing (viewing ADC values whilst pressing buttons):
-
-HOLD: GPIOB & 0x0200 (0=hold active, 0x0200 = hold inactive)
-
-ADC[1]: (approx values)
-
-Idle - 0x3ff
-MENU - unknown
-
-REPEAT/AB - 0x03?
-LEFT - 0x07?-0x08?
-SELECT - 0x0c?
-RIGHT - 0x11?
-
-PLAY/PAUSE - 0x17?-0x018?
-VOL UP - 0x1e?-0x01f?
-VOL DOWN - 0x26?
-
-*/
-
-void button_init_device(void)
-{
- /* Nothing to do */
-}
-
-int button_read_device(void)
-{
- int btn = BUTTON_NONE;
- int adc;
-
- /* TODO - determine how to detect BUTTON_MENU - it doesn't appear to
- be connected to a GPIO or to an ADC
- */
-
- adc = adc_read(ADC_BUTTONS);
-
- if (adc < 0x384) {
- if (adc < 0x140) {
- if (adc < 0x96) {
- if (adc < 0x50) {
- btn |= BUTTON_REPEATAB; /* 0x00..0x4f */
- } else {
- btn |= BUTTON_LEFT; /* 0x50..0x95 */
- }
- } else {
- if (adc < 0xe0) {
- btn |= BUTTON_SELECT; /* 0x96..0xdf */
- } else {
- btn |= BUTTON_RIGHT; /* 0xe0..0x13f */
- }
- }
- } else {
- if (adc < 0x208) {
- if (adc < 0x1b0) {
- btn |= BUTTON_PLAYPAUSE; /* 0x140..0x1af */
- } else {
- btn |= BUTTON_VOLUP; /* 0x1b0..0x207 */
- }
- } else {
- btn |= BUTTON_VOLDOWN; /* 0x209..0x383 */
- }
- }
- }
-
- return btn;
-}
-
-bool button_hold(void)
-{
- return (GPIOB & 0x200)?false:true;
-}
diff --git a/firmware/target/arm/tcc77x/m200/button-target.h b/firmware/target/arm/tcc77x/m200/button-target.h
deleted file mode 100644
index b96df22edc..0000000000
--- a/firmware/target/arm/tcc77x/m200/button-target.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#ifndef _BUTTON_TARGET_H_
-#define _BUTTON_TARGET_H_
-
-#define HAS_BUTTON_HOLD
-
-/* Main unit's buttons */
-#define BUTTON_MENU 0x00000001
-#define BUTTON_VOLUP 0x00000002
-#define BUTTON_VOLDOWN 0x00000004
-#define BUTTON_PLAYPAUSE 0x00000008
-#define BUTTON_REPEATAB 0x00000010
-#define BUTTON_LEFT 0x00000020
-#define BUTTON_RIGHT 0x00000040
-#define BUTTON_SELECT 0x00000080
-
-#define BUTTON_MAIN (BUTTON_MENU|BUTTON_VOLUP|BUTTON_VOLDOWN\
- |BUTTON_PLAYPAUSE|BUTTON_REPEATAB|BUTTON_LEFT\
- |BUTTON_RIGHT|BUTTON_SELECT)
-
-/* Software power-off */
-#define POWEROFF_BUTTON BUTTON_MENU
-#define POWEROFF_COUNT 40
-
-#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/tcc77x/m200/power-m200.c b/firmware/target/arm/tcc77x/m200/power-m200.c
deleted file mode 100644
index e84ff1c852..0000000000
--- a/firmware/target/arm/tcc77x/m200/power-m200.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#include "config.h"
-#include "cpu.h"
-#include <stdbool.h>
-#include "kernel.h"
-#include "system.h"
-#include "power.h"
-
-void power_init(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
-}
-
-bool ide_powered(void)
-{
- return true;
-}
-
-void power_off(void)
-{
-}
diff --git a/firmware/target/arm/tcc77x/powermgmt-tcc77x.c b/firmware/target/arm/tcc77x/powermgmt-tcc77x.c
deleted file mode 100644
index 07a56777d0..0000000000
--- a/firmware/target/arm/tcc77x/powermgmt-tcc77x.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Karl Kurbjun
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "adc.h"
-#include "powermgmt.h"
-#include "kernel.h"
-#include "pcf50606.h"
-
-unsigned short current_voltage = 3910;
-
-const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
-{
- /* FIXME: calibrate value */
- 3380
-};
-
-const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
-{
- /* FIXME: calibrate value */
- 3300
-};
-
-/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
-const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
-{
- /* FIXME: calibrate values. Table is "inherited" from iPod-PCF / H100 */
- { 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4080, 4160 }
-};
-
-#if CONFIG_CHARGING
-/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
-const unsigned short percent_to_volt_charge[11] =
-{
- /* FIXME: calibrate values. Table is "inherited" from iPod-PCF / H100 */
- 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4080, 4160
-};
-#endif /* CONFIG_CHARGING */
-
-#define BATTERY_SCALE_FACTOR 6000
-/* full-scale ADC readout (2^10) in millivolt */
-
-/* Returns battery voltage from ADC [millivolts] */
-int _battery_voltage(void)
-{
- return current_voltage;
-}
-
diff --git a/firmware/target/arm/tcc77x/system-target.h b/firmware/target/arm/tcc77x/system-target.h
deleted file mode 100644
index beeeac05c6..0000000000
--- a/firmware/target/arm/tcc77x/system-target.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-#ifndef SYSTEM_TARGET_H
-#define SYSTEM_TARGET_H
-
-#include "system-arm.h"
-
-#define CPUFREQ_DEFAULT 98784000
-#define CPUFREQ_NORMAL 98784000
-#define CPUFREQ_MAX 120000000
-
-#define inl(a) (*(volatile unsigned long *) (a))
-#define outl(a,b) (*(volatile unsigned long *) (b) = (a))
-#define inb(a) (*(volatile unsigned char *) (a))
-#define outb(a,b) (*(volatile unsigned char *) (b) = (a))
-#define inw(a) (*(volatile unsigned short *) (a))
-#define outw(a,b) (*(volatile unsigned short *) (b) = (a))
-
-/* TC32 is configured to 1MHz in clock_init() */
-#define USEC_TIMER TC32MCNT
-
-static inline void udelay(unsigned usecs)
-{
- unsigned stop = USEC_TIMER + usecs;
- while (TIME_BEFORE(USEC_TIMER, stop));
-}
-
-
-#define TCC77X_CSCFG_BW8 0
-#define TCC77X_CSCFG_BW16 1
-
-/* Due to hardware bug or "feature" this hack is needed to set bus width bits */
-static inline
-unsigned long tcc77x_cscfg_bw(int bw) {
- if (bw == TCC77X_CSCFG_BW8)
- return (((MCFG >> 11) & 3) ^ 3) << 28;
- else
- return (((MCFG >> 11) & 3) ^ 2) << 28;
-}
-
-#endif /* SYSTEM_TARGET_H */
diff --git a/firmware/target/arm/tcc77x/system-tcc77x.c b/firmware/target/arm/tcc77x/system-tcc77x.c
deleted file mode 100644
index cffb4deba4..0000000000
--- a/firmware/target/arm/tcc77x/system-tcc77x.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id$
- *
- * Copyright (C) 2007 by Dave Chapman
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "kernel.h"
-#include "system.h"
-#include "panic.h"
-
-/* Externally defined interrupt handlers */
-extern void TIMER(void);
-extern void ADC(void);
-extern void USB_DEVICE(void);
-
-void irq(void)
-{
- int irq = IREQ & 0x7fffffff;
- CREQ = irq; /* Clears the corresponding IRQ status */
-
- if (irq & TIMER0_IRQ_MASK)
- TIMER();
- else if (irq & ADC_IRQ_MASK)
- ADC();
-#ifdef HAVE_USBSTACK
- else if (irq & USBD_IRQ_MASK)
- USB_DEVICE();
-#endif
- else
- panicf("Unhandled IRQ 0x%08X", irq);
-}
-
-void fiq_handler(void) __attribute__((interrupt ("FIQ"), naked));
-
-#ifdef BOOTLOADER
-void fiq_handler(void)
-{
- /* TODO */
-}
-#endif
-
-void system_reboot(void)
-{
-}
-
-void system_exception_wait(void)
-{
- while (1);
-}
-
-/* TODO - these should live in the target-specific directories and
- once we understand what all the GPIO pins do, move the init to the
- specific driver for that hardware. For now, we just perform the
- same GPIO init as the original firmware - this makes it easier to
- investigate what the GPIO pins do.
-*/
-
-#ifdef LOGIK_DAX
-static void gpio_init(void)
-{
- /* Do what the original firmware does */
- GPIOD_FUNC = 0;
- GPIOD_DIR = 0x3f0;
- GPIOD = 0xe0;
-
- GPIOE_FUNC = 0;
- GPIOE_DIR = 0xe0;
- GPIOE = 0;
-
- GPIOA_FUNC = 0;
- GPIOA_DIR = 0xffff1000; /* 0 - 0xf000 */
- GPIOA = 0x1080;
-
- GPIOB_FUNC = 0x16a3;
- GPIOB_DIR = 0x6ffff;
- GPIOB = 0;
-
- GPIOC_FUNC = 1;
- GPIOC_DIR = 0x03ffffff; /* mvn r2, 0xfc000000 */
- GPIOC = 0;
-}
-#elif defined(IAUDIO_7)
-static void gpio_init(void)
-{
- /* Do what the original firmware does */
- GPIOA_FUNC = 0;
- GPIOB_FUNC = 0x1623;
- GPIOC_FUNC = 1;
- GPIOD_FUNC = 0;
- GPIOE_FUNC = 0;
- GPIOA = 0x30;
- GPIOB = 0x00c00;
- GPIOC = 0;
- GPIOD = 0x180;
- GPIOE = 0x80;
- GPIOA_DIR = 0x84b0;
- GPIOB_DIR = 0x80c00;
- GPIOC_DIR = 0x2000000;
- GPIOD_DIR = 0x3e3;
- GPIOE_DIR = 0x88;
-}
-#elif defined(SANSA_M200)
-static void gpio_init(void)
-{
- /* TODO - Implement for M200 */
-}
-#elif defined(SANSA_C100)
-static void gpio_init(void)
-{
- /* Do what the original firmware does */
- GPIOA_FUNC = 0;
- GPIOB_FUNC = 0x16A3;
- GPIOC_FUNC = 1;
- GPIOD_FUNC |= 2;
- GPIOE_FUNC = 0;
-
- GPIOA_DIR = 0xFFFF0E00;
- GPIOB_DIR = 0x6FFFF;
- GPIOC_DIR = 0x03FFFFFF;
- GPIOD_DIR = 0x3F7;
- GPIOE_DIR = 0x9B;
-
- GPIOA = 0x80;
- GPIOB = 0;
- GPIOC = 0;
- GPIOD |= 0xC0;
- GPIOE = 0x9B;
-}
-#endif
-
-/* Second function called in the original firmware's startup code - we just
- set up the clocks in the same way as the original firmware for now. */
-static void clock_init(void)
-{
- unsigned int i;
-
- /* STP = 0x1, PW = 0x04 , HLD = 0x0 */
- CSCFG3 = (CSCFG3 &~ 0x3fff) | 0x820;
-
- /* XIN=External main, Fcpu=Fsys, BCKDIV=1 (Fbus = Fsys / 2) */
- CLKCTRL = (CLKCTRL & ~0xff) | 0x14;
-
- if (BMI & 0x20)
- PCLKCFG0 = 0xc82d7000; /* EN1 = 1, XIN=Ext. main, DIV1 = 0x2d, P1 = 1 */
- else
- PCLKCFG0 = 0xc8ba7000; /* EN1 = 1, XIN=Ext. main, DIV1 = 0xba, P1 = 1 */
-
- MCFG |= 0x2000;
-
-#ifdef LOGIK_DAX
- /* Only seen in the Logik DAX original firmware */
- SDCFG = (SDCFG & ~0x7000) | 0x2000;
-#endif
-
- /* Disable PLL */
- PLL0CFG |= 0x80000000;
-
- /* Enable PLL, M=0xcf, P=0x13. m=M+8, p=P+2, S = 0
- Fout = (215/21)*12MHz = 122857142Hz */
- PLL0CFG = 0x0000cf13;
-
- i = 8000;
- while (--i) {};
-
- /* Enable PLL0 */
- CLKDIVC = 0x81000000;
-
- /* Fsys = PLL0, Fcpu = Fsys, Fbus=Fsys / 2 */
- CLKCTRL = 0x80000010;
-
- asm volatile (
- "nop \n\t"
- "nop \n\t"
- );
-
- /* Enable Z-Clock */
- PCLKCFG5 |= (1<<31) | (4<<28); /* Timer Z-Clock enable, XIN direct*/
-
- /* Set TC32 timer to be our USEC_TIMER (Xin divided by 12 = 1MHz) */
- TC32MCNT = 0;
- TC32LDV = 0;
- TC32EN = (1<<24) | 11;
-}
-
-static void cpu_init(void)
-{
- /* Memory protection - see page 48 of ARM946 TRM
-http://infocenter.arm.com/help/topic/com.arm.doc.ddi0201d/DDI0201D_arm946es_r1p1_trm.pdf
- */
- asm volatile (
- /* Region 0 - addr=0, size=4GB, enabled */
- "mov r0, #0x3f \n\t"
- "mcr p15, 0, r0, c6, c0, 0 \n\t"
- "mcr p15, 0, r0, c6, c0, 1 \n\t"
-
-#if defined(LOGIK_DAX) || defined(SANSA_C100)
- /* Address region 1 - addr 0x2fff0000, size=64KB, enabled*/
- "ldr r0, =0x2fff001f \n\t"
-#elif defined(IAUDIO_7)
- /* Address region 1 - addr 0x20000000, size=8KB, enabled*/
- "mov r0, #0x19 \n\t"
- "add r0, r0, #0x20000000 \n\t"
-#elif defined(SANSA_M200)
- /* Address region 1 - addr 0x20000000, size=256MB, enabled*/
- "mov r0, #0x37 \n\t"
- "add r0, r0, #0x20000000 \n\t"
-#endif
- "mcr p15, 0, r0, c6, c1, 0 \n\t"
- "mcr p15, 0, r0, c6, c1, 1 \n\t"
-
- /* Address region 2 - addr 0x30000000, size=256MB, enabled*/
- "mov r0, #0x37 \n\t"
- "add r0, r0, #0x30000000 \n\t"
- "mcr p15, 0, r0, c6, c2, 0 \n\t"
- "mcr p15, 0, r0, c6, c2, 1 \n\t"
-
- /* Address region 2 - addr 0x40000000, size=512MB, enabled*/
- "mov r0, #0x39 \n\t"
- "add r0, r0, #0x40000000 \n\t"
- "mcr p15, 0, r0, c6, c3, 0 \n\t"
- "mcr p15, 0, r0, c6, c3, 1 \n\t"
-
- /* Address region 4 - addr 0x60000000, size=256MB, enabled*/
- "mov r0, #0x37 \n\t"
- "add r0, r0, #0x60000000 \n\t"
- "mcr p15, 0, r0, c6, c4, 0 \n\t"
- "mcr p15, 0, r0, c6, c4, 1 \n\t"
-
- /* Address region 5 - addr 0x10000000, size=256MB, enabled*/
- "mov r0, #0x37 \n\t"
- "add r0, r0, #0x10000000 \n\t"
- "mcr p15, 0, r0, c6, c5, 0 \n\t"
- "mcr p15, 0, r0, c6, c5, 1 \n\t"
-
- /* Address region 6 - addr 0x80000000, size=2GB, enabled*/
- "mov r0, #0x37 \n\t"
- "add r0, r0, #0x80000006 \n\t"
- "mcr p15, 0, r0, c6, c6, 0 \n\t"
- "mcr p15, 0, r0, c6, c6, 1 \n\t"
-
- /* Address region 7 - addr 0x3000f000, size=4KB, enabled*/
- "ldr r0, =0x3000f017 \n\t"
- "mcr p15, 0, r0, c6, c7, 0 \n\t"
- "mcr p15, 0, r0, c6, c7, 1 \n\t"
-
-
- /* Register 5 - Access Permission Registers */
-
- "ldr r0, =0xffff \n\t"
- "mcr p15, 0, r0, c5, c0, 0 \n\t" /* write data access permission bits */
- "mcr p15, 0, r0, c5, c0, 1 \n\t" /* write instruction access permission bits */
-
- "mov r0, #0xa7 \n\t"
- "mcr p15, 0, r0, c3, c0, 0 \n\t" /* set write buffer control register */
-
-#if defined(LOGIK_DAX) || defined(SANSA_C100)
- "mov r0, #0xa5 \n\t"
-#elif defined(IAUDIO_7) || defined(SANSA_M200)
- "mov r0, #0xa7 \n\t"
-#else
- #error NOT DEFINED FOR THIS TARGET!
-#endif
- "mcr p15, 0, r0, c2, c0, 0 \n\t"
- "mcr p15, 0, r0, c2, c0, 1 \n\t"
-
- "mov r0, #0xa0000006 \n\t"
- "mcr p15, 0, r0, c9, c1, 0 \n\t"
-
- "ldr r1, =0x1107d \n\t"
- "mov r0, #0x0 \n\t"
- "mcr p15, 0, r0, c7, c5, 0 \n\t" /* Flush instruction cache */
- "mcr p15, 0, r0, c7, c6, 0 \n\t" /* Flush data cache */
-
- "mcr p15, 0, r1, c1, c0, 0 \n\t" /* CPU control bits */
- : : : "r0", "r1"
- );
-}
-
-
-
-void system_init(void)
-{
- /* mask all interrupts */
- IEN = 0;
-
- /* Set all interrupts as IRQ for now - some may need to be FIQ in future */
- IRQSEL = 0xffffffff;
-
- /* Set master enable bit */
- IEN = 0x80000000;
-
- cpu_init();
- clock_init();
- gpio_init();
-
- enable_irq();
-}
-
-int system_memory_guard(int newmode)
-{
- (void)newmode;
- return 0;
-}
-
-#ifdef HAVE_ADJUSTABLE_CPU_FREQ
-
-void set_cpu_frequency(long frequency)
-{
-}
-
-#endif
diff --git a/firmware/target/arm/tcc77x/timer-tcc77x.c b/firmware/target/arm/tcc77x/timer-tcc77x.c
deleted file mode 100644
index 6e8764d9ce..0000000000
--- a/firmware/target/arm/tcc77x/timer-tcc77x.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/***************************************************************************
-* __________ __ ___.
-* Open \______ \ ____ ____ | | _\_ |__ _______ ___
-* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
-* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
-* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
-* \/ \/ \/ \/ \/
-* $Id$
-*
-* Copyright (C) 2008 by Rob Purchase
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
-* KIND, either express or implied.
-*
-****************************************************************************/
-
-#include "config.h"
-#include "cpu.h"
-#include "system.h"
-#include "timer.h"
-#include "logf.h"
-
-/* Use the TC32 counter [sourced by Xin:12Mhz] for this timer, as it's the
- only one that allows a 32-bit counter (Timer0-5 are 16/20 bit only). */
-
-bool timer_set(long cycles, bool start)
-{
- #warning function not implemented
-
- (void)cycles;
- (void)start;
- return false;
-}
-
-bool timer_start(void)
-{
- #warning function not implemented
-
- return false;
-}
-
-void timer_stop(void)
-{
- #warning function not implemented
-}
-
-
-/* Timer interrupt processing - all timers (inc. tick) have a single IRQ */
-void TIMER(void)
-{
- if (TIREQ & TF0) /* Timer0 reached ref value */
- {
- /* Run through the list of tick tasks */
- call_tick_tasks();
-
- /* reset Timer 0 IRQ & ref flags */
- TIREQ |= TI0 | TF0;
- }
-
- if (TC32IRQ & (1<<3)) /* end of TC32 prescale */
- {
- /* dispatch timer */
- }
-}
diff --git a/firmware/target/arm/tms320dm320/boot.lds b/firmware/target/arm/tms320dm320/boot.lds
index c59cc7f514..2db687d533 100644
--- a/firmware/target/arm/tms320dm320/boot.lds
+++ b/firmware/target/arm/tms320dm320/boot.lds
@@ -38,12 +38,12 @@ STARTUP(target/arm/tms320dm320/crt0.o)
#ifdef SANSA_CONNECT
/* Offset in flash from beginning, we don't want overwrite OF bootloader
- due to recovery mode and more importantly - hardware block protection.
- This offset makes Rockbox bootloader a replacement for OF vmlinux.
- In .srr file header add any valid memory address from following
- <0x1000000; 0x1300180) u (0x131EAF4; 0x1420000) u (0x1440000; 0x5000000>
- ensuring that complete bootloader fits in.
- Entry point in .srr file should be equal to _loadaddress. */
+ * due to recovery mode and more importantly - hardware block protection.
+ * Rockbox bootloader is flashed into kernel partition and chainloaded
+ * from OF bootloader via Arbitrary Code Execution exploit. The first
+ * instruction must be position independent as Rockbox bootloader will be
+ * copied to RAM at 0x01000000 and executed from RAM.
+ */
#define FLASHSIZE 0x00400000
#define FLASHMEMORIG 0x00120010
/* Kernel partition is 2 M, srr header is 16 bytes, sig is 2048 bytes */
diff --git a/firmware/target/arm/tms320dm320/crt0.S b/firmware/target/arm/tms320dm320/crt0.S
index 9f2c8dbe04..e57e28a470 100644
--- a/firmware/target/arm/tms320dm320/crt0.S
+++ b/firmware/target/arm/tms320dm320/crt0.S
@@ -201,14 +201,14 @@ _start:
mov r3, #CACHE_NONE
bl map_section
- /* Enable caching for FLASH */
+ /* Enable write-through caching for FLASH */
ldr r0, =_flash_start
ldr r1, =_flash_start
ldr r2, =_flash_sizem
- mov r3, #CACHE_ALL
+ mov r3, #(CACHE_ALL & ~BUFFERED)
bl map_section
- /* Enable caching for RAM */
+ /* Enable write-back caching for RAM */
ldr r0, =_sdram_start
ldr r1, =_sdram_start
ldr r2, =_sdram_sizem
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
index 611bdbfde5..2a71563c0b 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id: $
*
-* Copyright (C) 2011 by Tomasz Moń
+* Copyright (C) 2011-2021 by Tomasz Moń
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,10 +22,14 @@
#include <stdio.h>
#include "config.h"
#include "system.h"
+#include "power.h"
#include "kernel.h"
+#include "panic.h"
+/*#define LOGF_ENABLE*/
#include "logf.h"
#include "avr-sansaconnect.h"
#include "uart-target.h"
+#include "usb.h"
#include "button.h"
#include "backlight.h"
#include "powermgmt.h"
@@ -46,24 +50,56 @@
#define dbgprintf(...)
#endif
-#define CMD_SYNC 0xAA
-#define CMD_CLOSE 0xCC
-#define CMD_LCM_POWER 0xC9
-#define LCM_POWER_OFF 0x00
-#define LCM_POWER_ON 0x01
-#define LCM_POWER_SLEEP 0x02
-#define LCM_POWER_WAKE 0x03
-#define LCM_REPOWER_ON 0x04
-
-#define CMD_STATE 0xBB
-#define CMD_VER 0xBC
-#define CMD_WHEEL_EN 0xD0
-#define CMD_SET_INTCHRG 0xD1
-#define CMD_CODEC_RESET 0xD7
-#define CMD_FILL 0xFF
-
-#define CMD_SYS_CTRL 0xDA
-#define SYS_CTRL_POWEROFF 0x00
+#define AVR_DELAY_US 100
+
+#define CMD_SYNC 0xAA
+#define CMD_CLOSE 0xCC
+#define CMD_FILL 0xFF
+
+/* Actual command opcodes handled by AVR */
+#define CMD_STATE 0xBB
+#define CMD_VER 0xBC
+#define CMD_MONOTIME 0xBD
+#define CMD_PGMWAKE 0xBF
+#define CMD_HDQ_READ 0xC0
+#define CMD_HDQ_WRITE 0xC1
+#define CMD_HDQ_STATUS 0xC2
+#define CMD_GET_LAST_RESET_TYPE 0xC4
+#define CMD_UNKNOWN_C5 0xC5
+#define CMD_GET_BATTERY_TEMP 0xC8
+#define CMD_LCM_POWER 0xC9
+#define CMD_AMP_ENABLE 0xCA
+#define CMD_WHEEL_EN 0xD0
+#define CMD_SET_INTCHRG 0xD1
+#define CMD_GET_INTCHRG 0xD2
+#define CMD_UNKNOWN_D3 0xD3
+#define CMD_UNKNOWN_D4 0xD4
+#define CMD_UNKNOWN_D5 0xD5
+#define CMD_UNKNOWN_D6 0xD6
+#define CMD_CODEC_RESET 0xD7
+#define CMD_ADC_START 0xD8
+#define CMD_ADC_RESULT 0xD9
+#define CMD_SYS_CTRL 0xDA
+#define CMD_SET_USBCHRG 0xE2
+#define CMD_GET_USBCHRG 0xE3
+#define CMD_MONORSTCNT 0xE4
+
+/* CMD_LCM_POWER parameters */
+#define LCM_POWER_OFF 0x00
+#define LCM_POWER_ON 0x01
+#define LCM_POWER_SLEEP 0x02
+#define LCM_POWER_WAKE 0x03
+#define LCM_REPOWER_ON 0x04
+
+/* CMD_SYS_CTRL parameters */
+#define SYS_CTRL_POWEROFF 0x00
+#define SYS_CTRL_RESET 0x01
+#define SYS_CTRL_SLEEP 0x02
+#define SYS_CTRL_DISABLE_WD 0x03
+#define SYS_CTRL_KICK_WD 0x04
+#define SYS_CTRL_EN_HDQ_THERM 0x05
+#define SYS_CTRL_EN_TS_THERM 0x06
+#define SYS_CTRL_FRESET 0x80
/* protects spi avr commands from concurrent access */
static struct mutex avr_mtx;
@@ -73,26 +109,38 @@ static struct mutex avr_mtx;
static int btn = 0;
static bool hold_switch;
#ifndef BOOTLOADER
-static long btn_stack[DEFAULT_STACK_SIZE/sizeof(long)];
-static const char btn_thread_name[] = "buttons";
-static struct event_queue btn_queue;
+static long avr_stack[DEFAULT_STACK_SIZE/sizeof(long)];
+static const char avr_thread_name[] = "avr";
+static struct semaphore avr_thread_trigger;
#endif
-static inline unsigned short be2short(unsigned char* buf)
+/* OF bootloader will refuse to start software if low power is set
+ * Bits 3, 4, 5, 6 and 7 are unknown.
+ */
+#define BATTERY_STATUS_LOW_POWER (1 << 2)
+#define BATTERY_STATUS_CHARGER_CONNECTED (1 << 1)
+#define BATTERY_STATUS_CHARGING (1 << 0)
+static uint8_t avr_battery_status;
+
+#define BATTERY_LEVEL_NOT_DETECTED (1 << 7)
+#define BATTERY_LEVEL_PERCENTAGE_MASK 0x7F
+static uint8_t avr_battery_level = 100;
+
+static inline uint16_t be2short(uint8_t *buf)
{
- return (unsigned short)((buf[0] << 8) | buf[1]);
+ return (uint16_t)((buf[0] << 8) | buf[1]);
}
#define BUTTON_DIRECT_MASK (BUTTON_LEFT | BUTTON_UP | BUTTON_RIGHT | BUTTON_DOWN | BUTTON_SELECT | BUTTON_VOL_UP | BUTTON_VOL_DOWN | BUTTON_NEXT | BUTTON_PREV)
#ifndef BOOTLOADER
-static void handle_wheel(unsigned char wheel)
+static void handle_wheel(uint8_t wheel)
{
static int key = 0;
- static unsigned char velocity = 0;
- static unsigned long wheel_delta = 1ul << 24;
- static unsigned char wheel_prev = 0;
- static long nextbacklight_hw_on = 0;
+ static uint8_t velocity = 0;
+ static uint32_t wheel_delta = 1ul << 24;
+ static uint8_t wheel_prev = 0;
+ static unsigned long nextbacklight_hw_on = 0;
static int prev_key = -1;
static int prev_key_post = 0;
@@ -153,18 +201,18 @@ static void handle_wheel(unsigned char wheel)
}
#endif
-/* buf must be 11-byte array of byte (reply from avr_hid_get_state() */
-static void parse_button_state(unsigned char *buf)
+/* buf must be 8-byte state array (reply from avr_hid_get_state() */
+static void parse_button_state(uint8_t *state)
{
- unsigned short main_btns_state = be2short(&buf[4]);
+ uint16_t main_btns_state = be2short(&state[2]);
#ifdef BUTTON_DEBUG
- unsigned short main_btns_changed = be2short(&buf[6]);
+ uint16_t main_btns_changed = be2short(&state[4]);
#endif
/* make sure other bits doesn't conflict with our "free bits" buttons */
main_btns_state &= BUTTON_DIRECT_MASK;
- if (buf[3] & 0x01) /* is power button pressed? */
+ if (state[1] & 0x01) /* is power button pressed? */
{
main_btns_state |= BUTTON_POWER;
}
@@ -173,11 +221,11 @@ static void parse_button_state(unsigned char *buf)
#ifndef BOOTLOADER
/* check if stored hold_switch state changed (prevents lost changes) */
- if ((buf[3] & 0x20) /* hold change notification */ ||
- (hold_switch != ((buf[3] & 0x02) >> 1)))
+ if ((state[1] & 0x20) /* hold change notification */ ||
+ (hold_switch != ((state[1] & 0x02) >> 1)))
{
#endif
- hold_switch = (buf[3] & 0x02) >> 1;
+ hold_switch = (state[1] & 0x02) >> 1;
#ifdef BUTTON_DEBUG
dbgprintf("HOLD changed (%d)", hold_switch);
#endif
@@ -186,14 +234,14 @@ static void parse_button_state(unsigned char *buf)
}
#endif
#ifndef BOOTLOADER
- if ((hold_switch == false) && (buf[3] & 0x80)) /* scrollwheel change */
+ if ((hold_switch == false) && (state[1] & 0x80)) /* scrollwheel change */
{
- handle_wheel(buf[2]);
+ handle_wheel(state[0]);
}
#endif
#ifdef BUTTON_DEBUG
- if (buf[3] & 0x10) /* power button change */
+ if (state[1] & 0x10) /* power button change */
{
/* power button state has changed */
main_btns_changed |= BUTTON_POWER;
@@ -215,50 +263,164 @@ static void parse_button_state(unsigned char *buf)
#endif
}
-static void spi_txrx(unsigned char *buf_tx, unsigned char *buf_rx, int n)
+static bool avr_command_reads_data(uint8_t opcode)
+{
+ switch (opcode)
+ {
+ case CMD_STATE:
+ case CMD_VER:
+ case CMD_GET_LAST_RESET_TYPE:
+ case CMD_GET_INTCHRG:
+ case CMD_MONOTIME:
+ case CMD_UNKNOWN_C5:
+ case CMD_MONORSTCNT:
+ case CMD_HDQ_STATUS:
+ case CMD_GET_BATTERY_TEMP:
+ case CMD_GET_USBCHRG:
+ case CMD_ADC_RESULT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static size_t avr_command_data_size(uint8_t opcode)
{
- int i;
- unsigned short rxdata;
+ switch (opcode)
+ {
+ case CMD_STATE: return 8;
+ case CMD_VER: return 1;
+ case CMD_MONOTIME: return 4;
+ case CMD_PGMWAKE: return 4;
+ case CMD_HDQ_READ: return 1;
+ case CMD_HDQ_WRITE: return 2;
+ case CMD_HDQ_STATUS: return 2;
+ case CMD_GET_LAST_RESET_TYPE: return 1;
+ case CMD_UNKNOWN_C5: return 1;
+ case CMD_GET_BATTERY_TEMP: return 2;
+ case CMD_LCM_POWER: return 1;
+ case CMD_AMP_ENABLE: return 1;
+ case CMD_WHEEL_EN: return 1;
+ case CMD_SET_INTCHRG: return 1;
+ case CMD_GET_INTCHRG: return 1;
+ case CMD_UNKNOWN_D3: return 1;
+ case CMD_UNKNOWN_D4: return 1;
+ case CMD_UNKNOWN_D5: return 2;
+ case CMD_UNKNOWN_D6: return 2;
+ case CMD_CODEC_RESET: return 0;
+ case CMD_ADC_START: return 1;
+ case CMD_ADC_RESULT: return 2;
+ case CMD_SYS_CTRL: return 1;
+ case CMD_SET_USBCHRG: return 1;
+ case CMD_GET_USBCHRG: return 1;
+ case CMD_MONORSTCNT: return 2;
+ default:
+ panicf("Invalid AVR opcode %02X", opcode);
+ return 0;
+ }
+}
+
+static uint8_t spi_read_byte(void)
+{
+ uint16_t rxdata;
+
+ do
+ {
+ rxdata = IO_SERIAL1_RX_DATA;
+ }
+ while (rxdata & (1<<8));
+
+ return rxdata & 0xFF;
+}
+
+static bool avr_run_command(uint8_t opcode, uint8_t *data, size_t data_length)
+{
+ bool success = true;
+ const bool is_read = avr_command_reads_data(opcode);
+ size_t i;
+ uint8_t rx;
+
+ /* Verify command data size and also make sure command is valid */
+ if (avr_command_data_size(opcode) != data_length)
+ {
+ panicf("AVR %02x invalid data length", opcode);
+ }
mutex_lock(&avr_mtx);
bitset16(&IO_CLK_MOD2, CLK_MOD2_SIF1);
IO_SERIAL1_TX_ENABLE = 0x0001;
- for (i = 0; i<n; i++)
- {
- IO_SERIAL1_TX_DATA = buf_tx[i];
+ IO_SERIAL1_TX_DATA = CMD_SYNC;
+ spi_read_byte();
+ /* Allow AVR to process CMD_SYNC */
+ udelay(AVR_DELAY_US);
- /* 100 us wait for AVR */
- udelay(100);
+ IO_SERIAL1_TX_DATA = opcode;
+ rx = spi_read_byte();
+ if (rx != CMD_SYNC)
+ {
+ /* AVR failed to register CMD_SYNC */
+ success = false;
+ }
+ /* Allow AVR to process opcode */
+ udelay(AVR_DELAY_US);
- do
+ if (is_read)
+ {
+ for (i = 0; i < data_length; i++)
{
- rxdata = IO_SERIAL1_RX_DATA;
- } while (rxdata & (1<<8));
-
- if (buf_rx != NULL)
- buf_rx[i] = rxdata & 0xFF;
+ IO_SERIAL1_TX_DATA = CMD_FILL;
+ data[i] = spi_read_byte();
+ udelay(AVR_DELAY_US);
+ }
+ }
+ else
+ {
+ for (i = 0; i < data_length; i++)
+ {
+ IO_SERIAL1_TX_DATA = data[i];
+ spi_read_byte();
+ udelay(AVR_DELAY_US);
+ }
+ }
- /* 100 us wait to give AVR time to process data */
- udelay(100);
+ IO_SERIAL1_TX_DATA = CMD_CLOSE;
+ rx = spi_read_byte();
+ udelay(AVR_DELAY_US);
+ if (is_read)
+ {
+ success = success && (rx == CMD_CLOSE);
}
IO_SERIAL1_TX_ENABLE = 0;
bitclr16(&IO_CLK_MOD2, CLK_MOD2_SIF1);
mutex_unlock(&avr_mtx);
+
+ return success;
}
-void avr_hid_sync(void)
+
+static void avr_hid_sync(void)
{
- int i;
- unsigned char prg[4] = {CMD_SYNC, CMD_VER, CMD_FILL, CMD_CLOSE};
+ uint8_t data;
+ while (!avr_run_command(CMD_VER, &data, sizeof(data)))
+ {
+ /* TODO: Program HID if failing for long time.
+ * To do so, unfortunately, AVR firmware would have to be written
+ * from scratch as OF blob cannot be used due to licensing.
+ */
+ }
+
+}
- /* Send SYNC three times */
- for (i = 0; i<3; i++)
+static void avr_execute_command(uint8_t opcode, uint8_t *data, size_t data_length)
+{
+ while (!avr_run_command(opcode, data, data_length))
{
- spi_txrx(prg, NULL, sizeof(prg));
+ /* Resync and try again */
+ avr_hid_sync();
}
}
@@ -283,114 +445,147 @@ void avr_hid_init(void)
mutex_init(&avr_mtx);
}
-/* defined in powermgmt-sansaconnect.c */
-void set_battery_level(unsigned int level);
-
-static void avr_hid_get_state(void)
+int _battery_level(void)
{
- static unsigned char cmd[11] = {CMD_SYNC, CMD_STATE,
- CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL,
- CMD_CLOSE};
-
- static unsigned char buf[11];
- static unsigned char cmd_empty[1] = {0xCC};
+ /* OF still plays music when level is at 0 */
+ if (avr_battery_level & BATTERY_LEVEL_NOT_DETECTED)
+ {
+ return 0;
+ }
+ return avr_battery_level & BATTERY_LEVEL_PERCENTAGE_MASK;
+}
- spi_txrx(cmd, buf, sizeof(cmd));
+unsigned int power_input_status(void)
+{
+ if (avr_battery_status & BATTERY_STATUS_CHARGER_CONNECTED)
+ {
+ return POWER_INPUT_USB_CHARGER;
+ }
+ return POWER_INPUT_NONE;
+}
- /*
- * buf[8] contains some battery/charger related information (unknown)
- * buf[9] contains battery level in percents (0-100)
- */
- set_battery_level((unsigned int)buf[9]);
+bool charging_state(void)
+{
+ return (avr_battery_status & BATTERY_STATUS_CHARGING) != 0;
+}
- spi_txrx(cmd_empty, NULL, 1); /* request interrupt on button press */
+static void avr_hid_get_state(void)
+{
+ uint8_t state[8];
+ avr_execute_command(CMD_STATE, state, sizeof(state));
- parse_button_state(buf);
+ avr_battery_status = state[6];
+ avr_battery_level = state[7];
+ parse_button_state(state);
}
static void avr_hid_enable_wheel(void)
{
- unsigned char wheel_en[4] = {CMD_SYNC, CMD_WHEEL_EN, 0x01, CMD_CLOSE};
-
- spi_txrx(wheel_en, NULL, sizeof(wheel_en));
+ uint8_t enable = 0x01;
+ avr_execute_command(CMD_WHEEL_EN, &enable, sizeof(enable));
}
/* command that is sent by "hidtool -J 1" issued on every OF boot */
void avr_hid_enable_charger(void)
{
- unsigned char charger_en[4] = {CMD_SYNC, CMD_SET_INTCHRG, 0x01, CMD_CLOSE};
+ uint8_t enable = 0x01;
+ avr_execute_command(CMD_SET_INTCHRG, &enable, sizeof(enable));
+}
- spi_txrx(charger_en, NULL, sizeof(charger_en));
+static void avr_hid_lcm_power(uint8_t parameter)
+{
+ avr_execute_command(CMD_LCM_POWER, &parameter, sizeof(parameter));
}
void avr_hid_lcm_sleep(void)
{
- unsigned char lcm_sleep[4] = {CMD_SYNC, CMD_LCM_POWER, LCM_POWER_SLEEP, CMD_CLOSE};
-
- spi_txrx(lcm_sleep, NULL, sizeof(lcm_sleep));
+ avr_hid_lcm_power(LCM_POWER_SLEEP);
}
-
void avr_hid_lcm_wake(void)
{
- unsigned char lcm_wake[4] = {CMD_SYNC, CMD_LCM_POWER, LCM_POWER_WAKE, CMD_CLOSE};
-
- spi_txrx(lcm_wake, NULL, sizeof(lcm_wake));
+ avr_hid_lcm_power(LCM_POWER_WAKE);
}
void avr_hid_lcm_power_on(void)
{
- unsigned char lcm_power_on[4] = {CMD_SYNC, CMD_LCM_POWER, LCM_POWER_ON, CMD_CLOSE};
-
- spi_txrx(lcm_power_on, NULL, sizeof(lcm_power_on));
+ avr_hid_lcm_power(LCM_POWER_ON);
}
void avr_hid_lcm_power_off(void)
{
- unsigned char lcm_power_off[4] = {CMD_SYNC, CMD_LCM_POWER, LCM_POWER_OFF, CMD_CLOSE};
-
- spi_txrx(lcm_power_off, NULL, sizeof(lcm_power_off));
+ avr_hid_lcm_power(LCM_POWER_OFF);
}
void avr_hid_reset_codec(void)
{
- unsigned char codec_reset[4] = {CMD_SYNC, CMD_CODEC_RESET, CMD_CLOSE, CMD_FILL};
+ avr_execute_command(CMD_CODEC_RESET, NULL, 0);
+}
- spi_txrx(codec_reset, NULL, sizeof(codec_reset));
+void avr_hid_set_amp_enable(uint8_t enable)
+{
+ avr_execute_command(CMD_AMP_ENABLE, &enable, sizeof(enable));
}
-void avr_hid_power_off(void)
+static void avr_hid_sys_ctrl(uint8_t parameter)
{
- unsigned char prg[4] = {CMD_SYNC, CMD_SYS_CTRL, SYS_CTRL_POWEROFF, CMD_CLOSE};
+ avr_execute_command(CMD_SYS_CTRL, &parameter, sizeof(parameter));
+}
- spi_txrx(prg, NULL, sizeof(prg));
+void avr_hid_power_off(void)
+{
+ avr_hid_sys_ctrl(SYS_CTRL_POWEROFF);
}
#ifndef BOOTLOADER
-void btn_thread(void)
+static bool avr_state_changed(void)
{
- struct queue_event ev;
+ return (IO_GIO_BITSET0 & 0x1) ? false : true;
+}
- while (1)
+static bool headphones_inserted(void)
+{
+ return (IO_GIO_BITSET0 & 0x04) ? false : true;
+}
+
+static void set_audio_output(bool headphones)
+{
+ if (headphones)
+ {
+ /* Stereo output on headphones */
+ avr_hid_set_amp_enable(0);
+ aic3x_switch_output(true);
+ }
+ else
{
- queue_wait(&btn_queue, &ev);
-
- /* Ignore all messages except BTN_INTERRUPT */
- if (ev.id != BTN_INTERRUPT)
- continue;
+ /* Mono output on built-in speaker */
+ aic3x_switch_output(false);
+ avr_hid_set_amp_enable(1);
+ }
+}
- /* Enable back button interrupt */
- IO_INTC_EINT1 |= INTR_EINT1_EXT0;
+void avr_thread(void)
+{
+ bool headphones_active_state = headphones_inserted();
+ bool headphones_state;
- /* Read buttons state */
- avr_hid_get_state();
+ set_audio_output(headphones_active_state);
- yield();
+ while (1)
+ {
+ semaphore_wait(&avr_thread_trigger, TIMEOUT_BLOCK);
+
+ if (avr_state_changed())
+ {
+ /* Read buttons state */
+ avr_hid_get_state();
+ }
- if (queue_empty(&btn_queue) && ((IO_GIO_BITSET0 & 0x1) == 0))
+ headphones_state = headphones_inserted();
+ if (headphones_state != headphones_active_state)
{
- /* for some reason we have lost next interrupt */
- queue_post(&btn_queue, BTN_INTERRUPT, 0);
+ set_audio_output(headphones_state);
+ headphones_active_state = headphones_state;
}
}
}
@@ -400,39 +595,17 @@ void GIO0(void)
{
/* Clear interrupt */
IO_INTC_IRQ1 = (1 << 5);
- /* Disable interrupt */
- IO_INTC_EINT1 &= ~INTR_EINT1_EXT0;
-
- /* interrupt will be enabled back after button read */
- queue_post(&btn_queue, BTN_INTERRUPT, 0);
-}
-
-static int headphones_inserted_callback(struct timeout *tmo)
-{
- (void)tmo;
- if (IO_GIO_BITSET0 & 0x04)
- {
- aic3x_switch_output(false);
- }
- else
- {
- aic3x_switch_output(true);
- }
-
- return 0;
+ semaphore_release(&avr_thread_trigger);
}
void GIO2(void) __attribute__ ((section(".icode")));
void GIO2(void)
{
- static struct timeout headphones_oneshot;
-
/* Clear interrupt */
IO_INTC_IRQ1 = (1 << 7);
- timeout_register(&headphones_oneshot, headphones_inserted_callback,
- HZ/2, 0);
+ semaphore_release(&avr_thread_trigger);
}
#endif
@@ -441,13 +614,16 @@ void button_init_device(void)
btn = 0;
hold_switch = false;
#ifndef BOOTLOADER
- queue_init(&btn_queue, true);
- create_thread(btn_thread, btn_stack, sizeof(btn_stack), 0,
- btn_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE)
+ semaphore_init(&avr_thread_trigger, 1, 1);
+ create_thread(avr_thread, avr_stack, sizeof(avr_stack), 0,
+ avr_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE)
IF_COP(, CPU));
#endif
IO_GIO_DIR0 |= 0x01; /* Set GIO0 as input */
+ /* Get in sync with AVR */
+ avr_hid_sync();
+
/* Enable wheel */
avr_hid_enable_wheel();
/* Read button status and tell avr we want interrupt on next change */
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h
index 06fd2b2d72..64b44675f7 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h
+++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h
@@ -24,7 +24,6 @@
#include "config.h"
-void avr_hid_sync(void);
void avr_hid_init(void);
void avr_hid_enable_charger(void);
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c
index 27eb0b407a..07be11e849 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c
@@ -123,7 +123,6 @@ void lcd_init_device(void)
/* Copy Rockbox frame buffer to the second framebuffer */
lcd_update();
- avr_hid_sync();
avr_hid_lcm_power_on();
/* set framebuffer address - OF sets RAM start address to 0x1000000 */
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c
index ecdf3b1a75..b139572605 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c
@@ -74,21 +74,7 @@ void power_off(void)
avr_hid_power_off();
}
-#if CONFIG_CHARGING
-unsigned int power_input_status(void)
-{
- return POWER_INPUT_NONE;
-}
-
-/* Returns true if the unit is charging the batteries. */
-bool charging_state(void)
-{
- return false;
-}
-#endif
-
void ide_power_enable(bool on)
{
(void)on;
}
-
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c
deleted file mode 100644
index 8b3f05107c..0000000000
--- a/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/***************************************************************************
- * __________ __ ___.
- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
- * \/ \/ \/ \/ \/
- * $Id: $
- *
- * Copyright (C) 2011 by Tomasz Moń
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- ****************************************************************************/
-
-#include "config.h"
-#include "adc.h"
-#include "powermgmt.h"
-#include "kernel.h"
-
-/* Use fake linear scale as AVR does the voltage to percentage conversion */
-
-static unsigned int current_battery_level = 100;
-
-/* This specifies the battery level that writes are still safe */
-const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
-{
- 5
-};
-
-/* Below this the player cannot be considered to operate reliably */
-const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
-{
- 4
-};
-
-/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
-const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
-{
- { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 },
-};
-
-/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
-const unsigned short percent_to_volt_charge[11] =
-{
- 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
-};
-
-/* Returns battery voltage from ADC [millivolts] */
-int _battery_voltage(void)
-{
- return current_battery_level;
-}
-
-void set_battery_level(unsigned int level)
-{
- current_battery_level = level;
-}
-
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_cppi.c b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_cppi.c
new file mode 100644
index 0000000000..93477bed9e
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_cppi.c
@@ -0,0 +1,1044 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: $
+ *
+ * Copyright (C) 2021 by Tomasz Moń
+ * Copied with minor modifications from Sansa Connect Linux driver
+ * Copyright (c) 2005,2006 Zermatt Systems, Inc.
+ * Written by: Ben Bostwick
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <string.h>
+#include "config.h"
+#include "system.h"
+#include "kernel.h"
+#include "panic.h"
+#include "logf.h"
+#include "tnetv105_usb_drv.h"
+#include "tnetv105_cppi.h"
+
+/* This file is pretty much directly copied from the Sansa Connect
+ * Linux kernel source code. This is because the functionality is
+ * nicely separated from actual kernel specific code and CPPI seems
+ * complex (atleast without access to the datasheet).
+ *
+ * The only non cosmetic change was changing the dynamic allocations
+ * to static allocations.
+ *
+ * It seems that the only way to get interrupt on non-control endpoint
+ * acticity is to use the CPPI. This sounds like a plausible explanation
+ * for the fake DMA buffers mentioned in CPPI code.
+ */
+
+/* Translate Linux consistent_sync() to Rockbox functions */
+#define DMA_TO_DEVICE commit_discard_dcache_range
+#define DMA_FROM_DEVICE discard_dcache_range
+#define consistent_sync(ptr, size, func) func(ptr, size)
+/* Rockbox TMS320DM320 crt0.S maps everything to itself */
+#define __virt_to_phys(ptr) ptr
+#define __phys_to_virt(ptr) ptr
+
+// CPPI functions
+#define CB_SOF_BIT (1<<31)
+#define CB_EOF_BIT (1<<30)
+#define CB_OWNERSHIP_BIT (1<<29)
+#define CB_EOQ_BIT (1<<28)
+#define CB_ZLP_GARBAGE (1<<23)
+#define CB_SIZE_MASK 0x0000ffff
+#define CB_OFFSET_MASK 0xffff0000
+#define TEARDOWN_VAL 0xfffffffc
+
+#define MAX_BUF_SIZE 512
+
+#define CPPI_DMA_RX_BUF_SIZE (MAX_BUF_SIZE * CPPI_RX_NUM_BUFS)
+
+static uint8_t *dma_recv_buf[CPPI_NUM_CHANNELS];
+static uint8_t ch0_rx_buf[CPPI_DMA_RX_BUF_SIZE];
+static uint8_t ch1_rx_buf[CPPI_DMA_RX_BUF_SIZE];
+
+#if USB_CPPI_LOGGING
+#define cppi_log_event0(msg) usb_log_event(msg, LOG_EVENT_D0, 0, 0, 0, 0)
+#define cppi_log_event1(msg, data0) usb_log_event(msg, LOG_EVENT_D1, data0, 0, 0, 0)
+#define cppi_log_event2(msg, data0, data1) usb_log_event(msg, LOG_EVENT_D2, data0, data1, 0, 0)
+#define cppi_log_event3(msg, data0, data1, data2) usb_log_event(msg, LOG_EVENT_D3, data0, data1, data2, 0)
+#define cppi_log_event4(msg, data0, data1, data2, data3) usb_log_event(msg, LOG_EVENT_D4, data0, data1, data2, data3)
+#else
+#define cppi_log_event0(x)
+#define cppi_log_event1(x, y)
+#define cppi_log_event2(x, y, z)
+#define cppi_log_event3(x, y, z, w)
+#define cppi_log_event4(x, y, z, w, u)
+#endif
+
+/*
+ * This function processes transmit interrupts. It traverses the
+ * transmit buffer queue, detecting sent data buffers
+ *
+ * @return 0 if OK, non-zero otherwise.
+ */
+int tnetv_cppi_tx_int(struct cppi_info *cppi, int ch)
+{
+ cppi_tcb *CurrentTcb,*LastTcbProcessed;
+ uint32_t TxFrameStatus;
+ cppi_txcntl *pTxCtl = &cppi->tx_ctl[ch];
+ int bytes_sent = 0;
+
+ cppi_log_event1("[cppi]TxInt ch", ch);
+
+ CurrentTcb = pTxCtl->TxActQueueHead;
+
+ if (CurrentTcb == 0)
+ {
+ cppi_log_event0("[cppi] tx int: no current tcb");
+ return -1;
+ }
+
+ // sync up the tcb from memory
+ consistent_sync(CurrentTcb, sizeof(*CurrentTcb), DMA_FROM_DEVICE);
+
+ TxFrameStatus = CurrentTcb->mode;
+ LastTcbProcessed = NULL;
+
+ cppi_log_event3("[cppi] int tcb status", (uint32_t) CurrentTcb, TxFrameStatus, CurrentTcb->Off_BLen);
+
+ while(CurrentTcb && (TxFrameStatus & CB_OWNERSHIP_BIT) == 0)
+ {
+ cppi_log_event3("[cppi] tx int: tcb (mode) (len)", (uint32_t) CurrentTcb, CurrentTcb->mode, CurrentTcb->Off_BLen);
+
+ // calculate the amount of bytes sent.
+ // don't count the fake ZLP byte
+ if (CurrentTcb->Off_BLen > 0x1)
+ {
+ bytes_sent += CurrentTcb->Off_BLen & 0xFFFF;
+ }
+
+ if (CurrentTcb->mode & CB_EOQ_BIT)
+ {
+ if (CurrentTcb->Next)
+ {
+ cppi_log_event0(" [cppi] misqueue!");
+
+ // Misqueued packet
+ tnetv_usb_reg_write(TNETV_DMA_TX_STATE(ch, TNETV_CPPI_TX_WORD_HDP), CurrentTcb->HNext);
+ }
+ else
+ {
+ cppi_log_event0("[cppi] eoq");
+
+ /* Tx End of Queue */
+ pTxCtl->TxActive = 0;
+ }
+ }
+
+ cppi_log_event1("[cppi]SendComplete: ", CurrentTcb->Off_BLen & 0xFFFF);
+
+ // Write the completion pointer
+ tnetv_usb_reg_write(TNETV_DMA_TX_CMPL(ch), __dma_to_vlynq_phys(CurrentTcb->dma_handle));
+
+
+ LastTcbProcessed = CurrentTcb;
+ CurrentTcb = CurrentTcb->Next;
+
+ // clean up TCB fields
+ LastTcbProcessed->HNext = 0;
+ LastTcbProcessed->Next = 0;
+ LastTcbProcessed->BufPtr = 0;
+ LastTcbProcessed->Off_BLen = 0;
+ LastTcbProcessed->mode = 0;
+ LastTcbProcessed->Eop = 0;
+
+ /* Push Tcb(s) back onto the list */
+ if (pTxCtl->TcbPool)
+ {
+ LastTcbProcessed->Next = pTxCtl->TcbPool->Next;
+ pTxCtl->TcbPool->Next = LastTcbProcessed;
+ }
+ else
+ {
+ pTxCtl->TcbPool = LastTcbProcessed;
+ }
+
+ consistent_sync(LastTcbProcessed, sizeof(*LastTcbProcessed), DMA_TO_DEVICE);
+
+ // get the status of the next packet
+ if (CurrentTcb)
+ {
+ // sync up the tcb from memory
+ consistent_sync(CurrentTcb, sizeof(*CurrentTcb), DMA_FROM_DEVICE);
+
+ TxFrameStatus = CurrentTcb->mode;
+ }
+
+
+ }
+
+ pTxCtl->TxActQueueHead = CurrentTcb;
+
+ if (!LastTcbProcessed)
+ {
+ cppi_log_event1(" [cppi]No Tx packets serviced on int! ch", ch);
+ return -1;
+ }
+
+ return bytes_sent;
+}
+
+int tnetv_cppi_flush_tx_queue(struct cppi_info *cppi, int ch)
+{
+ cppi_txcntl *pTxCtl = &cppi->tx_ctl[ch];
+ cppi_tcb *tcb, *next_tcb;
+
+ tcb = pTxCtl->TxActQueueHead;
+
+ cppi_log_event1("[cppi] flush TX ", (uint32_t) pTxCtl->TxActQueueHead);
+
+ while (tcb)
+ {
+ tcb->mode = 0;
+ tcb->BufPtr = 0;
+ tcb->Off_BLen = 0;
+ tcb->Eop = 0;
+ tcb->HNext = 0;
+
+ next_tcb = tcb->Next;
+
+ tcb->Next = pTxCtl->TcbPool;
+ pTxCtl->TcbPool = tcb;
+
+ tcb = next_tcb;
+ }
+
+ pTxCtl->TxActQueueHead = 0;
+ pTxCtl->TxActQueueTail = 0;
+ pTxCtl->TxActive = 0;
+
+ return 0;
+}
+
+
+/**
+ * @ingroup CPHAL_Functions
+ * This function transmits the data in FragList using available transmit
+ * buffer descriptors. More information on the use of the Mode parameter
+ * is available in the module-specific appendices. Note: The OS should
+ * not call Send() for a channel that has been requested to be torndown.
+ *
+ */
+int tnetv_cppi_send(struct cppi_info *cppi, int ch, dma_addr_t buf, unsigned length, int send_zlp)
+{
+ cppi_txcntl *pTxCtl;
+ cppi_tcb *first_tcb;
+ cppi_tcb *tcb;
+ int queued_len;
+ dma_addr_t buf_to_send;
+ dma_addr_t buf_ptr;
+ int total_len = length;
+ int pktlen;
+
+ pTxCtl = &cppi->tx_ctl[ch];
+
+ if (length == 0)
+ {
+ cppi_log_event0("[cppi] len = 0, nothing to send");
+ return -1;
+ }
+
+ // no send buffers.. try again later
+ if (!pTxCtl->TcbPool)
+ {
+ cppi_log_event0("[cppi] out of cppi buffers");
+ return -1;
+ }
+
+ // only send 1 packet at a time
+ if (pTxCtl->TxActQueueHead || pTxCtl->TxActive)
+ {
+ cppi_log_event0("[cppi] already sending!");
+ return -1;
+ }
+
+ buf_to_send = buf;
+
+ // usb_requests can have a 32 bit length, but CPPI DMA fragments
+ // have a (64k - 1) limit. Split the usb_request up into fragments here.
+ first_tcb = pTxCtl->TcbPool;
+ tcb = first_tcb;
+
+ cppi_log_event4("[cppi]cppi_send (buf) (len) (pool) (dma)", (uint32_t) buf_to_send, total_len, (uint32_t) first_tcb, first_tcb->dma_handle);
+
+ queued_len = 0;
+
+ do
+ {
+ buf_ptr = buf_to_send + queued_len;
+ tcb->BufPtr = __dma_to_vlynq_phys(buf_ptr);
+ tcb->HNext = 0;
+
+ // can't transfer more that 64k-1 bytes in 1 CPPI transfer
+ // need to queue up transfers if it's greater than that
+ pktlen = ((total_len - queued_len) > CPPI_MAX_FRAG) ? CPPI_MAX_FRAG : (total_len - queued_len);
+ tcb->Off_BLen = pktlen;
+ tcb->mode = (CB_OWNERSHIP_BIT | CB_SOF_BIT | CB_EOF_BIT | pktlen);
+
+ queued_len += pktlen;
+
+ if (queued_len < total_len)
+ {
+ tcb->HNext = __dma_to_vlynq_phys(((cppi_tcb *) tcb->Next)->dma_handle);
+
+ // write out the buffer to memory
+ consistent_sync(tcb, sizeof(*tcb), DMA_TO_DEVICE);
+
+ cppi_log_event4("[cppi] q tcb", (uint32_t) tcb, ((uint32_t *) tcb)[0], ((uint32_t *) tcb)[1], ((uint32_t *) tcb)[2]);
+ cppi_log_event4("[cppi] ", ((uint32_t *) tcb)[3], ((uint32_t *) tcb)[4], ((uint32_t *) tcb)[5], ((uint32_t *) tcb)[6]);
+
+ tcb = tcb->Next;
+ }
+ } while (queued_len < total_len);
+
+ /* In the Tx Interrupt handler, we will need to know which TCB is EOP,
+ so we can save that information in the SOP */
+ first_tcb->Eop = tcb;
+
+ // set the secret ZLP bit if necessary, this will be a completely separate packet
+ if (send_zlp)
+ {
+#if defined(AUTO_ZLP) && AUTO_ZLP
+ // add an extra buffer at the end to hold the ZLP
+ tcb->HNext = __dma_to_vlynq_phys(((cppi_tcb *) tcb->Next)->dma_handle);
+
+ // write out the buffer to memory
+ consistent_sync(tcb, sizeof(*tcb), DMA_TO_DEVICE);
+
+ tcb = tcb->Next;
+
+ /* In the Tx Interrupt handler, we will need to know which TCB is EOP,
+ so we can save that information in the SOP */
+ first_tcb->Eop = tcb;
+#endif
+
+ buf_ptr = buf_to_send + queued_len;
+ tcb->BufPtr = __dma_to_vlynq_phys(buf_ptr); // not used, but can't be zero
+ tcb->HNext = 0;
+ tcb->Off_BLen = 0x1; // device will send (((len - 1) / maxpacket) + 1) ZLPs
+ tcb->mode = (CB_SOF_BIT | CB_EOF_BIT | CB_OWNERSHIP_BIT | CB_ZLP_GARBAGE | 0x1); // send 1 ZLP
+ tcb->Eop = tcb;
+
+ cppi_log_event0("[cppi] Send ZLP!");
+ }
+
+ pTxCtl->TcbPool = tcb->Next;
+
+ tcb->Next = 0;
+ tcb->HNext = 0;
+
+ // write out the buffer to memory
+ consistent_sync(tcb, sizeof(*tcb), DMA_TO_DEVICE);
+
+ cppi_log_event4("[cppi] q tcb", (uint32_t) tcb, ((uint32_t *) tcb)[0], ((uint32_t *) tcb)[1], ((uint32_t *) tcb)[2]);
+ cppi_log_event4("[cppi] ", ((uint32_t *) tcb)[3], ((uint32_t *) tcb)[4], ((uint32_t *) tcb)[5], ((uint32_t *) tcb)[6]);
+
+ cppi_log_event4("[cppi] send queued (ptr) (len) (ftcb, ltcb)", (uint32_t) tcb->BufPtr, tcb->Off_BLen, (uint32_t) first_tcb, (uint32_t) tcb);
+
+ /* put it on the queue */
+ pTxCtl->TxActQueueHead = first_tcb;
+ pTxCtl->TxActQueueTail = tcb;
+
+ cppi_log_event3("[cppi] setting state (head) (virt) (next)", (uint32_t) first_tcb, __dma_to_vlynq_phys(first_tcb->dma_handle), (uint32_t) first_tcb->HNext);
+
+ /* write CPPI TX HDP - cache is cleaned above */
+ tnetv_usb_reg_write(TNETV_DMA_TX_STATE(ch, TNETV_CPPI_TX_WORD_HDP), __dma_to_vlynq_phys(first_tcb->dma_handle));
+
+ pTxCtl->TxActive = 1;
+
+ return 0;
+}
+
+/*
+ * This function allocates transmit buffer descriptors (internal CPHAL function).
+ * It creates a high priority transmit queue by default for a single Tx
+ * channel. If QoS is enabled for the given CPHAL device, this function
+ * will also allocate a low priority transmit queue.
+ *
+ * @return 0 OK, Non-Zero Not OK
+ */
+int tnetv_cppi_init_tcb(struct cppi_info *cppi, int ch)
+{
+ int i, num;
+ cppi_tcb *pTcb = 0;
+ char *AllTcb;
+ int tcbSize;
+ cppi_txcntl *pTxCtl = &cppi->tx_ctl[ch];
+
+ num = pTxCtl->TxNumBuffers;
+ tcbSize = (sizeof(cppi_tcb) + 0xf) & ~0xf;
+
+ cppi_log_event4("[cppi] init_tcb (ch) (num) (dma) (tcbsz)", ch, num, pTxCtl->tcb_start_dma_addr, tcbSize);
+
+ if (pTxCtl->TxNumBuffers == 0)
+ {
+ return -1;
+ }
+
+ /* if the memory has already been allocated, simply reuse it! */
+ AllTcb = pTxCtl->TcbStart;
+
+ // now reinitialize the TCB pool
+ pTxCtl->TcbPool = 0;
+ for (i = 0; i < num; i++)
+ {
+ pTcb = (cppi_tcb *)(AllTcb + (i * tcbSize));
+ pTcb->dma_handle = pTxCtl->tcb_start_dma_addr + (i * tcbSize);
+
+ pTcb->BufPtr = 0;
+ pTcb->mode = 0;
+ pTcb->HNext = 0;
+ pTcb->Off_BLen = 0;
+ pTcb->Eop = 0;
+
+ pTcb->Next = (void *) pTxCtl->TcbPool;
+
+ pTxCtl->TcbPool = pTcb;
+ }
+
+ cppi_log_event2(" [cppi]TcbPool", (uint32_t) pTxCtl->TcbPool, pTxCtl->TcbPool->dma_handle);
+
+#if USB_CPPI_LOGGING
+ {
+ // BEN DEBUG
+ cppi_tcb *first_tcb = pTxCtl->TcbPool;
+ cppi_log_event4("[cppi] init tcb", (uint32_t) first_tcb, ((uint32_t *) first_tcb)[0], ((uint32_t *) first_tcb)[1], ((uint32_t *) first_tcb)[2]);
+ cppi_log_event4("[cppi] ", ((uint32_t *) first_tcb)[3], ((uint32_t *) first_tcb)[4], ((uint32_t *) first_tcb)[5], ((uint32_t *) first_tcb)[6]);
+ }
+#endif
+
+ return 0;
+}
+
+// BEN DEBUG
+void tnetv_cppi_dump_info(struct cppi_info *cppi)
+{
+ int ch;
+ cppi_rxcntl *pRxCtl;
+ cppi_txcntl *pTxCtl;
+ cppi_tcb *tcb;
+ cppi_rcb *rcb;
+
+ logf("CPPI struct:\n");
+ logf("Buf mem: %x Buf size: %d int: %x %x\n\n", (uint32_t) cppi->dma_mem, cppi->dma_size, tnetv_usb_reg_read(TNETV_USB_RX_INT_STATUS), tnetv_usb_reg_read(DM320_VLYNQ_INTST));
+
+ for (ch = 0; ch < CPPI_NUM_CHANNELS; ch++)
+ {
+ pRxCtl = &cppi->rx_ctl[ch];
+ pTxCtl = &cppi->tx_ctl[ch];
+
+ logf("ch: %d\n", ch);
+ logf(" rx_numbufs: %d active %d free_buf_cnt %d\n", pRxCtl->RxNumBuffers, pRxCtl->RxActive, tnetv_usb_reg_read(TNETV_USB_RX_FREE_BUF_CNT(ch)));
+ logf(" q_cnt %d head %x tail %x\n", pRxCtl->RxActQueueCount, (uint32_t) pRxCtl->RxActQueueHead, (uint32_t) pRxCtl->RxActQueueTail);
+ logf(" fake_head: %x fake_tail: %x\n", (uint32_t) pRxCtl->RxFakeRcvHead, (uint32_t) pRxCtl->RxFakeRcvTail);
+
+ rcb = (cppi_rcb *) pRxCtl->RcbStart;
+ do
+ {
+ if (!rcb)
+ break;
+
+ logf(" Rcb: %x\n", (uint32_t) rcb);
+ logf(" HNext %x BufPtr %x Off_BLen %x mode %x\n", rcb->HNext, rcb->BufPtr, rcb->Off_BLen, rcb->mode);
+ logf(" Next %x Eop %x dma_handle %x fake_bytes %x\n", (uint32_t) rcb->Next, (uint32_t) rcb->Eop, rcb->dma_handle, rcb->fake_bytes);
+ rcb = rcb->Next;
+
+ } while (rcb && rcb != (cppi_rcb *) pRxCtl->RcbStart);
+
+ logf("\n");
+ logf(" tx_numbufs: %d active %d\n", pTxCtl->TxNumBuffers, pTxCtl->TxActive);
+ logf(" q_cnt %d head %x tail %x\n", pTxCtl->TxActQueueCount, (uint32_t) pTxCtl->TxActQueueHead, (uint32_t) pTxCtl->TxActQueueTail);
+
+ tcb = (cppi_tcb *) pTxCtl->TcbPool;
+ do
+ {
+ if (!tcb)
+ break;
+
+ logf(" Tcb (pool): %x\n", (uint32_t) tcb);
+ logf(" HNext %x BufPtr %x Off_BLen %x mode %x\n", tcb->HNext, tcb->BufPtr, tcb->Off_BLen, tcb->mode);
+ logf(" Next %x Eop %x dma_handle %x\n", (uint32_t) tcb->Next, (uint32_t) tcb->Eop, tcb->dma_handle);
+ tcb = tcb->Next;
+
+ } while (tcb && tcb != (cppi_tcb *) pTxCtl->TcbPool);
+
+ tcb = (cppi_tcb *) pTxCtl->TxActQueueHead;
+ do
+ {
+ if (!tcb)
+ break;
+
+ logf(" Tcb (act): %x\n", (uint32_t) tcb);
+ logf(" HNext %x BufPtr %x Off_BLen %x mode %x\n", tcb->HNext, tcb->BufPtr, tcb->Off_BLen, tcb->mode);
+ logf(" Next %x Eop %x dma_handle %x\n", (uint32_t) tcb->Next, (uint32_t) tcb->Eop, tcb->dma_handle);
+ tcb = tcb->Next;
+
+ } while (tcb && tcb != (cppi_tcb *) pTxCtl->TxActQueueTail);
+
+ }
+}
+
+/**
+ *
+ * This function is called to indicate to the CPHAL that the upper layer
+ * software has finished processing the receive data (given to it by
+ * osReceive()). The CPHAL will then return the appropriate receive buffers
+ * and buffer descriptors to the available pool.
+ *
+ */
+int tnetv_cppi_rx_return(struct cppi_info *cppi, int ch, cppi_rcb *done_rcb)
+{
+ cppi_rxcntl *pRxCtl = &cppi->rx_ctl[ch];
+ cppi_rcb *curRcb, *lastRcb, *endRcb;
+ int num_bufs = 0;
+
+ if (!done_rcb)
+ return -1;
+
+ //cppi_log_event3("[cppi] rx_return (last) (first) bufinq", (uint32_t) done_rcb, (uint32_t) done_rcb->Eop, tnetv_usb_reg_read(TNETV_USB_RX_FREE_BUF_CNT(ch)));
+
+ curRcb = done_rcb;
+ endRcb = done_rcb->Eop;
+ do
+ {
+ curRcb->mode = CB_OWNERSHIP_BIT;
+ curRcb->Off_BLen = MAX_BUF_SIZE;
+ curRcb->Eop = 0;
+
+ pRxCtl->RxActQueueCount++;
+ num_bufs++;
+
+ lastRcb = curRcb;
+ curRcb = lastRcb->Next;
+
+ consistent_sync(lastRcb, sizeof(*lastRcb), DMA_TO_DEVICE);
+
+ } while (lastRcb != endRcb);
+
+ cppi_log_event1("[cppi] rx_return done", num_bufs);
+
+ // let the hardware know about the buffer(s)
+ tnetv_usb_reg_write(TNETV_USB_RX_FREE_BUF_CNT(ch), num_bufs);
+
+ return 0;
+}
+
+int tnetv_cppi_rx_int_recv(struct cppi_info *cppi, int ch, int *buf_size, void *buf, int maxpacket)
+{
+ cppi_rxcntl *pRxCtl = &cppi->rx_ctl[ch];
+ cppi_rcb *CurrentRcb, *LastRcb = 0, *SopRcb;
+ uint8_t *cur_buf_data_addr;
+ int cur_buf_bytes;
+ int copy_buf_size = *buf_size;
+ int ret = -EAGAIN;
+
+ *buf_size = 0;
+
+ CurrentRcb = pRxCtl->RxFakeRcvHead;
+ if (!CurrentRcb)
+ {
+ cppi_log_event2("[cppi] rx_int recv: nothing in q", tnetv_usb_reg_read(TNETV_USB_RX_INT_STATUS), tnetv_usb_reg_read(DM320_VLYNQ_INTST));
+ return -1;
+ }
+
+ cppi_log_event1("[cppi] rx_int recv (ch)", ch);
+ cppi_log_event4(" [cppi] recv - Processing SOP descriptor fb hd tl", (uint32_t) CurrentRcb, CurrentRcb->fake_bytes, (uint32_t) pRxCtl->RxFakeRcvHead, (uint32_t) pRxCtl->RxFakeRcvTail);
+
+ SopRcb = CurrentRcb;
+ LastRcb = 0;
+
+ do
+ {
+ // convert from vlynq phys to virt
+ cur_buf_data_addr = (uint8_t *) __vlynq_phys_to_dma(CurrentRcb->BufPtr);
+ cur_buf_data_addr = (uint8_t *) __phys_to_virt(cur_buf_data_addr);
+ cur_buf_bytes = (CurrentRcb->mode) & CB_SIZE_MASK;
+
+ // make sure we don't overflow the buffer.
+ if (cur_buf_bytes > copy_buf_size)
+ {
+ ret = 0;
+ break;
+ }
+
+ // BEN - packet can be ZLP
+ if (cur_buf_bytes)
+ {
+ consistent_sync(cur_buf_data_addr, MAX_BUF_SIZE, DMA_FROM_DEVICE);
+
+ memcpy((buf + *buf_size), cur_buf_data_addr, cur_buf_bytes);
+
+ copy_buf_size -= cur_buf_bytes;
+ *buf_size += cur_buf_bytes;
+ CurrentRcb->fake_bytes -= cur_buf_bytes;
+ }
+ else
+ {
+ CurrentRcb->fake_bytes = 0;
+ }
+
+ cppi_log_event4(" [cppi] bytes totrcvd amtleft fake", cur_buf_bytes, *buf_size, copy_buf_size, CurrentRcb->fake_bytes);
+
+ LastRcb = CurrentRcb;
+ CurrentRcb = LastRcb->Next;
+
+ // sync out fake bytes info
+ consistent_sync(LastRcb, sizeof(*LastRcb), DMA_TO_DEVICE);
+
+ // make sure each packet processed individually
+ if (cur_buf_bytes < maxpacket)
+ {
+ ret = 0;
+ break;
+ }
+
+ } while (LastRcb != pRxCtl->RxFakeRcvTail && CurrentRcb->fake_bytes && copy_buf_size > 0);
+
+ // make sure that the CurrentRcb isn't in the cache
+ consistent_sync(CurrentRcb, sizeof(*CurrentRcb), DMA_FROM_DEVICE);
+
+ if (copy_buf_size == 0)
+ {
+ ret = 0;
+ }
+
+ if (LastRcb)
+ {
+ SopRcb->Eop = LastRcb;
+
+ cppi_log_event3(" [cppi] rcv end", *buf_size, (uint32_t) CurrentRcb, (uint32_t) SopRcb->Eop);
+
+ if (LastRcb == pRxCtl->RxFakeRcvTail)
+ {
+ pRxCtl->RxFakeRcvHead = 0;
+ pRxCtl->RxFakeRcvTail = 0;
+ }
+ else
+ {
+ pRxCtl->RxFakeRcvHead = CurrentRcb;
+ }
+
+ cppi_log_event1(" [cppi] st rx return", ch);
+ cppi_log_event2(" rcv fake hd tl", (uint32_t) pRxCtl->RxFakeRcvHead, (uint32_t) pRxCtl->RxFakeRcvTail);
+
+ // all done, clean up the RCBs
+ tnetv_cppi_rx_return(cppi, ch, SopRcb);
+ }
+
+ return ret;
+}
+
+/*
+ * This function processes receive interrupts. It traverses the receive
+ * buffer queue, extracting the data and passing it to the upper layer software via
+ * osReceive(). It handles all error conditions and fragments without valid data by
+ * immediately returning the RCB's to the RCB pool.
+ */
+int tnetv_cppi_rx_int(struct cppi_info *cppi, int ch)
+{
+ cppi_rxcntl *pRxCtl = &cppi->rx_ctl[ch];
+ cppi_rcb *CurrentRcb, *LastRcb = 0, *SopRcb;
+ uint32_t RxBufStatus,PacketsServiced;
+ int TotalFrags;
+
+ cppi_log_event1("[cppi] rx_int (ch)", ch);
+
+ CurrentRcb = pRxCtl->RxActQueueHead;
+
+ if (!CurrentRcb)
+ {
+ cppi_log_event1("[cppi] rx_int no bufs!", (uint32_t) CurrentRcb);
+ return -1;
+ }
+
+ // make sure that all of the buffers get an invalidated cache
+ consistent_sync(pRxCtl->RcbStart, sizeof(cppi_rcb) * CPPI_RX_NUM_BUFS, DMA_FROM_DEVICE);
+
+ RxBufStatus = CurrentRcb->mode;
+ PacketsServiced = 0;
+
+ cppi_log_event4("[cppi] currentrcb, mode numleft fake", (uint32_t) CurrentRcb, CurrentRcb->mode, pRxCtl->RxActQueueCount, CurrentRcb->fake_bytes);
+ cppi_log_event4("[cppi]", ((uint32_t *) CurrentRcb)[0], ((uint32_t *) CurrentRcb)[1], ((uint32_t *) CurrentRcb)[2], ((uint32_t *) CurrentRcb)[3]);
+
+ while(((RxBufStatus & CB_OWNERSHIP_BIT) == 0) && (pRxCtl->RxActQueueCount > 0))
+ {
+ cppi_log_event2(" [cppi]Processing SOP descriptor st", (uint32_t) CurrentRcb, RxBufStatus);
+
+ SopRcb = CurrentRcb;
+
+ TotalFrags = 0;
+
+ do
+ {
+ TotalFrags++;
+ PacketsServiced++;
+
+ // Write the completion pointer
+ tnetv_usb_reg_write(TNETV_DMA_RX_CMPL(ch), __dma_to_vlynq_phys(CurrentRcb->dma_handle));
+
+ CurrentRcb->fake_bytes = (CurrentRcb->mode) & 0xFFFF;
+
+ // BEN - make sure this gets marked!
+ if (!CurrentRcb->fake_bytes || (CurrentRcb->mode & CB_ZLP_GARBAGE))
+ {
+ CurrentRcb->mode &= 0xFFFF0000;
+ CurrentRcb->fake_bytes = 0x10000;
+ }
+
+ cppi_log_event1(" fake_bytes:", CurrentRcb->fake_bytes);
+
+ RxBufStatus = CurrentRcb->mode;
+ LastRcb = CurrentRcb;
+ CurrentRcb = LastRcb->Next;
+
+ // sync the fake_bytes value back to mem
+ consistent_sync(LastRcb, sizeof(*LastRcb), DMA_TO_DEVICE);
+
+ } while (((CurrentRcb->mode & CB_OWNERSHIP_BIT) == 0) && ((RxBufStatus & CB_EOF_BIT) == 0));
+
+ SopRcb->Eop = LastRcb;
+
+ pRxCtl->RxActQueueHead = CurrentRcb;
+ pRxCtl->RxActQueueCount -= TotalFrags;
+
+ if (LastRcb->mode & CB_EOQ_BIT)
+ {
+ if (CurrentRcb)
+ {
+ cppi_log_event1(" [cppi] rcv done q next", LastRcb->HNext);
+ tnetv_usb_reg_write(TNETV_DMA_RX_STATE(ch, TNETV_CPPI_RX_WORD_HDP), LastRcb->HNext);
+ }
+ else
+ {
+ cppi_log_event0(" [cppi] rcv done");
+
+ pRxCtl->RxActive = 0;
+ }
+ }
+
+ // BEN - add to the list of buffers we need to deal with
+ if (!pRxCtl->RxFakeRcvHead)
+ {
+ pRxCtl->RxFakeRcvHead = SopRcb;
+ pRxCtl->RxFakeRcvTail = SopRcb->Eop;
+ }
+ else
+ {
+ pRxCtl->RxFakeRcvTail = SopRcb->Eop;
+ }
+
+ // make sure we have enough buffers
+ cppi_log_event1(" nextrcb", CurrentRcb->mode);
+
+ if (CurrentRcb)
+ {
+ // continue the loop
+ RxBufStatus = CurrentRcb->mode;
+ }
+
+ } /* while */
+
+ cppi_log_event2("[cppi] fake hd tl", (uint32_t) pRxCtl->RxFakeRcvHead, (uint32_t) pRxCtl->RxFakeRcvTail);
+
+ // sync out all buffers before leaving
+ consistent_sync(pRxCtl->RcbStart, (CPPI_RX_NUM_BUFS * sizeof(cppi_rcb)), DMA_FROM_DEVICE);
+
+ return PacketsServiced;
+}
+
+static void tnetv_cppi_rx_queue_init(struct cppi_info *cppi, int ch, dma_addr_t buf, unsigned length)
+{
+ cppi_rxcntl *pRxCtl = &cppi->rx_ctl[ch];
+ cppi_rcb *rcb, *first_rcb;
+ unsigned int queued_len = 0;
+ int rcblen;
+ int num_frags = 0;
+ dma_addr_t buf_ptr;
+
+ if (length == 0)
+ {
+ cppi_log_event0("[cppi] len = 0, nothing to recv");
+ return;
+ }
+
+ // usb_requests can have a 32 bit length, but CPPI DMA fragments
+ // have a 64k limit. Split the usb_request up into fragments here.
+ first_rcb = pRxCtl->RcbPool;
+ rcb = first_rcb;
+
+ cppi_log_event2("[cppi] Rx queue add: head len", (uint32_t) first_rcb, length);
+
+ while (queued_len < length)
+ {
+ buf_ptr = buf + queued_len;
+ rcb->BufPtr = __dma_to_vlynq_phys(buf_ptr);
+
+ rcb->HNext = 0;
+ rcb->mode = CB_OWNERSHIP_BIT;
+
+ rcblen = ((length - queued_len) > MAX_BUF_SIZE) ? MAX_BUF_SIZE : (length - queued_len);
+ rcb->Off_BLen = rcblen;
+
+ queued_len += rcblen;
+ if (queued_len < length)
+ {
+ rcb->HNext = __dma_to_vlynq_phys(((cppi_rcb *) (rcb->Next))->dma_handle);
+ rcb = rcb->Next;
+ }
+
+ num_frags++;
+ }
+
+ pRxCtl->RcbPool = rcb->Next;
+ rcb->Next = 0;
+
+ cppi_log_event4("[cppi] Adding Rcb (dma) (paddr) (buf)", (uint32_t) rcb, rcb->dma_handle, __dma_to_vlynq_phys(rcb->dma_handle), (uint32_t) rcb->BufPtr);
+ cppi_log_event4("[cppi] Next HNext (len) of (total)", (uint32_t) rcb->Next, rcb->HNext, queued_len, length);
+
+ pRxCtl->RxActQueueCount += num_frags;
+
+ cppi_log_event4("[cppi] rx queued (ptr) (len) (ftcb, ltcb)", (uint32_t) rcb->BufPtr, rcb->Off_BLen, (uint32_t) first_rcb, (uint32_t) rcb);
+ cppi_log_event2(" [cppi] mode num_frags", rcb->mode, num_frags);
+
+ pRxCtl->RxActQueueHead = first_rcb;
+ pRxCtl->RxActQueueTail = rcb;
+
+ cppi_log_event2("[cppi] setting rx (head) (virt)", (uint32_t) first_rcb, __dma_to_vlynq_phys(first_rcb->dma_handle));
+ cppi_log_event4("[cppi] ", ((uint32_t *) first_rcb)[0], ((uint32_t *) first_rcb)[1], ((uint32_t *) first_rcb)[2], ((uint32_t *) first_rcb)[3]);
+
+ // make this into a circular buffer so we never get caught with
+ // no free buffers left
+ rcb->Next = pRxCtl->RxActQueueHead;
+ rcb->HNext = (uint32_t) (__dma_to_vlynq_phys(pRxCtl->RxActQueueHead->dma_handle));
+}
+
+int tnetv_cppi_rx_queue_add(struct cppi_info *cppi, int ch, dma_addr_t buf, unsigned length)
+{
+ (void)buf;
+ (void)length;
+ cppi_rxcntl *pRxCtl = &cppi->rx_ctl[ch];
+ unsigned int cur_bufs;
+
+ cur_bufs = tnetv_usb_reg_read(TNETV_USB_RX_FREE_BUF_CNT(ch));
+
+ if (!pRxCtl->RxActive)
+ {
+ cppi_log_event0("[cppi] queue add - not active");
+
+ pRxCtl->RcbPool = (cppi_rcb *) pRxCtl->RcbStart;
+
+ // add all the buffers to the active (circular) queue
+ tnetv_cppi_rx_queue_init(cppi, ch, (dma_addr_t) __virt_to_phys(dma_recv_buf[ch]), (MAX_BUF_SIZE * pRxCtl->RxNumBuffers));
+
+ /* write Rx Queue Head Descriptor Pointer */
+ tnetv_usb_reg_write(TNETV_DMA_RX_STATE(ch, TNETV_CPPI_RX_WORD_HDP), __dma_to_vlynq_phys(pRxCtl->RxActQueueHead->dma_handle));
+
+ pRxCtl->RxActive = 1;
+
+ // sync out all buffers before starting
+ consistent_sync(pRxCtl->RcbStart, (CPPI_RX_NUM_BUFS * sizeof(cppi_rcb)), DMA_TO_DEVICE);
+
+ // sync out temp rx buffer
+ consistent_sync(dma_recv_buf[ch], CPPI_DMA_RX_BUF_SIZE, DMA_FROM_DEVICE);
+
+ if (cur_bufs < pRxCtl->RxActQueueCount)
+ {
+ // let the hardware know about the buffer(s)
+ tnetv_usb_reg_write(TNETV_USB_RX_FREE_BUF_CNT(ch), pRxCtl->RxActQueueCount - cur_bufs);
+ }
+ }
+
+ cppi_log_event3("[cppi] rx add: (cur_bufs) (avail_bufs) (now)", cur_bufs, pRxCtl->RxActQueueCount, tnetv_usb_reg_read(TNETV_USB_RX_FREE_BUF_CNT(ch)));
+
+ return 0;
+}
+
+int tnetv_cppi_flush_rx_queue(struct cppi_info *cppi, int ch)
+{
+ cppi_rxcntl *pRxCtl = &cppi->rx_ctl[ch];
+ cppi_rcb *rcb;
+ int num_bufs;
+
+ cppi_log_event1("[cppi] flush RX ", (uint32_t) pRxCtl->RxActQueueHead);
+
+ // flush out any pending receives
+ tnetv_cppi_rx_int(cppi, ch);
+
+ // now discard all received data
+ rcb = pRxCtl->RxFakeRcvHead;
+
+ if (rcb)
+ {
+ rcb->Eop = pRxCtl->RxFakeRcvTail;
+
+ // clean up any unreceived RCBs
+ tnetv_cppi_rx_return(cppi, ch, rcb);
+ }
+
+ pRxCtl->RxFakeRcvHead = 0;
+ pRxCtl->RxFakeRcvTail = 0;
+
+ pRxCtl->RxActive = 0;
+
+ // drain the HW free buffer count
+ num_bufs = tnetv_usb_reg_read(TNETV_USB_RX_FREE_BUF_CNT(ch));
+ tnetv_usb_reg_write(TNETV_USB_RX_FREE_BUF_CNT(ch), -num_bufs);
+
+ cppi_log_event2("[cppi] flush RX queue done (freed) act: ", num_bufs, (uint32_t) pRxCtl->RxActQueueCount);
+
+ return 0;
+}
+
+
+/*
+ * This function allocates receive buffer descriptors (internal CPHAL function).
+ * After allocation, the function 'queues' (gives to the hardware) the newly
+ * created receive buffers to enable packet reception.
+ *
+ * @param ch Channel number.
+ *
+ * @return 0 OK, Non-Zero Not OK
+ */
+int tnetv_cppi_init_rcb(struct cppi_info *cppi, int ch)
+{
+ int i, num;
+ cppi_rcb *pRcb;
+ char *AllRcb;
+ int rcbSize;
+ cppi_rxcntl *pRxCtl = &cppi->rx_ctl[ch];
+
+ num = pRxCtl->RxNumBuffers;
+ rcbSize = (sizeof(cppi_rcb) + 0xf) & ~0xf;
+
+ cppi_log_event2("[cppi] init_rcb ch num", ch, num);
+
+ if (pRxCtl->RxNumBuffers == 0)
+ {
+ return -1;
+ }
+
+ /* if the memory has already been allocated, simply reuse it! */
+ AllRcb = pRxCtl->RcbStart;
+
+ // now reinitialize the RCB pool
+ pRxCtl->RcbPool = 0;
+ for (i = (num - 1); i >= 0; i--)
+ {
+ pRcb = (cppi_rcb *)(AllRcb + (i * rcbSize));
+
+ pRcb->dma_handle = pRxCtl->rcb_start_dma_addr + (i * rcbSize);
+
+ pRcb->BufPtr = 0;
+ pRcb->mode = 0;
+ pRcb->HNext = 0;
+ pRcb->Next = (void *) pRxCtl->RcbPool;
+ pRcb->Off_BLen = 0;
+ pRcb->Eop = 0;
+ pRcb->fake_bytes = 0;
+
+ pRxCtl->RcbPool = pRcb;
+ }
+
+ cppi_log_event2(" [cppi]RcbPool (dma)", (uint32_t) pRxCtl->RcbPool, pRxCtl->RcbPool->dma_handle);
+
+ pRxCtl->RxActQueueCount = 0;
+ pRxCtl->RxActQueueHead = 0;
+ pRxCtl->RxActive = 0;
+
+ pRxCtl->RxFakeRcvHead = 0;
+ pRxCtl->RxFakeRcvTail = 0;
+
+ return 0;
+}
+
+static uint8_t ch_buf_cnt[][2] = {
+ {CPPI_RX_NUM_BUFS, 2}, // ch0: bulk out/in
+ {CPPI_RX_NUM_BUFS, 2}, // ch1: bulk out/in
+ {0, 2}, // ch2: interrupt
+ {0, 2} // ch3: interrupt
+};
+
+void tnetv_cppi_init(struct cppi_info *cppi)
+{
+ int ch;
+ uint8_t *alloc_ptr;
+ int ch_mem_size[CPPI_NUM_CHANNELS];
+
+ // wipe cppi memory
+ memset(cppi, 0, sizeof(*cppi));
+
+ // find out how much memory we need to allocate
+ cppi->dma_size = 0;
+ for (ch = 0; ch < CPPI_NUM_CHANNELS; ch++)
+ {
+ ch_mem_size[ch] = (ch_buf_cnt[ch][0] * sizeof(cppi_rcb)) + (ch_buf_cnt[ch][1] * sizeof(cppi_tcb));
+ cppi->dma_size += ch_mem_size[ch];
+ }
+
+ // allocate DMA-able memory
+ if (cppi->dma_size != CPPI_INFO_MEM_SIZE)
+ {
+ panicf("Invalid dma size expected %d got %d", cppi->dma_size, CPPI_INFO_MEM_SIZE);
+ }
+ cppi->dma_handle = (dma_addr_t) __virt_to_phys(cppi->dma_mem);
+
+ memset(cppi->dma_mem, 0, cppi->dma_size);
+
+ cppi_log_event2("[cppi] all CBs sz mem", cppi->dma_size, (uint32_t) cppi->dma_mem);
+
+ // now set up the pointers
+ alloc_ptr = cppi->dma_mem;
+ for (ch = 0; ch < CPPI_NUM_CHANNELS; ch++)
+ {
+ cppi->rx_ctl[ch].RxNumBuffers = ch_buf_cnt[ch][0];
+ cppi->rx_ctl[ch].RcbStart = alloc_ptr;
+ cppi->rx_ctl[ch].rcb_start_dma_addr = (dma_addr_t) __virt_to_phys(alloc_ptr);
+ alloc_ptr += (ch_buf_cnt[ch][0] * sizeof(cppi_rcb));
+
+ cppi->tx_ctl[ch].TxNumBuffers = ch_buf_cnt[ch][1];
+ cppi->tx_ctl[ch].TcbStart = alloc_ptr;
+ cppi->tx_ctl[ch].tcb_start_dma_addr = (dma_addr_t) __virt_to_phys(alloc_ptr);
+ alloc_ptr += (ch_buf_cnt[ch][1] * sizeof(cppi_tcb));
+
+ cppi_log_event3("[cppi] alloc bufs: ch dmarcb dmatcb", ch, cppi->rx_ctl[ch].rcb_start_dma_addr, cppi->tx_ctl[ch].tcb_start_dma_addr);
+
+ // set up receive buffer
+ if (ch_buf_cnt[ch][0])
+ {
+ dma_recv_buf[ch] = (ch == 0) ? ch0_rx_buf : ((ch == 1) ? ch1_rx_buf : 0);
+ cppi_log_event3("[cppi] Alloc fake DMA buf ch", ch, (uint32_t) dma_recv_buf[ch], (uint32_t) __virt_to_phys(dma_recv_buf[ch]));
+ }
+ else
+ {
+ dma_recv_buf[ch] = 0;
+ }
+ }
+
+}
+
+void tnetv_cppi_cleanup(struct cppi_info *cppi)
+{
+ cppi_log_event0("wipe cppi mem");
+
+ // wipe cppi memory
+ memset(cppi, 0, sizeof(*cppi));
+}
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_cppi.h b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_cppi.h
new file mode 100644
index 0000000000..9d0ac37cd0
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_cppi.h
@@ -0,0 +1,144 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: $
+ *
+ * Copyright (C) 2021 by Tomasz Moń
+ * Copied with minor modifications from Sansa Connect Linux driver
+ * Copyright (c) 2005 Zermatt Systems, Inc.
+ * Written by: Ben Bostwick
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef TNETV105_CPPI_H
+#define TNETV105_CPPI_H
+
+#include <stdint.h>
+
+typedef uint32_t dma_addr_t;
+#define USB_CPPI_LOGGING 0
+#define EAGAIN 11 /* Try again */
+#define CPPI_RX_NUM_BUFS 129
+#define CPPI_INFO_MEM_SIZE (2 * CPPI_RX_NUM_BUFS * sizeof(cppi_rcb) + 4 * 2 * sizeof(cppi_tcb))
+
+#define CPPI_NUM_CHANNELS 4
+#define CPPI_MAX_FRAG 0xFE00
+
+struct cppi_info;
+
+typedef struct
+{
+ uint32_t HNext; /*< Hardware's pointer to next buffer descriptor */
+ uint32_t BufPtr; /*< Pointer to the data buffer */
+ uint32_t Off_BLen; /*< Contains buffer offset and buffer length */
+ uint32_t mode; /*< SOP, EOP, Ownership, EOQ, Teardown, Q Starv, Length */
+ void *Next;
+ void *Eop;
+ dma_addr_t dma_handle;
+ uint32_t dummy;
+
+} cppi_tcb;
+
+typedef struct
+{
+ uint32_t HNext; /*< Hardware's pointer to next buffer descriptor */
+ uint32_t BufPtr; /*< Pointer to the data buffer */
+ uint32_t Off_BLen; /*< Contains buffer offset and buffer length */
+ uint32_t mode; /*< SOP, EOP, Ownership, EOQ, Teardown Complete bits */
+ void *Next;
+ void *Eop;
+ dma_addr_t dma_handle;
+ uint32_t fake_bytes;
+
+} cppi_rcb;
+
+typedef struct cppi_txcntl
+{
+ cppi_tcb *TcbPool;
+ cppi_tcb *TxActQueueHead;
+ cppi_tcb *TxActQueueTail;
+ uint32_t TxActQueueCount;
+ uint32_t TxActive;
+ cppi_tcb *LastTcbProcessed;
+ char *TcbStart;
+ dma_addr_t tcb_start_dma_addr;
+ int TxNumBuffers;
+
+#ifdef _CPHAL_STATS
+ uint32_t TxMisQCnt;
+ uint32_t TxEOQCnt;
+ uint32_t TxPacketsServiced;
+ uint32_t TxMaxServiced;
+ uint32_t NumTxInt;
+#endif
+} cppi_txcntl;
+
+
+typedef struct cppi_rxcntl
+{
+ cppi_rcb *RcbPool;
+ cppi_rcb *RxActQueueHead;
+ cppi_rcb *RxActQueueTail;
+ uint32_t RxActQueueCount;
+ uint32_t RxActive;
+ char *RcbStart;
+ dma_addr_t rcb_start_dma_addr;
+ int RxNumBuffers;
+
+ cppi_rcb *RxFakeRcvHead;
+ cppi_rcb *RxFakeRcvTail;
+
+#ifdef _CPHAL_STATS
+ uint32_t RxMisQCnt;
+ uint32_t RxEOQCnt;
+ uint32_t RxMaxServiced;
+ uint32_t RxPacketsServiced;
+ uint32_t NumRxInt;
+#endif
+} cppi_rxcntl;
+
+typedef struct cppi_info
+{
+ struct cppi_txcntl tx_ctl[CPPI_NUM_CHANNELS];
+ struct cppi_rxcntl rx_ctl[CPPI_NUM_CHANNELS];
+
+ uint8_t dma_mem[CPPI_INFO_MEM_SIZE];
+ int dma_size;
+ dma_addr_t dma_handle;
+
+} cppi_info;
+
+#define tnetv_cppi_rx_int_recv_check(cppi, ch) (((cppi)->rx_ctl[(ch)].RxFakeRcvHead) ? 1 : 0)
+
+int tnetv_cppi_init_tcb(struct cppi_info *cppi, int ch);
+int tnetv_cppi_flush_tx_queue(struct cppi_info *cppi, int ch);
+int tnetv_cppi_send(struct cppi_info *cppi, int ch, dma_addr_t buf, unsigned length, int send_zlp);
+int tnetv_cppi_tx_int(struct cppi_info *cppi, int ch);
+void tnetv_cppi_free_tcb(struct cppi_info *cppi, int ch);
+
+int tnetv_cppi_init_rcb(struct cppi_info *cppi, int ch);
+int tnetv_cppi_flush_rx_queue(struct cppi_info *cppi, int ch);
+int tnetv_cppi_rx_return(struct cppi_info *cppi, int ch, cppi_rcb *done_rcb);
+int tnetv_cppi_rx_queue_add(struct cppi_info *cppi, int ch, dma_addr_t buf, unsigned length);
+int tnetv_cppi_rx_int(struct cppi_info *cppi, int ch);
+int tnetv_cppi_rx_int_recv(struct cppi_info *cppi, int ch, int *buf_size, void *buf, int maxpacket);
+void tnetv_cppi_free_rcb(struct cppi_info *cppi, int ch);
+
+void tnetv_cppi_init(struct cppi_info *cppi);
+void tnetv_cppi_cleanup(struct cppi_info *cppi);
+
+void tnetv_cppi_dump_info(struct cppi_info *cppi);
+
+#endif
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c
new file mode 100644
index 0000000000..5563a40814
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.c
@@ -0,0 +1,1521 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: $
+ *
+ * Copyright (C) 2021 by Tomasz Moń
+ * Ported from Sansa Connect TNETV105 UDC Linux driver
+ * Copyright (c) 2005,2006 Zermatt Systems, Inc.
+ * Written by: Ben Bostwick
+ * Linux driver was modeled strongly after the pxa usb driver.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "config.h"
+#include "system.h"
+#include "kernel.h"
+#include "panic.h"
+#include "logf.h"
+#include "usb.h"
+#include "usb_drv.h"
+#include "usb_core.h"
+#include <string.h>
+#include "tnetv105_usb_drv.h"
+#include "tnetv105_cppi.h"
+
+#ifdef SANSA_CONNECT
+#define SDRAM_SIZE 0x04000000
+
+static void set_tnetv_reset(bool high)
+{
+ if (high)
+ {
+ IO_GIO_BITSET0 = (1 << 7);
+ }
+ else
+ {
+ IO_GIO_BITCLR0 = (1 << 7);
+ }
+}
+
+static bool is_tnetv_reset_high(void)
+{
+ return (IO_GIO_BITSET0 & (1 << 7)) ? true : false;
+}
+#endif
+
+static bool setup_is_set_address;
+
+static cppi_info cppi;
+
+static struct ep_runtime_t
+{
+ int max_packet_size;
+ bool in_allocated;
+ bool out_allocated;
+ uint8_t *rx_buf; /* OUT */
+ int rx_remaining;
+ int rx_size;
+ uint8_t *tx_buf; /* IN */
+ int tx_remaining;
+ int tx_size;
+ volatile bool block; /* flag indicating that transfer is blocking */
+ struct semaphore complete; /* semaphore for blocking transfers */
+}
+ep_runtime[USB_NUM_ENDPOINTS];
+
+static const struct
+{
+ int type;
+ int hs_max_packet_size;
+ /* Not sure what xyoff[1] is for. Presumably it is double buffer, but how
+ * the double buffering works is not so clear from the Sansa Connect Linux
+ * kernel patch. As TNETV105 datasheet is not available, the values are
+ * simply taken from the Linux patch as potential constraints are unknown.
+ *
+ * Linux kernel has 9 endpoints:
+ * * 0: ep0
+ * * 1: ep1in-bulk
+ * * 2: ep2out-bulk
+ * * 3: ep3in-int
+ * * 4: ep4in-int
+ * * 5: ep1out-bulk
+ * * 6: ep2in-bulk
+ * * 7: ep3out-int
+ * * 8: ep4out-int
+ */
+ uint16_t xyoff_in[2];
+ uint16_t xyoff_out[2];
+}
+ep_const_data[USB_NUM_ENDPOINTS] =
+{
+ {
+ .type = USB_ENDPOINT_XFER_CONTROL,
+ .hs_max_packet_size = EP0_MAX_PACKET_SIZE,
+ /* Do not set xyoff as it likely does not apply here.
+ * Linux simply hardcodes the offsets when needed.
+ */
+ },
+ {
+ .type = USB_ENDPOINT_XFER_BULK,
+ .hs_max_packet_size = EP1_MAX_PACKET_SIZE,
+ .xyoff_in = {EP1_XBUFFER_ADDRESS, EP1_YBUFFER_ADDRESS},
+ .xyoff_out = {EP5_XBUFFER_ADDRESS, EP5_YBUFFER_ADDRESS},
+ },
+ {
+ .type = USB_ENDPOINT_XFER_BULK,
+ .hs_max_packet_size = EP2_MAX_PACKET_SIZE,
+ .xyoff_in = {EP6_XBUFFER_ADDRESS, EP6_YBUFFER_ADDRESS},
+ .xyoff_out = {EP2_XBUFFER_ADDRESS, EP2_YBUFFER_ADDRESS},
+ },
+ {
+ .type = USB_ENDPOINT_XFER_INT,
+ .hs_max_packet_size = EP3_MAX_PACKET_SIZE,
+ .xyoff_in = {EP3_XBUFFER_ADDRESS, EP3_YBUFFER_ADDRESS},
+ .xyoff_out = {EP7_XBUFFER_ADDRESS, EP7_YBUFFER_ADDRESS},
+ },
+ {
+ .type = USB_ENDPOINT_XFER_INT,
+ .hs_max_packet_size = EP4_MAX_PACKET_SIZE,
+ .xyoff_in = {EP4_XBUFFER_ADDRESS, EP4_YBUFFER_ADDRESS},
+ .xyoff_out = {EP8_XBUFFER_ADDRESS, EP8_YBUFFER_ADDRESS},
+ },
+};
+
+#define VLYNQ_CTL_RESET_MASK 0x0001
+#define VLYNQ_CTL_CLKDIR_MASK 0x8000
+#define VLYNQ_STS_LINK_MASK 0x0001
+
+#define DM320_VLYNQ_CTRL_RESET (1 << 0)
+#define DM320_VLYNQ_CTRL_LOOP (1 << 1)
+#define DM320_VLYNQ_CTRL_ADR_OPT (1 << 2)
+#define DM320_VLYNQ_CTRL_INT_CFG (1 << 7)
+#define DM320_VLYNQ_CTRL_INT_VEC_MASK (0x00001F00)
+#define DM320_VLYNQ_CTRL_INT_EN (1 << 13)
+#define DM320_VLYNQ_CTRL_INT_LOC (1 << 14)
+#define DM320_VLYNQ_CTRL_CLKDIR (1 << 15)
+#define DM320_VLYNQ_CTRL_CLKDIV_MASK (0x00070000)
+#define DM320_VLYNQ_CTRL_PWR_MAN (1 << 31)
+
+#define DM320_VLYNQ_STAT_LINK (1 << 0)
+#define DM320_VLYNQ_STAT_MST_PEND (1 << 1)
+#define DM320_VLYNQ_STAT_SLV_PEND (1 << 2)
+#define DM320_VLYNQ_STAT_F0_NE (1 << 3)
+#define DM320_VLYNQ_STAT_F1_NE (1 << 4)
+#define DM320_VLYNQ_STAT_F2_NE (1 << 5)
+#define DM320_VLYNQ_STAT_F3_NE (1 << 6)
+#define DM320_VLYNQ_STAT_LOC_ERR (1 << 7)
+#define DM320_VLYNQ_STAT_REM_ERR (1 << 8)
+#define DM320_VLYNQ_STAT_FC_OUT (1 << 9)
+#define DM320_VLYNQ_STAT_FC_IN (1 << 10)
+
+#define MAX_PACKET(epn, speed) ((((speed) == USB_SPEED_HIGH) && (((epn) == 1) || ((epn) == 2))) ? USB_HIGH_SPEED_MAXPACKET : USB_FULL_SPEED_MAXPACKET)
+
+#define VLYNQ_INTR_USB20 (1 << 0)
+#define VLYNQ_INTR_CPPI (1 << 1)
+
+static inline void set_vlynq_clock(bool enable)
+{
+ if (enable)
+ {
+ IO_CLK_MOD2 |= (1 << 13);
+ }
+ else
+ {
+ IO_CLK_MOD2 &= ~(1 << 13);
+ }
+}
+
+static inline void set_vlynq_irq(bool enabled)
+{
+ if (enabled)
+ {
+ /* Enable VLYNQ interrupt */
+ IO_INTC_EINT1 |= (1 << 0);
+ }
+ else
+ {
+ IO_INTC_EINT1 &= ~(1 << 0);
+ }
+}
+
+static int tnetv_hw_reset(void)
+{
+ int timeout;
+
+ /* hold down the reset pin on the USB chip */
+ set_tnetv_reset(false);
+
+ /* Turn on VLYNQ clock. */
+ set_vlynq_clock(true);
+
+ /* now reset the VLYNQ module */
+ VL_CTRL |= (VLYNQ_CTL_CLKDIR_MASK | DM320_VLYNQ_CTRL_PWR_MAN);
+ VL_CTRL |= VLYNQ_CTL_RESET_MASK;
+
+ mdelay(10);
+
+ /* pull up the reset pin */
+ set_tnetv_reset(true);
+
+ /* take the VLYNQ out of reset */
+ VL_CTRL &= ~VLYNQ_CTL_RESET_MASK;
+
+ timeout = 0;
+ while (!(VL_STAT & VLYNQ_STS_LINK_MASK) && timeout++ < 50);
+ {
+ mdelay(40);
+ }
+
+ if (!(VL_STAT & VLYNQ_STS_LINK_MASK))
+ {
+ logf("ERROR: VLYNQ not initialized!\n");
+ return -1;
+ }
+
+ /* set up vlynq local map */
+ VL_TXMAP = DM320_VLYNQ_PADDR;
+ VL_RXMAPOF1 = CONFIG_SDRAM_START;
+ VL_RXMAPSZ1 = SDRAM_SIZE;
+
+ /* set up vlynq remote map for tnetv105 */
+ VL_TXMAP_R = 0x00000000;
+ VL_RXMAPOF1_R = 0x0C000000;
+ VL_RXMAPSZ1_R = 0x00030000;
+
+ /* clear TNETV gpio state */
+ tnetv_usb_reg_write(TNETV_V2USB_GPIO_FS, 0);
+
+ /* set USB_CHARGE_EN pin (gpio 1) - output, disable pullup */
+ tnetv_usb_reg_write(TNETV_V2USB_GPIO_DOUT, 0);
+ tnetv_usb_reg_write(TNETV_V2USB_GPIO_DIR, 0xffff);
+
+ return 0;
+}
+
+static int tnetv_xcvr_on(void)
+{
+ return tnetv_hw_reset();
+}
+
+static void tnetv_xcvr_off(void)
+{
+ /* turn off vlynq module clock */
+ set_vlynq_clock(false);
+
+ /* hold down the reset pin on the USB chip */
+ set_tnetv_reset(false);
+}
+
+/* Copy data from the usb data memory. The memory reads should be done 32 bits at a time.
+ * We do not assume that the dst data is aligned.
+ */
+static void tnetv_copy_from_data_mem(void *dst, const volatile uint32_t *sp, int size)
+{
+ uint8_t *dp = (uint8_t *) dst;
+ uint32_t value;
+
+ while (size >= 4)
+ {
+ value = *sp++;
+ dp[0] = value;
+ dp[1] = value >> 8;
+ dp[2] = value >> 16;
+ dp[3] = value >> 24;
+ dp += 4;
+ size -= 4;
+ }
+
+ if (size)
+ {
+ value = sp[0];
+ switch (size)
+ {
+ case 3:
+ dp[2] = value >> 16;
+ case 2:
+ dp[1] = value >> 8;
+ case 1:
+ dp[0] = value;
+ break;
+ }
+ }
+}
+
+/* Copy data into the usb data memory. The memory writes must be done 32 bits at a time.
+ * We do not assume that the src data is aligned.
+*/
+static void tnetv_copy_to_data_mem(volatile uint32_t *dp, const void *src, int size)
+{
+ const uint8_t *sp = (const uint8_t *) src;
+ uint32_t value;
+
+ while (size >= 4)
+ {
+ value = sp[0] | (sp[1] << 8) | (sp[2] << 16) | (sp[3] << 24);
+ *dp++ = value;
+ sp += 4;
+ size -= 4;
+ }
+
+ switch (size)
+ {
+ case 3:
+ value = sp[0] | (sp[1] << 8) | (sp[2] << 16);
+ *dp = value;
+ break;
+ case 2:
+ value = sp[0] | (sp[1] << 8);
+ *dp = value;
+ break;
+ case 1:
+ value = sp[0];
+ *dp = value;
+ break;
+ }
+}
+
+static void tnetv_init_endpoints(void)
+{
+ UsbEp0CtrlType ep0Cfg;
+ UsbEp0ByteCntType ep0Cnt;
+ UsbEpCfgCtrlType epCfg;
+ UsbEpStartAddrType epStartAddr;
+ int ch, wd, epn;
+
+ ep0Cnt.val = 0;
+ ep0Cnt.f.out_ybuf_nak = 1;
+ ep0Cnt.f.out_xbuf_nak = 1;
+ ep0Cnt.f.in_ybuf_nak = 1;
+ ep0Cnt.f.in_xbuf_nak = 1;
+ tnetv_usb_reg_write(TNETV_USB_EP0_CNT, ep0Cnt.val);
+
+ /* Setup endpoint zero */
+ ep0Cfg.val = 0;
+ ep0Cfg.f.buf_size = EP0_BUF_SIZE_64; /* must be 64 bytes for USB 2.0 */
+ ep0Cfg.f.dbl_buf = 0;
+ ep0Cfg.f.in_en = 1;
+ ep0Cfg.f.in_int_en = 1;
+ ep0Cfg.f.out_en = 1;
+ ep0Cfg.f.out_int_en = 1;
+ tnetv_usb_reg_write(TNETV_USB_EP0_CFG, ep0Cfg.val);
+
+ /* disable cell dma */
+ tnetv_usb_reg_write(TNETV_USB_CELL_DMA_EN, 0);
+
+ /* turn off dma engines */
+ tnetv_usb_reg_write(TNETV_USB_TX_CTL, 0);
+ tnetv_usb_reg_write(TNETV_USB_RX_CTL, 0);
+
+ /* clear out DMA registers */
+ for (ch = 0; ch < TNETV_DMA_NUM_CHANNELS; ch++)
+ {
+ for (wd = 0; wd < TNETV_DMA_TX_NUM_WORDS; wd++)
+ {
+ tnetv_usb_reg_write(TNETV_DMA_TX_STATE(ch, wd), 0);
+ }
+
+ for (wd = 0; wd < TNETV_DMA_RX_NUM_WORDS; wd++)
+ {
+ tnetv_usb_reg_write(TNETV_DMA_RX_STATE(ch, wd), 0);
+ }
+
+ /* flush the free buf count */
+ while (tnetv_usb_reg_read(TNETV_USB_RX_FREE_BUF_CNT(ch)) != 0)
+ {
+ tnetv_usb_reg_write(TNETV_USB_RX_FREE_BUF_CNT(ch), 0xFFFF);
+ }
+ }
+
+ for (epn = 1; epn < USB_NUM_ENDPOINTS; epn++)
+ {
+ tnetv_usb_reg_write(TNETV_USB_EPx_ADR(epn),0);
+ tnetv_usb_reg_write(TNETV_USB_EPx_CFG(epn), 0);
+ tnetv_usb_reg_write(TNETV_USB_EPx_IN_CNT(epn), 0x80008000);
+ tnetv_usb_reg_write(TNETV_USB_EPx_OUT_CNT(epn), 0x80008000);
+ }
+
+ /* Setup the other endpoints */
+ for (epn = 1; epn < USB_NUM_ENDPOINTS; epn++)
+ {
+ epCfg.val = tnetv_usb_reg_read(TNETV_USB_EPx_CFG(epn));
+ epStartAddr.val = tnetv_usb_reg_read(TNETV_USB_EPx_ADR(epn));
+
+ /* Linux kernel enables dbl buf for both IN and OUT.
+ * For IN this is problematic when tnetv_cppi_send() is called
+ * to send single ZLP, it will actually send two ZLPs.
+ * Disable the dbl buf here as datasheet is not available and
+ * this results in working mass storage on Windows 10.
+ */
+ epCfg.f.in_dbl_buf = 0;
+ epCfg.f.in_toggle_rst = 1;
+ epCfg.f.in_ack_int = 0;
+ epCfg.f.in_stall = 0;
+ epCfg.f.in_nak_int = 0;
+ epCfg.f.out_dbl_buf = 0;
+ epCfg.f.out_toggle_rst = 1;
+ epCfg.f.out_ack_int = 0;
+ epCfg.f.out_stall = 0;
+ epCfg.f.out_nak_int = 0;
+
+ /* buf_size is specified "in increments of 8 bytes" */
+ epCfg.f.in_buf_size = ep_const_data[epn].hs_max_packet_size >> 3;
+ epCfg.f.out_buf_size = ep_const_data[epn].hs_max_packet_size >> 3;
+
+ epStartAddr.f.xBuffStartAddrIn = ep_const_data[epn].xyoff_in[0] >> 4;
+ epStartAddr.f.yBuffStartAddrIn = ep_const_data[epn].xyoff_in[1] >> 4;
+ epStartAddr.f.xBuffStartAddrOut = ep_const_data[epn].xyoff_out[0] >> 4;
+ epStartAddr.f.yBuffStartAddrOut = ep_const_data[epn].xyoff_out[1] >> 4;
+
+ /* allocate memory for DMA */
+ tnetv_cppi_init_rcb(&cppi, (epn - 1));
+ /* set up DMA queue */
+ tnetv_cppi_init_tcb(&cppi, (epn - 1));
+
+ /* now write out the config to the TNETV (write enable bits last) */
+ tnetv_usb_reg_write(TNETV_USB_EPx_ADR(epn), epStartAddr.val);
+ tnetv_usb_reg_write(TNETV_USB_EPx_CFG(epn), epCfg.val);
+ tnetv_usb_reg_write(TNETV_USB_EPx_IN_CNT(epn), 0x80008000);
+ tnetv_usb_reg_write(TNETV_USB_EPx_OUT_CNT(epn), 0x80008000);
+ }
+
+ /* turn on dma engines */
+ tnetv_usb_reg_write(TNETV_USB_TX_CTL, 1);
+ tnetv_usb_reg_write(TNETV_USB_RX_CTL, 1);
+
+ /* enable cell dma */
+ tnetv_usb_reg_write(TNETV_USB_CELL_DMA_EN, (TNETV_USB_CELL_DMA_EN_RX | TNETV_USB_CELL_DMA_EN_TX));
+}
+
+static void tnetv_udc_enable_interrupts(void)
+{
+ UsbCtrlType usb_ctl;
+ uint8_t tx_int_en, rx_int_en;
+ int ep, chan;
+
+ /* set up the system interrupts */
+ usb_ctl.val = tnetv_usb_reg_read(TNETV_USB_CTRL);
+ usb_ctl.f.vbus_int_en = 1;
+ usb_ctl.f.reset_int_en = 1;
+ usb_ctl.f.suspend_int_en = 1;
+ usb_ctl.f.resume_int_en = 1;
+ usb_ctl.f.ep0_in_int_en = 1;
+ usb_ctl.f.ep0_out_int_en = 1;
+ usb_ctl.f.setup_int_en = 1;
+ usb_ctl.f.setupow_int_en = 1;
+ tnetv_usb_reg_write(TNETV_USB_CTRL, usb_ctl.val);
+
+ /* Enable the DMA endpoint interrupts */
+ tx_int_en = 0;
+ rx_int_en = 0;
+
+ for (ep = 1; ep < USB_NUM_ENDPOINTS; ep++)
+ {
+ chan = ep - 1;
+ rx_int_en |= (1 << chan); /* OUT */
+ tx_int_en |= (1 << chan); /* IN */
+ }
+
+ /* enable rx interrupts */
+ tnetv_usb_reg_write(TNETV_USB_RX_INT_EN, rx_int_en);
+ /* enable tx interrupts */
+ tnetv_usb_reg_write(TNETV_USB_TX_INT_EN, tx_int_en);
+
+ set_vlynq_irq(true);
+}
+
+static void tnetv_udc_disable_interrupts(void)
+{
+ UsbCtrlType usb_ctl;
+
+ /* disable interrupts from linux */
+ set_vlynq_irq(false);
+
+ /* Disable Endpoint Interrupts */
+ tnetv_usb_reg_write(TNETV_USB_RX_INT_DIS, 0x3);
+ tnetv_usb_reg_write(TNETV_USB_TX_INT_DIS, 0x3);
+
+ /* Disable USB system interrupts */
+ usb_ctl.val = tnetv_usb_reg_read(TNETV_USB_CTRL);
+ usb_ctl.f.vbus_int_en = 0;
+ usb_ctl.f.reset_int_en = 0;
+ usb_ctl.f.suspend_int_en = 0;
+ usb_ctl.f.resume_int_en = 0;
+ usb_ctl.f.ep0_in_int_en = 0;
+ usb_ctl.f.ep0_out_int_en = 0;
+ usb_ctl.f.setup_int_en = 0;
+ usb_ctl.f.setupow_int_en = 0;
+ tnetv_usb_reg_write(TNETV_USB_CTRL, usb_ctl.val);
+}
+
+static void tnetv_ep_halt(int epn, bool in)
+{
+ if (in)
+ {
+ tnetv_usb_reg_write(TNETV_USB_EPx_IN_CNT(epn), 0x80008000);
+ }
+ else
+ {
+ tnetv_usb_reg_write(TNETV_USB_EPx_OUT_CNT(epn), 0x80008000);
+ }
+}
+
+/* Reset the TNETV usb2.0 controller and configure it to run in function mode */
+static void tnetv_usb_reset(void)
+{
+ uint32_t timeout = 0;
+ int wd;
+ int ch;
+
+ /* configure function clock */
+ tnetv_usb_reg_write(TNETV_V2USB_CLK_CFG, 0x80);
+
+ /* Reset the USB 2.0 function module */
+ tnetv_usb_reg_write(TNETV_V2USB_RESET, 0x01);
+
+ /* now poll the module ready register until the 2.0 controller finishes resetting */
+ while (!(tnetv_usb_reg_read(TNETV_USB_RESET_CMPL) & 0x1) && (timeout < 1000000))
+ {
+ timeout++;
+ }
+
+ if (!(tnetv_usb_reg_read(TNETV_USB_RESET_CMPL) & 0x1))
+ {
+ logf("tnetv105_udc: VLYNQ USB module reset failed!\n");
+ return;
+ }
+
+ /* turn off external clock */
+ tnetv_usb_reg_write(TNETV_V2USB_CLK_PERF, 0);
+
+ /* clear out USB data memory */
+ for (wd = 0; wd < TNETV_EP_DATA_SIZE; wd += 4)
+ {
+ tnetv_usb_reg_write(TNETV_EP_DATA_ADDR(wd), 0);
+ }
+
+ /* clear out DMA memory */
+ for (ch = 0; ch < TNETV_DMA_NUM_CHANNELS; ch++)
+ {
+ for (wd = 0; wd < TNETV_DMA_TX_NUM_WORDS; wd++)
+ {
+ tnetv_usb_reg_write(TNETV_DMA_TX_STATE(ch, wd), 0);
+ }
+
+ for (wd = 0; wd < TNETV_DMA_RX_NUM_WORDS; wd++)
+ {
+
+ tnetv_usb_reg_write(TNETV_DMA_RX_STATE(ch, wd), 0);
+ }
+ }
+
+ /* point VLYNQ interrupts at the pending register */
+ VL_INTPTR = DM320_VLYNQ_INTPND_PHY;
+
+ /* point VLYNQ remote interrupts at the pending register */
+ VL_INTPTR_R = 0;
+
+ /* clear out interrupt register */
+ VL_INTST |= 0xFFFFFFFF;
+
+ /* enable interrupts on remote device */
+ VL_CTRL_R |= (DM320_VLYNQ_CTRL_INT_EN);
+ VL_INTVEC30_R = 0x8180;
+
+ /* enable VLYNQ interrupts & set interrupts to trigger VLYNQ int */
+ VL_CTRL |= (DM320_VLYNQ_CTRL_INT_LOC | DM320_VLYNQ_CTRL_INT_CFG);
+}
+
+static int tnetv_ep_start_xmit(int epn, void *buf, int size)
+{
+ UsbEp0ByteCntType ep0Cnt;
+
+ if (epn == 0)
+ {
+ /* Write the Control Data packet to the EP0 IN memory area */
+ tnetv_copy_to_data_mem(TNETV_EP_DATA_ADDR(EP0_INPKT_ADDRESS), buf, size);
+
+ /* start xmitting */
+ ep0Cnt.val = tnetv_usb_reg_read(TNETV_USB_EP0_CNT);
+ ep0Cnt.f.in_xbuf_cnt = size;
+ ep0Cnt.f.in_xbuf_nak = 0;
+ tnetv_usb_reg_write(TNETV_USB_EP0_CNT, ep0Cnt.val);
+ }
+ else
+ {
+ dma_addr_t buffer = (dma_addr_t)buf;
+ int send_zlp = 0;
+ if (size == 0)
+ {
+ /* Any address in SDRAM will do, contents do not matter */
+ buffer = CONFIG_SDRAM_START;
+ size = 1;
+ send_zlp = 1;
+ }
+ else
+ {
+ commit_discard_dcache_range(buf, size);
+ }
+ if ((buffer >= CONFIG_SDRAM_START) && (buffer + size < CONFIG_SDRAM_START + SDRAM_SIZE))
+ {
+ if (tnetv_cppi_send(&cppi, (epn - 1), buffer, size, send_zlp))
+ {
+ panicf("tnetv_cppi_send() failed");
+ }
+ }
+ else
+ {
+ panicf("USB xmit buf outside SDRAM %p", buf);
+ }
+ }
+
+ return 0;
+}
+
+static void tnetv_gadget_req_nuke(int epn, bool in)
+{
+ struct ep_runtime_t *ep = &ep_runtime[epn];
+ uint32_t old_rx_int = 0;
+ uint32_t old_tx_int = 0;
+ int ch;
+ int flags;
+
+ /* don't nuke control ep */
+ if (epn == 0)
+ {
+ return;
+ }
+
+ flags = disable_irq_save();
+
+ /* save and disable interrupts before nuking request */
+ old_rx_int = tnetv_usb_reg_read(TNETV_USB_RX_INT_EN);
+ old_tx_int = tnetv_usb_reg_read(TNETV_USB_TX_INT_EN);
+ tnetv_usb_reg_write(TNETV_USB_RX_INT_DIS, 0x3);
+ tnetv_usb_reg_write(TNETV_USB_TX_INT_DIS, 0x3);
+
+ ch = epn - 1;
+
+ if (in)
+ {
+ tnetv_cppi_flush_tx_queue(&cppi, ch);
+
+ tnetv_usb_reg_write(TNETV_USB_EPx_IN_CNT(epn), 0x80008000);
+ if (ep->tx_remaining > 0)
+ {
+ usb_core_transfer_complete(epn, USB_DIR_IN, -1, 0);
+ }
+ ep->tx_buf = NULL;
+ ep->tx_remaining = 0;
+ ep->tx_size = 0;
+
+ if (ep->block)
+ {
+ semaphore_release(&ep->complete);
+ ep->block = false;
+ }
+ }
+ else
+ {
+ tnetv_cppi_flush_rx_queue(&cppi, ch);
+
+ tnetv_usb_reg_write(TNETV_USB_EPx_OUT_CNT(epn), 0x80008000);
+ if (ep->rx_remaining > 0)
+ {
+ usb_core_transfer_complete(epn, USB_DIR_OUT, -1, 0);
+ }
+ ep->rx_buf = NULL;
+ ep->rx_remaining = 0;
+ ep->rx_size = 0;
+ }
+
+ /* reenable any interrupts */
+ tnetv_usb_reg_write(TNETV_USB_RX_INT_EN, old_rx_int);
+ tnetv_usb_reg_write(TNETV_USB_TX_INT_EN, old_tx_int);
+
+ restore_irq(flags);
+}
+
+static int tnetv_gadget_ep_enable(int epn, bool in)
+{
+ UsbEpCfgCtrlType epCfg;
+ int flags;
+ enum usb_device_speed speed;
+
+ if (epn == 0 || epn >= USB_NUM_ENDPOINTS)
+ {
+ return 0;
+ }
+
+ flags = disable_irq_save();
+
+ /* set the maxpacket for this endpoint based on the current speed */
+ speed = usb_drv_port_speed() ? USB_SPEED_HIGH : USB_SPEED_FULL;
+ ep_runtime[epn].max_packet_size = MAX_PACKET(epn, speed);
+
+ /* Enable the endpoint */
+ epCfg.val = tnetv_usb_reg_read(TNETV_USB_EPx_CFG(epn));
+ if (in)
+ {
+ epCfg.f.in_en = 1;
+ epCfg.f.in_stall = 0;
+ epCfg.f.in_toggle_rst = 1;
+ epCfg.f.in_buf_size = ep_runtime[epn].max_packet_size >> 3;
+ tnetv_usb_reg_write(TNETV_USB_EPx_IN_CNT(epn), 0x80008000);
+ }
+ else
+ {
+ epCfg.f.out_en = 1;
+ epCfg.f.out_stall = 0;
+ epCfg.f.out_toggle_rst = 1;
+ epCfg.f.out_buf_size = ep_runtime[epn].max_packet_size >> 3;
+ tnetv_usb_reg_write(TNETV_USB_EPx_OUT_CNT(epn), 0x80008000);
+ }
+ tnetv_usb_reg_write(TNETV_USB_EPx_CFG(epn), epCfg.val);
+
+ restore_irq(flags);
+
+ return 0;
+}
+
+static int tnetv_gadget_ep_disable(int epn, bool in)
+{
+ UsbEpCfgCtrlType epCfg;
+ int flags;
+
+ if (epn == 0 || epn >= USB_NUM_ENDPOINTS)
+ {
+ return 0;
+ }
+
+ flags = disable_irq_save();
+
+ /* Disable the endpoint */
+ epCfg.val = tnetv_usb_reg_read(TNETV_USB_EPx_CFG(epn));
+ if (in)
+ {
+ epCfg.f.in_en = 0;
+ }
+ else
+ {
+ epCfg.f.out_en = 0;
+ }
+ tnetv_usb_reg_write(TNETV_USB_EPx_CFG(epn), epCfg.val);
+
+ /* Turn off the endpoint and unready it */
+ tnetv_ep_halt(epn, in);
+
+ restore_irq(flags);
+
+ /* Clear out all the pending requests */
+ tnetv_gadget_req_nuke(epn, in);
+
+ return 0;
+}
+
+/* TNETV udc goo
+ * Power up and enable the udc. This includes resetting the hardware, turn on the appropriate clocks
+ * and initializing things so that the first setup packet can be received.
+ */
+static void tnetv_udc_enable(void)
+{
+ /* Enable M48XI crystal resonator */
+ IO_CLK_LPCTL1 &= ~(0x01);
+
+ /* Set GIO33 as CLKOUT1B */
+ IO_GIO_FSEL3 |= 0x0003;
+
+ if (tnetv_xcvr_on())
+ return;
+
+ tnetv_usb_reset();
+
+ /* BEN - RNDIS mode is assuming zlps after packets that are multiples of buffer endpoints
+ * zlps are not required by the spec and many controllers don't send them.
+ * set DMA to RNDIS mode (packet concatenation, less interrupts)
+ * tnetv_usb_reg_write(TNETV_USB_RNDIS_MODE, 0xFF);
+ */
+ tnetv_usb_reg_write(TNETV_USB_RNDIS_MODE, 0);
+
+ tnetv_init_endpoints();
+
+ tnetv_udc_enable_interrupts();
+}
+
+static void tnetv_udc_disable(void)
+{
+ tnetv_udc_disable_interrupts();
+
+ tnetv_hw_reset();
+
+ tnetv_xcvr_off();
+
+ /* Set GIO33 as normal output, drive it low */
+ IO_GIO_FSEL3 &= ~(0x0003);
+ IO_GIO_BITCLR2 = (1 << 1);
+
+ /* Disable M48XI crystal resonator */
+ IO_CLK_LPCTL1 |= 0x01;
+}
+
+static void tnetv_udc_handle_reset(void)
+{
+ UsbCtrlType usbCtrl;
+
+ /* disable USB interrupts */
+ tnetv_udc_disable_interrupts();
+
+ usbCtrl.val = tnetv_usb_reg_read(TNETV_USB_CTRL);
+ usbCtrl.f.func_addr = 0;
+ tnetv_usb_reg_write(TNETV_USB_CTRL, usbCtrl.val);
+
+ /* Reset endpoints */
+ tnetv_init_endpoints();
+
+ /* Re-enable interrupts */
+ tnetv_udc_enable_interrupts();
+}
+
+static void ep_write(int epn)
+{
+ struct ep_runtime_t *ep = &ep_runtime[epn];
+ int tx_size;
+ if (epn == 0)
+ {
+ tx_size = MIN(ep->max_packet_size, ep->tx_remaining);
+ }
+ else
+ {
+ /* DMA takes care of splitting the buffer into packets,
+ * but only up to CPPI_MAX_FRAG. After the data is sent
+ * a single interrupt is generated. There appears to be
+ * splitting code in the tnetv_cppi_send() function but
+ * it is somewhat suspicious (it doesn't seem like it
+ * will work with requests larger than 2*CPPI_MAX_FRAG).
+ * Also, if tnetv_cppi_send() does the splitting, we will
+ * get an interrupt after CPPI_MAX_FRAG but before the
+ * full request is sent.
+ *
+ * CPPI_MAX_FRAG is multiple of both 64 and 512 so we
+ * don't have to worry about this split prematurely ending
+ * the transfer.
+ */
+ tx_size = MIN(CPPI_MAX_FRAG, ep->tx_remaining);
+ }
+ tnetv_ep_start_xmit(epn, ep->tx_buf, tx_size);
+ ep->tx_remaining -= tx_size;
+ ep->tx_buf += tx_size;
+}
+
+static void in_interrupt(int epn)
+{
+ struct ep_runtime_t *ep = &ep_runtime[epn];
+
+ if (ep->tx_remaining <= 0)
+ {
+ usb_core_transfer_complete(epn, USB_DIR_IN, 0, ep->tx_size);
+ /* release semaphore for blocking transfer */
+ if (ep->block)
+ {
+ semaphore_release(&ep->complete);
+ ep->tx_buf = NULL;
+ ep->tx_size = 0;
+ ep->tx_remaining = 0;
+ ep->block = false;
+ }
+ }
+ else if (ep->tx_buf)
+ {
+ ep_write(epn);
+ }
+}
+
+static void ep_read(int epn)
+{
+ if (epn == 0)
+ {
+ UsbEp0ByteCntType ep0Cnt;
+ ep0Cnt.val = tnetv_usb_reg_read(TNETV_USB_EP0_CNT);
+ ep0Cnt.f.out_xbuf_nak = 0;
+ tnetv_usb_reg_write(TNETV_USB_EP0_CNT, ep0Cnt.val);
+ }
+ else
+ {
+ struct ep_runtime_t *ep = &ep_runtime[epn];
+ tnetv_cppi_rx_queue_add(&cppi, (epn - 1), 0, ep->rx_remaining);
+ }
+}
+
+static void out_interrupt(int epn)
+{
+ struct ep_runtime_t *ep = &ep_runtime[epn];
+ int is_short;
+ int rcv_len;
+
+ if (epn == 0)
+ {
+ UsbEp0ByteCntType ep0Cnt;
+
+ /* get the length of the received data */
+ ep0Cnt.val = tnetv_usb_reg_read(TNETV_USB_EP0_CNT);
+ rcv_len = ep0Cnt.f.out_xbuf_cnt;
+
+ if (rcv_len > ep->rx_remaining)
+ {
+ rcv_len = ep->rx_remaining;
+ }
+
+ tnetv_copy_from_data_mem(ep->rx_buf, TNETV_EP_DATA_ADDR(EP0_OUTPKT_ADDRESS), rcv_len);
+ ep->rx_buf += rcv_len;
+ ep->rx_remaining -= rcv_len;
+
+ /* See if we are done */
+ is_short = rcv_len && (rcv_len < ep->max_packet_size);
+ if (is_short || (ep->rx_remaining == 0))
+ {
+ usb_core_transfer_complete(epn, USB_DIR_OUT, 0, ep->rx_size - ep->rx_remaining);
+ ep->rx_remaining = 0;
+ ep->rx_size = 0;
+ ep->rx_buf = 0;
+ return;
+ }
+
+ /* make sure nak is cleared only if we expect more data */
+ ep0Cnt.f.out_xbuf_nak = 0;
+ tnetv_usb_reg_write(TNETV_USB_EP0_CNT, ep0Cnt.val);
+ ep_read(epn);
+ }
+ else if (ep->rx_remaining > 0)
+ {
+ int ret, bytes_rcvd;
+
+ /* copy the data from the DMA buffers */
+ bytes_rcvd = ep->rx_remaining;
+ ret = tnetv_cppi_rx_int_recv(&cppi, (epn - 1), &bytes_rcvd, ep->rx_buf, ep->max_packet_size);
+ if (ret == 0 || ret == -EAGAIN)
+ {
+ ep->rx_buf += bytes_rcvd;
+ ep->rx_remaining -= bytes_rcvd;
+ }
+
+ /* complete the request if we got a short packet or an error
+ * make sure we don't complete a request with zero bytes.
+ */
+ if ((ret == 0) && (ep->rx_remaining != ep->rx_size))
+ {
+ usb_core_transfer_complete(epn, USB_DIR_OUT, 0, ep->rx_size - ep->rx_remaining);
+ ep->rx_remaining = 0;
+ ep->rx_size = 0;
+ ep->rx_buf = 0;
+ }
+ }
+}
+
+static bool tnetv_handle_cppi(void)
+{
+ int ret;
+ int ch;
+ uint32_t tx_intstatus;
+ uint32_t rx_intstatus;
+ uint32_t status;
+ int rcv_sched = 0;
+
+ rx_intstatus = tnetv_usb_reg_read(TNETV_USB_RX_INT_STATUS);
+ tx_intstatus = tnetv_usb_reg_read(TNETV_USB_TX_INT_STATUS);
+
+ /* handle any transmit interrupts */
+ status = tx_intstatus;
+ for (ch = 0; ch < CPPI_NUM_CHANNELS && status; ch++)
+ {
+ if (status & 0x1)
+ {
+ ret = tnetv_cppi_tx_int(&cppi, ch);
+ if (ret >= 0)
+ {
+ in_interrupt(ch + 1);
+ }
+ }
+
+ status = status >> 1;
+ }
+
+ rcv_sched = 0;
+ status = rx_intstatus;
+ for (ch = 0; ch < CPPI_NUM_CHANNELS; ch++)
+ {
+ if (status & 0x1 || tnetv_cppi_rx_int_recv_check(&cppi, ch))
+ {
+ ret = tnetv_cppi_rx_int(&cppi, ch);
+ if (ret < 0)
+ {
+ /* only an error if interrupt bit is set */
+ logf("CPPI Rx: failed to ACK int!\n");
+ }
+ else
+ {
+ if (tnetv_cppi_rx_int_recv_check(&cppi, ch))
+ {
+ out_interrupt(ch + 1);
+ }
+ }
+ }
+
+ if (tnetv_cppi_rx_int_recv_check(&cppi, ch))
+ {
+ rcv_sched = 1;
+ }
+
+ status = status >> 1;
+ }
+
+ rx_intstatus = tnetv_usb_reg_read(TNETV_USB_RX_INT_STATUS);
+ tx_intstatus = tnetv_usb_reg_read(TNETV_USB_TX_INT_STATUS);
+
+ if (rx_intstatus || tx_intstatus || rcv_sched)
+ {
+ /* Request calling again after short delay
+ * Needed when for example when OUT endpoint has pending
+ * data but the USB task did not call usb_drv_recv() yet.
+ */
+ return true;
+ }
+ return false;
+}
+
+static int cppi_timeout_cb(struct timeout *tmo)
+{
+ (void)tmo;
+ int flags = disable_irq_save();
+ bool requeue = tnetv_handle_cppi();
+ restore_irq(flags);
+ return requeue ? 1 : 0;
+}
+
+void VLYNQ(void) __attribute__ ((section(".icode")));
+void VLYNQ(void)
+{
+ UsbStatusType sysIntrStatus;
+ UsbStatusType sysIntClear;
+ UsbCtrlType usbCtrl;
+ volatile uint32_t *reg;
+ uint32_t vlynq_intr;
+
+ /* Clear interrupt */
+ IO_INTC_IRQ1 = (1 << 0);
+
+ /* clear out VLYNQ interrupt register */
+ vlynq_intr = VL_INTST;
+
+ if (vlynq_intr & VLYNQ_INTR_USB20)
+ {
+ VL_INTST = VLYNQ_INTR_USB20;
+
+ /* Examine system interrupt status */
+ sysIntrStatus.val = tnetv_usb_reg_read(TNETV_USB_STATUS);
+
+ if (sysIntrStatus.f.reset)
+ {
+ sysIntClear.val = 0;
+ sysIntClear.f.reset = 1;
+ tnetv_usb_reg_write(TNETV_USB_STATUS, sysIntClear.val);
+
+ tnetv_udc_handle_reset();
+ usb_core_bus_reset();
+ }
+
+ if (sysIntrStatus.f.suspend)
+ {
+ sysIntClear.val = 0;
+ sysIntClear.f.suspend = 1;
+ tnetv_usb_reg_write(TNETV_USB_STATUS, sysIntClear.val);
+ }
+
+ if (sysIntrStatus.f.resume)
+ {
+ sysIntClear.val = 0;
+ sysIntClear.f.resume = 1;
+ tnetv_usb_reg_write(TNETV_USB_STATUS, sysIntClear.val);
+ }
+
+ if (sysIntrStatus.f.vbus)
+ {
+ sysIntClear.val = 0;
+ sysIntClear.f.vbus = 1;
+ tnetv_usb_reg_write(TNETV_USB_STATUS, sysIntClear.val);
+
+ if (*((uint32_t *) TNETV_USB_IF_STATUS) & 0x40)
+ {
+ /* write out connect bit */
+ reg = (volatile uint32_t *) TNETV_USB_CTRL;
+ *reg |= 0x80;
+
+ /* write to wakeup bit in clock config */
+ reg = (volatile uint32_t *) TNETV_V2USB_CLK_WKUP;
+ *reg |= TNETV_V2USB_CLK_WKUP_VBUS;
+ }
+ else
+ {
+ /* clear out connect bit */
+ reg = (volatile uint32_t *) TNETV_USB_CTRL;
+ *reg &= ~0x80;
+ }
+ }
+
+ if (sysIntrStatus.f.setup_ow)
+ {
+ sysIntrStatus.f.setup_ow = 0;
+ sysIntClear.val = 0;
+ sysIntClear.f.setup_ow = 1;
+ tnetv_usb_reg_write(TNETV_USB_STATUS, sysIntClear.val);
+ }
+ if (sysIntrStatus.f.setup)
+ {
+ UsbEp0ByteCntType ep0Cnt;
+ static struct usb_ctrlrequest setup;
+
+ sysIntrStatus.f.setup = 0;
+
+ /* Copy setup packet into buffer */
+ tnetv_copy_from_data_mem(&setup, TNETV_EP_DATA_ADDR(EP0_OUTPKT_ADDRESS), sizeof(setup));
+
+ /* Determine next stage of the control message */
+ if (setup.bRequestType & USB_DIR_IN)
+ {
+ /* This is a control-read. Switch directions to send the response.
+ * set the dir bit before clearing the interrupt
+ */
+ usbCtrl.val = tnetv_usb_reg_read(TNETV_USB_CTRL);
+ usbCtrl.f.dir = 1;
+ tnetv_usb_reg_write(TNETV_USB_CTRL, usbCtrl.val);
+ }
+ else
+ {
+ /* This is a control-write. Remain using USB_DIR_OUT to receive the rest of the data.
+ * set the NAK bits according to supplement doc
+ */
+ ep0Cnt.val = 0;
+ ep0Cnt.f.in_xbuf_nak = 1;
+ ep0Cnt.f.out_xbuf_nak = 1;
+ tnetv_usb_reg_write(TNETV_USB_EP0_CNT, ep0Cnt.val);
+
+ /* clear the dir bit before clearing the interrupt */
+ usbCtrl.val = tnetv_usb_reg_read(TNETV_USB_CTRL);
+ usbCtrl.f.dir = 0;
+ tnetv_usb_reg_write(TNETV_USB_CTRL, usbCtrl.val);
+ }
+
+ /* Clear interrupt */
+ sysIntClear.val = 0;
+ sysIntClear.f.setup = 1;
+ tnetv_usb_reg_write(TNETV_USB_STATUS, sysIntClear.val);
+
+ if (((setup.bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) &&
+ (setup.bRequest == USB_REQ_SET_ADDRESS))
+ {
+ /* Rockbox USB core works according to USB specification, i.e.
+ * it first acknowledges the control transfer and then sets
+ * the address. However, Linux TNETV105 driver first sets the
+ * address and then acknowledges the transfer. At first,
+ * it seemed that Linux driver was wrong, but it seems that
+ * TNETV105 simply requires such order. It might be documented
+ * in the datasheet and thus there is no comment in the Linux
+ * driver about this.
+ */
+ setup_is_set_address = true;
+ }
+ else
+ {
+ setup_is_set_address = false;
+ }
+
+ /* Process control packet */
+ usb_core_control_request(&setup);
+ }
+
+ if (sysIntrStatus.f.ep0_in_ack)
+ {
+ sysIntClear.val = 0;
+ sysIntClear.f.ep0_in_ack = 1;
+ tnetv_usb_reg_write(TNETV_USB_STATUS, sysIntClear.val);
+
+ in_interrupt(0);
+ }
+
+ if (sysIntrStatus.f.ep0_out_ack)
+ {
+ sysIntClear.val = 0;
+ sysIntClear.f.ep0_out_ack = 1;
+ tnetv_usb_reg_write(TNETV_USB_STATUS, sysIntClear.val);
+
+ out_interrupt(0);
+ }
+ }
+
+ if (vlynq_intr & VLYNQ_INTR_CPPI)
+ {
+ static struct timeout cppi_timeout;
+
+ VL_INTST = VLYNQ_INTR_CPPI;
+
+ if (tnetv_handle_cppi())
+ {
+ timeout_register(&cppi_timeout, cppi_timeout_cb, 1, 0);
+ }
+ }
+}
+
+void usb_charging_maxcurrent_change(int maxcurrent)
+{
+ uint32_t wreg;
+
+ if (!is_tnetv_reset_high())
+ {
+ /* TNETV105 is in reset, it is not getting more than 100 mA */
+ return;
+ }
+
+ wreg = tnetv_usb_reg_read(TNETV_V2USB_GPIO_DOUT);
+ if (maxcurrent < 500)
+ {
+ /* set tnetv into low power mode */
+ tnetv_usb_reg_write(TNETV_V2USB_GPIO_DOUT, (wreg & ~0x2));
+ }
+ else
+ {
+ /* set tnetv into high power mode */
+ tnetv_usb_reg_write(TNETV_V2USB_GPIO_DOUT, (wreg | 0x2));
+ }
+}
+
+void usb_drv_init(void)
+{
+ int epn;
+ memset(ep_runtime, 0, sizeof(ep_runtime));
+ ep_runtime[0].max_packet_size = EP0_MAX_PACKET_SIZE;
+ ep_runtime[0].in_allocated = true;
+ ep_runtime[0].out_allocated = true;
+ for (epn = 0; epn < USB_NUM_ENDPOINTS; epn++)
+ {
+ semaphore_init(&ep_runtime[epn].complete, 1, 0);
+ }
+ tnetv_cppi_init(&cppi);
+ tnetv_udc_enable();
+}
+
+void usb_drv_exit(void)
+{
+ tnetv_udc_disable();
+ tnetv_cppi_cleanup(&cppi);
+}
+
+void usb_drv_stall(int endpoint, bool stall, bool in)
+{
+ int epn = EP_NUM(endpoint);
+
+ if (epn == 0)
+ {
+ UsbEp0CtrlType ep0Ctrl;
+ ep0Ctrl.val = tnetv_usb_reg_read(TNETV_USB_EP0_CFG);
+ if (in)
+ {
+ ep0Ctrl.f.in_stall = stall ? 1 : 0;
+ }
+ else
+ {
+ ep0Ctrl.f.out_stall = stall ? 1 : 0;
+ }
+ tnetv_usb_reg_write(TNETV_USB_EP0_CFG, ep0Ctrl.val);
+ }
+ else
+ {
+ UsbEpCfgCtrlType epCfg;
+ epCfg.val = tnetv_usb_reg_read(TNETV_USB_EPx_CFG(epn));
+ if (in)
+ {
+ epCfg.f.in_stall = stall ? 1 : 0;
+ }
+ else
+ {
+ epCfg.f.out_stall = stall ? 1 : 0;
+ }
+ tnetv_usb_reg_write(TNETV_USB_EPx_CFG(epn), epCfg.val);
+ }
+}
+
+bool usb_drv_stalled(int endpoint, bool in)
+{
+ int epn = EP_NUM(endpoint);
+ if (epn == 0)
+ {
+ UsbEp0CtrlType ep0Ctrl;
+ ep0Ctrl.val = tnetv_usb_reg_read(TNETV_USB_EP0_CFG);
+ if (in)
+ {
+ return ep0Ctrl.f.in_stall;
+ }
+ else
+ {
+ return ep0Ctrl.f.out_stall;
+ }
+ }
+ else
+ {
+ UsbEpCfgCtrlType epCfg;
+ epCfg.val = tnetv_usb_reg_read(TNETV_USB_EPx_CFG(epn));
+ if (in)
+ {
+ return epCfg.f.in_stall;
+ }
+ else
+ {
+ return epCfg.f.out_stall;
+ }
+ }
+}
+
+static int _usb_drv_send(int endpoint, void *ptr, int length, bool block)
+{
+ int epn = EP_NUM(endpoint);
+ struct ep_runtime_t *ep;
+ int flags;
+
+ ep = &ep_runtime[epn];
+
+ flags = disable_irq_save();
+ ep->tx_buf = ptr;
+ ep->tx_remaining = ep->tx_size = length;
+ ep->block = block;
+ ep_write(epn);
+ restore_irq(flags);
+
+ /* wait for transfer to end */
+ if (block)
+ {
+ semaphore_wait(&ep->complete, TIMEOUT_BLOCK);
+ }
+ return 0;
+}
+
+int usb_drv_send(int endpoint, void* ptr, int length)
+{
+ if ((EP_NUM(endpoint) == 0) && (length == 0))
+ {
+ if (setup_is_set_address)
+ {
+ /* usb_drv_set_address() will call us later */
+ return 0;
+ }
+ /* HACK: Do not wait for status stage ZLP
+ * This seems to be the only way to get through SET ADDRESS
+ * and retain ability to receive SETUP packets.
+ */
+ return _usb_drv_send(endpoint, ptr, length, false);
+ }
+ return _usb_drv_send(endpoint, ptr, length, false);
+}
+
+int usb_drv_send_nonblocking(int endpoint, void* ptr, int length)
+{
+ return _usb_drv_send(endpoint, ptr, length, false);
+}
+
+int usb_drv_recv(int endpoint, void* ptr, int length)
+{
+ int epn = EP_NUM(endpoint);
+ struct ep_runtime_t *ep;
+ int flags;
+
+ ep = &ep_runtime[epn];
+
+ flags = disable_irq_save();
+ ep->rx_buf = ptr;
+ ep->rx_remaining = ep->rx_size = length;
+ ep_read(epn);
+ restore_irq(flags);
+
+ return 0;
+}
+
+void usb_drv_ack(struct usb_ctrlrequest* req);
+
+void usb_drv_set_address(int address)
+{
+ UsbCtrlType usbCtrl;
+ usbCtrl.val = tnetv_usb_reg_read(TNETV_USB_CTRL);
+ usbCtrl.f.func_addr = address;
+ tnetv_usb_reg_write(TNETV_USB_CTRL, usbCtrl.val);
+
+ /* This seems to be the only working order */
+ setup_is_set_address = false;
+ usb_drv_send(EP_CONTROL, NULL, 0);
+ usb_drv_cancel_all_transfers();
+}
+
+/* return port speed FS=0, HS=1 */
+int usb_drv_port_speed(void)
+{
+ UsbCtrlType usbCtrl;
+ usbCtrl.val = tnetv_usb_reg_read(TNETV_USB_CTRL);
+ return usbCtrl.f.speed ? 1 : 0;
+}
+
+void usb_drv_cancel_all_transfers(void)
+{
+ int epn;
+ if (setup_is_set_address)
+ {
+ return;
+ }
+ for (epn = 1; epn < USB_NUM_ENDPOINTS; epn++)
+ {
+ tnetv_gadget_req_nuke(epn, false);
+ tnetv_gadget_req_nuke(epn, true);
+ }
+}
+
+static const uint8_t TestPacket[] =
+{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
+ 0xAA, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
+ 0xEE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xBF, 0xDF,
+ 0xEF, 0xF7, 0xFB, 0xFD, 0xFC, 0x7E, 0xBF, 0xDF,
+ 0xEF, 0xF7, 0xFB, 0xFD, 0x7E
+};
+
+void usb_drv_set_test_mode(int mode)
+{
+ UsbCtrlType usbCtrl;
+ if (mode == 4)
+ {
+ volatile uint32_t *reg;
+ UsbEp0ByteCntType ep0Cnt;
+ UsbEp0CtrlType ep0Cfg;
+ uint8_t *addr;
+ size_t i;
+
+ /* set up the xnak for ep0 */
+ reg = (volatile uint32_t *) TNETV_USB_EP0_CNT;
+ *reg &= ~0xFF;
+
+ /* Setup endpoint zero */
+ ep0Cfg.val = 0;
+ ep0Cfg.f.buf_size = EP0_BUF_SIZE_64; /* must be 64 bytes for USB 2.0 */
+ ep0Cfg.f.dbl_buf = 0;
+ ep0Cfg.f.in_en = 1;
+ ep0Cfg.f.in_int_en = 0;
+ ep0Cfg.f.out_en = 0;
+ ep0Cfg.f.out_int_en = 0;
+ tnetv_usb_reg_write(TNETV_USB_EP0_CFG, ep0Cfg.val);
+
+ addr = (uint8_t *) TNETV_EP_DATA_ADDR(EP0_INPKT_ADDRESS);
+ for (i = 0; i < sizeof(TestPacket); i++)
+ {
+ *addr++ = TestPacket[i];
+ }
+
+ /* start xmitting (only 53 bytes are used) */
+ ep0Cnt.val = 0;
+ ep0Cnt.f.in_xbuf_cnt = 53;
+ ep0Cnt.f.in_xbuf_nak = 0;
+ tnetv_usb_reg_write(TNETV_USB_EP0_CNT, ep0Cnt.val);
+ }
+
+ /* write the config */
+ usbCtrl.val = tnetv_usb_reg_read(TNETV_USB_CTRL);
+ usbCtrl.f.hs_test_mode = mode;
+ usbCtrl.f.dir = 1;
+ tnetv_usb_reg_write(TNETV_USB_CTRL, usbCtrl.val);
+}
+
+int usb_drv_request_endpoint(int type, int dir)
+{
+ int epn;
+ for (epn = 1; epn < USB_NUM_ENDPOINTS; epn++)
+ {
+ if (type == ep_const_data[epn].type)
+ {
+ if ((dir == USB_DIR_IN) && (!ep_runtime[epn].in_allocated))
+ {
+ ep_runtime[epn].in_allocated = true;
+ tnetv_gadget_ep_enable(epn, true);
+ return epn | USB_DIR_IN;
+ }
+ if ((dir == USB_DIR_OUT) && (!ep_runtime[epn].out_allocated))
+ {
+ ep_runtime[epn].out_allocated = true;
+ tnetv_gadget_ep_enable(epn, false);
+ return epn | USB_DIR_OUT;
+ }
+ }
+ }
+ return -1;
+}
+
+void usb_drv_release_endpoint(int ep)
+{
+ int epn = EP_NUM(ep);
+ if (EP_DIR(ep) == DIR_IN)
+ {
+ ep_runtime[epn].in_allocated = false;
+ tnetv_gadget_ep_disable(epn, true);
+ }
+ else
+ {
+ ep_runtime[epn].out_allocated = false;
+ tnetv_gadget_ep_disable(epn, false);
+ }
+}
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.h b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.h
new file mode 100644
index 0000000000..c31c9c6505
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/sansa-connect/tnetv105_usb_drv.h
@@ -0,0 +1,335 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: $
+ *
+ * Copyright (C) 2021 by Tomasz Moń
+ * Ported from Sansa Connect TNETV105 UDC Linux driver
+ * Copyright (c) 2005 Zermatt Systems, Inc.
+ * Written by: Ben Bostwick
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef TNETV105_USB_DRV_H
+#define TNETV105_USB_DRV_H
+
+#include <stdint.h>
+
+#define DM320_AHB_PADDR 0x00060000
+#define DM320_VLYNQ_PADDR 0x70000000
+
+/* TNETV105 Memory Map */
+#define VLYNQ_BASE (0x70000000)
+
+#define TNETV_BASE (VLYNQ_BASE)
+#define TNETV_V2USB_BASE (TNETV_BASE + 0x00000200)
+#define TNETV_WDOG_BASE (TNETV_BASE + 0x00000280)
+#define TNETV_USB_HOST_BASE (TNETV_BASE + 0x00010000)
+#define TNETV_USB_DEVICE_BASE (TNETV_BASE + 0x00020000)
+
+#define TNETV_V2USB_REG(x) (TNETV_V2USB_BASE + (x))
+
+#define TNETV_V2USB_RESET (TNETV_V2USB_REG(0x00))
+#define TNETV_V2USB_CLK_PERF (TNETV_V2USB_REG(0x04))
+#define TNETV_V2USB_CLK_MODE (TNETV_V2USB_REG(0x08))
+#define TNETV_V2USB_CLK_CFG (TNETV_V2USB_REG(0x0C))
+#define TNETV_V2USB_CLK_WKUP (TNETV_V2USB_REG(0x10))
+#define TNETV_V2USB_CLK_PWR (TNETV_V2USB_REG(0x14))
+
+#define TNETV_V2USB_PID_VID (TNETV_V2USB_REG(0x28))
+
+#define TNETV_V2USB_GPIO_DOUT (TNETV_V2USB_REG(0x40))
+#define TNETV_V2USB_GPIO_DIN (TNETV_V2USB_REG(0x44))
+#define TNETV_V2USB_GPIO_DIR (TNETV_V2USB_REG(0x48))
+#define TNETV_V2USB_GPIO_FS (TNETV_V2USB_REG(0x4C))
+#define TNETV_V2USB_GPIO_INTF (TNETV_V2USB_REG(0x50))
+#define TNETV_V2USB_GPIO_EOI (TNETV_V2USB_REG(0x54))
+
+#define TNETV_USB_DEVICE_REG(x) (TNETV_USB_DEVICE_BASE + (x))
+
+#define TNETV_USB_REV (TNETV_USB_DEVICE_REG(0x00))
+#define TNETV_USB_TX_CTL (TNETV_USB_DEVICE_REG(0x04))
+#define TNETV_USB_TX_TEARDOWN (TNETV_USB_DEVICE_REG(0x08))
+#define TNETV_USB_RX_CTL (TNETV_USB_DEVICE_REG(0x14))
+#define TNETV_USB_RX_TEARDOWN (TNETV_USB_DEVICE_REG(0x18))
+#define TNETV_USB_TX_ENDIAN_CTL (TNETV_USB_DEVICE_REG(0x40))
+#define TNETV_USB_RX_ENDIAN_CTL (TNETV_USB_DEVICE_REG(0x44))
+
+#define TNETV_USB_RX_FREE_BUF_CNT(ch) (TNETV_USB_DEVICE_REG(0x140 + ((ch) * 4)))
+
+#define TNETV_USB_TX_INT_STATUS (TNETV_USB_DEVICE_REG(0x170))
+#define TNETV_USB_TX_INT_EN (TNETV_USB_DEVICE_REG(0x178))
+#define TNETV_USB_TX_INT_DIS (TNETV_USB_DEVICE_REG(0x17C))
+#define TNETV_USB_VBUS_INT (TNETV_USB_DEVICE_REG(0x180))
+#define TNETV_USB_VBUS_EOI (TNETV_USB_DEVICE_REG(0x184))
+#define TNETV_USB_RX_INT_STATUS (TNETV_USB_DEVICE_REG(0x190))
+#define TNETV_USB_RX_INT_EN (TNETV_USB_DEVICE_REG(0x198))
+#define TNETV_USB_RX_INT_DIS (TNETV_USB_DEVICE_REG(0x19C))
+
+#define TNETV_USB_RESET_CMPL (TNETV_USB_DEVICE_REG(0x1A0))
+#define TNETV_CPPI_STATE (TNETV_USB_DEVICE_REG(0x1A4))
+
+#define TNETV_USB_STATUS (TNETV_USB_DEVICE_REG(0x200))
+#define TNETV_USB_CTRL (TNETV_USB_DEVICE_REG(0x204))
+#define TNETV_USB_IF_STATUS (TNETV_USB_DEVICE_REG(0x210))
+#define TNETV_USB_IF_ERR (TNETV_USB_DEVICE_REG(0x214))
+#define TNETV_USB_IF_SM (TNETV_USB_DEVICE_REG(0x218))
+
+#define TNETV_USB_EP0_CFG (TNETV_USB_DEVICE_REG(0x220))
+#define TNETV_USB_EP0_CNT (TNETV_USB_DEVICE_REG(0x224))
+
+#define TNETV_USB_EPx_CFG(x) (TNETV_USB_DEVICE_REG(0x220 + (0x10 * (x))))
+#define TNETV_USB_EPx_IN_CNT(x) (TNETV_USB_DEVICE_REG(0x224 + (0x10 * (x))))
+#define TNETV_USB_EPx_OUT_CNT(x) (TNETV_USB_DEVICE_REG(0x228 + (0x10 * (x))))
+#define TNETV_USB_EPx_ADR(x) (TNETV_USB_DEVICE_REG(0x22C + (0x10 * (x))))
+
+/* USB CPPI Config registers (0x300 - 0x30C) */
+#define TNETV_USB_RNDIS_MODE (TNETV_USB_DEVICE_REG(0x300))
+#define TNETV_USB_CELL_DMA_EN (TNETV_USB_DEVICE_REG(0x30C))
+
+#define TNETV_USB_RAW_INT (TNETV_USB_DEVICE_REG(0x310))
+#define TNETV_USB_RAW_EOI (TNETV_USB_DEVICE_REG(0x314))
+
+/* USB DMA setup RAM (0x800 - 0x8FF) */
+#define TNETV_DMA_BASE (TNETV_USB_DEVICE_BASE + 0x800)
+#define TNETV_DMA_TX_STATE(ch, wd) ((uint32_t *) ((TNETV_DMA_BASE) + ((ch) * 0x40) + ((wd) * 4)))
+#define TNETV_DMA_TX_CMPL(ch) ((TNETV_DMA_BASE) + ((ch) * 0x40) + 0x1C)
+
+#define TNETV_CPPI_TX_WORD_HDP 0
+
+#define TNETV_DMA_RX_STATE(ch, wd) ((uint32_t *) ((TNETV_DMA_BASE) + ((ch) * 0x40) + 0x20 + ((wd) * 4)))
+#define TNETV_DMA_RX_CMPL(ch) ((TNETV_DMA_BASE) + ((ch) * 0x40) + 0x3C)
+
+#define TNETV_CPPI_RX_WORD_HDP 1
+
+#define TNETV_DMA_NUM_CHANNELS 3
+
+#define TNETV_DMA_TX_NUM_WORDS 6
+#define TNETV_DMA_RX_NUM_WORDS 7
+
+
+/* USB Buffer RAM (0x1000 - 0x1A00) */
+#define TNETV_EP_DATA_ADDR(x) ((uint32_t *) ((TNETV_USB_DEVICE_BASE) + 0x1000 + (x)))
+
+#define TNETV_EP_DATA_SIZE (0xA00)
+
+#define TNETV_V2USB_RESET_DEV (1 << 0)
+
+#define TNETV_USB_CELL_DMA_EN_RX (1 << 0)
+#define TNETV_USB_CELL_DMA_EN_TX (1 << 1)
+
+#define TNETV_V2USB_CLK_WKUP_VBUS (1 << 12)
+
+#define DM320_VLYNQ_INTPND_PHY ((DM320_AHB_PADDR) + 0x0314)
+
+
+/* macro to convert from a linux pointer to a physical address
+ * to be sent over the VLYNQ bus. The dm320 vlynq rx registers are
+ * set up so the base address is the physical address of RAM
+ */
+#define __dma_to_vlynq_phys(addr) ((((uint32_t) (addr)) - 0x01000000))
+#define __vlynq_phys_to_dma(addr) ((((uint32_t) (addr)) + 0x01000000))
+
+//----------------------------------------------------------------------
+
+#define USB_FULL_SPEED_MAXPACKET 64
+#define USB_HIGH_SPEED_MAXPACKET 512
+
+/* WORD offsets into the data memory */
+#define EP0_MAX_PACKET_SIZE 64 /* Control ep - 64 bytes */
+#define EP1_MAX_PACKET_SIZE 512 /* Bulk ep - 512 bytes */
+#define EP2_MAX_PACKET_SIZE 512 /* Bulk ep - 512 bytes */
+#define EP3_MAX_PACKET_SIZE 64 /* Int ep - 64 bytes */
+#define EP4_MAX_PACKET_SIZE 64 /* Int ep - 64 bytes */
+
+/* BEN TODO: fix this crap */
+#define EP0_OUTPKT_ADDRESS 0
+#define EP0_INPKT_ADDRESS (EP0_MAX_PACKET_SIZE)
+#define EP1_XBUFFER_ADDRESS (EP0_MAX_PACKET_SIZE << 1)
+#define EP1_YBUFFER_ADDRESS (EP1_XBUFFER_ADDRESS + EP1_MAX_PACKET_SIZE)
+#define EP2_XBUFFER_ADDRESS (EP1_XBUFFER_ADDRESS + (EP1_MAX_PACKET_SIZE << 1))
+#define EP2_YBUFFER_ADDRESS (EP2_XBUFFER_ADDRESS + EP2_MAX_PACKET_SIZE)
+#define EP3_XBUFFER_ADDRESS (EP2_XBUFFER_ADDRESS + (EP2_MAX_PACKET_SIZE << 1))
+#define EP3_YBUFFER_ADDRESS (EP3_XBUFFER_ADDRESS + EP3_MAX_PACKET_SIZE)
+#define EP4_XBUFFER_ADDRESS (EP3_XBUFFER_ADDRESS + (EP3_MAX_PACKET_SIZE << 1))
+#define EP4_YBUFFER_ADDRESS (EP4_XBUFFER_ADDRESS + EP4_MAX_PACKET_SIZE)
+#define EP5_XBUFFER_ADDRESS (EP4_XBUFFER_ADDRESS + (EP4_MAX_PACKET_SIZE << 1))
+#define EP5_YBUFFER_ADDRESS (EP5_XBUFFER_ADDRESS + EP1_MAX_PACKET_SIZE)
+#define EP6_XBUFFER_ADDRESS (EP5_XBUFFER_ADDRESS + (EP1_MAX_PACKET_SIZE << 1))
+#define EP6_YBUFFER_ADDRESS (EP6_XBUFFER_ADDRESS + EP2_MAX_PACKET_SIZE)
+#define EP7_XBUFFER_ADDRESS (EP6_XBUFFER_ADDRESS + (EP2_MAX_PACKET_SIZE << 1))
+#define EP7_YBUFFER_ADDRESS (EP7_XBUFFER_ADDRESS + EP3_MAX_PACKET_SIZE)
+#define EP8_XBUFFER_ADDRESS (EP7_XBUFFER_ADDRESS + (EP3_MAX_PACKET_SIZE << 1))
+#define EP8_YBUFFER_ADDRESS (EP8_XBUFFER_ADDRESS + EP4_MAX_PACKET_SIZE)
+
+#define SETUP_PKT_DATA_SIZE 8
+
+#define EP0_BUF_SIZE_8 0
+#define EP0_BUF_SIZE_16 1
+#define EP0_BUF_SIZE_32 2
+#define EP0_BUF_SIZE_64 3
+
+/* USB Status register */
+typedef struct {
+ uint32_t rsvd1 : 5;
+ uint32_t ep0_out_ack : 1;
+ uint32_t rsvd2 : 1;
+ uint32_t ep0_in_ack : 1;
+ uint32_t rsvd3 : 16;
+ uint32_t setup_ow : 1;
+ uint32_t setup : 1;
+ uint32_t vbus : 1;
+ uint32_t resume : 1;
+ uint32_t suspend : 1;
+ uint32_t reset : 1;
+ uint32_t sof : 1;
+ uint32_t any_int : 1;
+} UsbStatusStruct;
+
+typedef union {
+ uint32_t val;
+ UsbStatusStruct f;
+} UsbStatusType;
+
+/* USB Function control register */
+typedef struct {
+ uint32_t dir : 1;
+ uint32_t hs_test_mode : 3;
+ uint32_t rsvd1 : 1;
+ uint32_t wkup_en : 1;
+ uint32_t low_pwr_en : 1;
+ uint32_t connect : 1;
+ uint32_t rsvd2 : 4;
+ uint32_t ep0_in_int_en : 1;
+ uint32_t ep0_out_int_en : 1;
+ uint32_t err_cnt_en : 2;
+ uint32_t func_addr : 7;
+ uint32_t speed : 1;
+ uint32_t setupow_int_en : 1;
+ uint32_t setup_int_en : 1;
+ uint32_t vbus_int_en : 1;
+ uint32_t resume_int_en : 1;
+ uint32_t suspend_int_en : 1;
+ uint32_t reset_int_en : 1;
+ uint32_t sof_int_en : 1;
+ uint32_t rsvd3 : 1;
+} UsbCtrlStruct;
+
+typedef union {
+ uint32_t val;
+ UsbCtrlStruct f;
+} UsbCtrlType;
+
+/* Endpoint 0 Control Register */
+typedef struct {
+ uint32_t buf_size : 2;
+ uint32_t in_int_en : 1;
+ uint32_t in_stall : 1;
+ uint32_t dbl_buf : 1;
+ uint32_t in_toggle : 1;
+ uint32_t in_nak_int_en : 1;
+ uint32_t in_en : 1;
+ uint32_t res3 : 10;
+ uint32_t out_int_en : 1;
+ uint32_t out_stall : 1;
+ uint32_t res4 : 1;
+ uint32_t out_toggle : 1;
+ uint32_t out_nak_int_en : 1;
+ uint32_t out_en : 1;
+ uint32_t res6 : 8;
+} UsbEp0CtrlStruct;
+
+typedef union {
+ uint32_t val;
+ UsbEp0CtrlStruct f;
+} UsbEp0CtrlType;
+
+/* Endpoint 0 current packet size register */
+typedef struct {
+ uint32_t in_xbuf_cnt : 7;
+ uint32_t in_xbuf_nak : 1;
+ uint32_t in_ybuf_cnt : 7;
+ uint32_t in_ybuf_nak : 1;
+ uint32_t out_xbuf_cnt : 7;
+ uint32_t out_xbuf_nak : 1;
+ uint32_t out_ybuf_cnt : 7;
+ uint32_t out_ybuf_nak : 1;
+} UsbEp0ByteCntStruct;
+
+typedef union {
+ uint32_t val;
+ UsbEp0ByteCntStruct f;
+} UsbEp0ByteCntType;
+
+/* Endpoint n Configuration and Control register */
+typedef struct {
+ uint32_t res1 : 1;
+ uint32_t in_toggle_rst : 1;
+ uint32_t in_ack_int : 1;
+ uint32_t in_stall : 1;
+ uint32_t in_dbl_buf : 1;
+ uint32_t in_toggle : 1;
+ uint32_t in_nak_int : 1;
+ uint32_t in_en : 1;
+ uint32_t res2 : 1;
+ uint32_t out_toggle_rst : 1;
+ uint32_t out_ack_int : 1;
+ uint32_t out_stall : 1;
+ uint32_t out_dbl_buf : 1;
+ uint32_t out_toggle : 1;
+ uint32_t out_nak_int : 1;
+ uint32_t out_en : 1;
+ uint32_t in_buf_size : 8;
+ uint32_t out_buf_size : 8;
+} UsbEpCfgCtrlStruct;
+
+typedef union {
+ uint32_t val;
+ UsbEpCfgCtrlStruct f;
+} UsbEpCfgCtrlType;
+
+/* Endpoint n XY Buffer Start Address register */
+typedef struct {
+ uint8_t xBuffStartAddrIn;
+ uint8_t yBuffStartAddrIn;
+ uint8_t xBuffStartAddrOut;
+ uint8_t yBuffStartAddrOut;
+} UsbEpStartAddrStruct;
+
+typedef union {
+ uint32_t val;
+ UsbEpStartAddrStruct f;
+} UsbEpStartAddrType;
+
+/* Endpoint n Packet Control register */
+typedef struct {
+ uint32_t xBufPacketCount : 11;
+ uint32_t res1 : 4;
+ uint32_t xbuf_nak : 1;
+ uint32_t yBufPacketCount : 11;
+ uint32_t res2 : 4;
+ uint32_t ybuf_nak : 1;
+} UsbEpByteCntStruct;
+
+typedef union {
+ uint32_t val;
+ UsbEpByteCntStruct f;
+} UsbEpByteCntType;
+
+#define tnetv_usb_reg_read(x) (*((volatile uint32_t *) (x)))
+#define tnetv_usb_reg_write(x, val) (*((volatile uint32_t *) (x)) = (uint32_t) (val))
+
+
+#endif
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c
index abe6622f0b..986efe374c 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c
@@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
* $Id: $
*
- * Copyright (C) 2011 by Tomasz Moń
+ * Copyright (C) 2011-2021 by Tomasz Moń
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,52 +22,12 @@
#include "config.h"
#include "system.h"
#include "kernel.h"
-#include "usb.h"
-#ifdef HAVE_USBSTACK
-#include "usb_drv.h"
#include "usb_core.h"
-#endif
-
-static bool usb_is_connected = false;
static int usb_detect_callback(struct timeout *tmo)
{
(void)tmo;
-
- if (IO_GIO_BITSET0 & (1 << 9))
- {
- /* Set GIO33 as normal output, drive it low */
- IO_GIO_FSEL3 &= ~(0x0003);
- IO_GIO_BITCLR2 = (1 << 1);
-
- /* Disable M48XI crystal resonator */
- IO_CLK_LPCTL1 |= 0x01;
-
- /* Drive reset low */
- IO_GIO_BITCLR0 = (1 << 7);
-
- /* Disable VLYNQ clock */
- IO_CLK_MOD2 &= ~(1 << 13);
-
- usb_is_connected = false;
- }
- else
- {
- /* Enable M48XI crystal resonator */
- IO_CLK_LPCTL1 &= ~(0x01);
-
- /* Set GIO33 as CLKOUT1B */
- IO_GIO_FSEL3 |= 0x0003;
-
- /* Drive reset high */
- IO_GIO_BITSET0 = (1 << 7);
-
- /* Enable VLYNQ clock */
- IO_CLK_MOD2 |= (1 << 13);
-
- usb_is_connected = true;
- }
-
+ usb_status_event(usb_detect());
return 0;
}
@@ -82,20 +42,15 @@ void GIO9(void)
timeout_register(&usb_oneshot, usb_detect_callback, HZ, 0);
}
-bool usb_drv_connected(void)
-{
- return false;
-}
-
int usb_detect(void)
{
- if (usb_is_connected == true)
+ if (IO_GIO_BITSET0 & (1 << 9))
{
- return USB_INSERTED;
+ return USB_EXTRACTED;
}
else
{
- return USB_EXTRACTED;
+ return USB_INSERTED;
}
}
@@ -127,14 +82,18 @@ void usb_init_device(void)
/* Enable USB insert detection interrupt */
IO_INTC_EINT1 |= (1 << 14);
-
- /* Check if USB is connected */
- usb_detect_callback(NULL);
}
void usb_enable(bool on)
{
- (void)on;
+ if (on)
+ {
+ usb_core_init();
+ }
+ else
+ {
+ usb_core_exit();
+ }
}
void usb_attach(void)
diff --git a/firmware/target/arm/tms320dm320/sdmmc-dm320.c b/firmware/target/arm/tms320dm320/sdmmc-dm320.c
index 8818d645d8..33354a3146 100644
--- a/firmware/target/arm/tms320dm320/sdmmc-dm320.c
+++ b/firmware/target/arm/tms320dm320/sdmmc-dm320.c
@@ -71,6 +71,7 @@
#define BLOCKS_PER_BANK 0x7A7800
/* command flags for send_cmd */
+#define SDHC_RESP_FMT_MASK 0x0600
#define SDHC_RESP_FMT_NONE 0x0000
#define SDHC_RESP_FMT_1 0x0200
#define SDHC_RESP_FMT_2 0x0400
@@ -119,6 +120,7 @@ static struct sd_card_status sd_status[NUM_CARDS] =
/* Shoot for around 75% usage */
static struct mutex sd_mtx SHAREDBSS_ATTR;
+static struct semaphore data_done SHAREDBSS_ATTR;
static volatile unsigned int transfer_error[NUM_DRIVES];
/* align on cache line size */
static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE]
@@ -233,25 +235,20 @@ static int sd_poll_status(int st_reg_num, volatile unsigned int flag)
static int dma_wait_for_completion(void)
{
- unsigned short dma_status;
+ uint16_t dma_status;
- do
- {
- long time = current_tick;
+ semaphore_wait(&data_done, TIMEOUT_BLOCK);
- if (TIME_AFTER(time, next_yield))
- {
- long ty = current_tick;
- yield();
- next_yield = ty + MIN_YIELD_PERIOD;
- }
+ dma_status = IO_MMC_SD_DMA_STATUS1;
+ if (dma_status & MMC_DMASTAT1_TOUTDT)
+ {
+ return -EC_DATA_TIMEOUT;
+ }
- dma_status = IO_MMC_SD_DMA_STATUS1;
- if (dma_status & (1 << 13))
- {
- return -EC_DATA_TIMEOUT;
- }
- } while (dma_status & (1 << 12));
+ if (dma_status & MMC_DMASTAT1_RUNST)
+ {
+ panicf("Semaphore released while DMA still running");
+ }
return EC_OK;
}
@@ -306,16 +303,23 @@ static int sd_command(int cmd, unsigned long arg,
{
/* discard response */
}
- else if ((cmdat & SDHC_RESP_FMT_1) || (cmdat & SDHC_RESP_FMT_3))
- {
- response[0] = (IO_MMC_RESPONSE7 << 16) | IO_MMC_RESPONSE6;
- }
- else if (cmdat & SDHC_RESP_FMT_2)
+ else
{
- response[0] = (IO_MMC_RESPONSE7 << 16) | IO_MMC_RESPONSE6;
- response[1] = (IO_MMC_RESPONSE5 << 16) | IO_MMC_RESPONSE4;
- response[2] = (IO_MMC_RESPONSE3 << 16) | IO_MMC_RESPONSE2;
- response[3] = (IO_MMC_RESPONSE1 << 16) | IO_MMC_RESPONSE0;
+ switch (cmdat & SDHC_RESP_FMT_MASK)
+ {
+ case SDHC_RESP_FMT_1:
+ case SDHC_RESP_FMT_3:
+ response[0] = (IO_MMC_RESPONSE7 << 16) | IO_MMC_RESPONSE6;
+ break;
+ case SDHC_RESP_FMT_2:
+ response[0] = (IO_MMC_RESPONSE7 << 16) | IO_MMC_RESPONSE6;
+ response[1] = (IO_MMC_RESPONSE5 << 16) | IO_MMC_RESPONSE4;
+ response[2] = (IO_MMC_RESPONSE3 << 16) | IO_MMC_RESPONSE2;
+ response[3] = (IO_MMC_RESPONSE1 << 16) | IO_MMC_RESPONSE0;
+ break;
+ default:
+ break;
+ }
}
return 0;
@@ -713,8 +717,6 @@ sd_transfer_retry:
goto sd_transfer_error;
}
- count -= count_per_dma;
-
if (write == false)
{
discard_dcache_range(use_direct_dma ? buffer : aligned_buffer,
@@ -726,9 +728,6 @@ sd_transfer_retry:
}
}
- buffer += count_per_dma*SD_BLOCK_SIZE;
- start_addr += count_per_dma;
-
last_disk_activity = current_tick;
ret = sd_command(SD_STOP_TRANSMISSION, 0, SDHC_RESP_FMT_1, NULL);
@@ -742,6 +741,10 @@ sd_transfer_retry:
{
goto sd_transfer_error;
}
+
+ count -= count_per_dma;
+ buffer += count_per_dma*SD_BLOCK_SIZE;
+ start_addr += count_per_dma;
} while (count > 0);
while (1)
@@ -774,20 +777,10 @@ int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
int sd_write_sectors(IF_MD(int card_no,) unsigned long start, int count,
const void* outbuf)
{
-#ifndef BOOTLOADER
#ifndef HAVE_MULTIDRIVE
const int card_no = 0;
#endif
return sd_transfer_sectors(card_no, start, count, (void*)outbuf, true);
-#else /* we don't need write support in bootloader */
-#ifdef HAVE_MULTIDRIVE
- (void)card_no;
-#endif
- (void)start;
- (void)count;
- (void)outbuf;
- return 0;
-#endif
}
int sd_init(void)
@@ -797,14 +790,13 @@ int sd_init(void)
if (!initialized)
{
mutex_init(&sd_mtx);
+ semaphore_init(&data_done, 1, 0);
initialized = true;
}
mutex_lock(&sd_mtx);
-#ifndef BOOTLOADER
enable_controller(false);
-#endif
/* based on linux/drivers/mmc/dm320mmc.c
Copyright (C) 2006 ZSI, All Rights Reserved.
@@ -815,7 +807,7 @@ int sd_init(void)
/* mmc module clock: 75 Mhz (AHB) / 2 = ~37.5 Mhz
* (Frequencies above are taken from Sansa Connect's OF source code) */
- IO_CLK_DIV3 = (IO_CLK_DIV3 & 0xFF00) | 0x02; /* OF uses 1 */
+ IO_CLK_DIV3 = (IO_CLK_DIV3 & 0xFF00) | 0x01;
bitset16(&IO_CLK_MOD2, CLK_MOD2_MMC);
@@ -852,7 +844,9 @@ int sd_init(void)
#endif
#endif
- sd_select_device(1);
+ /* Enable data done interrupt */
+ IO_MMC_INT_ENABLE |= MMC_IE_EDATDNE;
+ IO_INTC_EINT1 |= INTR_EINT1_MMCSDMS0;
/* Disable Memory Card CLK - it is enabled on demand by TMS320DM320 */
bitclr16(&IO_MMC_MEM_CLK_CONTROL, (1 << 8));
@@ -895,3 +889,17 @@ int sd_event(long id, intptr_t data)
return rc;
}
+
+void SD_MMC(void) __attribute__ ((section(".icode")));
+void SD_MMC(void)
+{
+ uint16_t status = IO_MMC_STATUS0;
+
+ /* Clear interrupt */
+ IO_INTC_IRQ1 = INTR_IRQ1_MMCSDMS0;
+
+ if (status & MMC_ST0_DATDNE)
+ {
+ semaphore_release(&data_done);
+ }
+}
diff --git a/firmware/target/arm/tms320dm320/system-dm320.c b/firmware/target/arm/tms320dm320/system-dm320.c
index 93cf3c51c4..935f3609a6 100644
--- a/firmware/target/arm/tms320dm320/system-dm320.c
+++ b/firmware/target/arm/tms320dm320/system-dm320.c
@@ -494,6 +494,13 @@ void udelay(int usec) {
}
}
+void mdelay(int msec)
+{
+ int ms_per_tick = 1000 / HZ;
+ /* Round up to next full tick */
+ sleep((msec + ms_per_tick - 1) / ms_per_tick);
+}
+
#ifdef BOOTLOADER
void system_prepare_fw_start(void)
{
diff --git a/firmware/target/arm/tms320dm320/system-target.h b/firmware/target/arm/tms320dm320/system-target.h
index 59ae61f8df..1c46e909ed 100644
--- a/firmware/target/arm/tms320dm320/system-target.h
+++ b/firmware/target/arm/tms320dm320/system-target.h
@@ -30,6 +30,7 @@
#define CPUFREQ_MAX 175000000
void udelay(int usec);
+void mdelay(int msec);
#if defined(CREATIVE_ZVx) && defined(BOOTLOADER)
/* hacky.. */
diff --git a/firmware/target/arm/wmcodec-telechips.c b/firmware/target/arm/wmcodec-telechips.c
index 8fb035bdfa..deaced2682 100644
--- a/firmware/target/arm/wmcodec-telechips.c
+++ b/firmware/target/arm/wmcodec-telechips.c
@@ -34,8 +34,6 @@
#if defined(COWON_D2)
/* The D2's audio codec uses an I2C address of 0x34 */
#define I2C_AUDIO_ADDRESS 0x34
-#elif defined (IAUDIO_7) || defined(LOGIK_DAX) || defined(SANSA_M200)
-#define I2C_AUDIO_ADDRESS 0x34
#else
#error wmcodec not implemented for this target!
#endif
diff --git a/firmware/target/hosted/sdl/sim-ui-defines.h b/firmware/target/hosted/sdl/sim-ui-defines.h
index c3ae7c0551..5b4030bd37 100644
--- a/firmware/target/hosted/sdl/sim-ui-defines.h
+++ b/firmware/target/hosted/sdl/sim-ui-defines.h
@@ -203,13 +203,6 @@
#define UI_LCD_POSX 42 /* x position of lcd */
#define UI_LCD_POSY 35 /* y position of lcd */
-#elif defined(IRIVER_IFP7XX)
-#define UI_TITLE "iriver iFP7xx"
-#define UI_WIDTH 425 /* width of GUI window */
-#define UI_HEIGHT 183 /* height of GUI window */
-#define UI_LCD_POSX 115 /* x position of lcd */
-#define UI_LCD_POSY 54 /* y position of lcd */
-
#elif defined(MROBE_100)
#define UI_TITLE "Olympus M:Robe 100"
#define UI_WIDTH 247 /* width of GUI window */
@@ -226,13 +219,6 @@
#define UI_LCD_POSX 58 /* x position of lcd */
#define UI_LCD_POSY 67 /* y position of lcd */
-#elif defined(IAUDIO_7)
-#define UI_TITLE "iAudio7"
-#define UI_WIDTH 494 /* width of GUI window */
-#define UI_HEIGHT 214 /* height of GUI window */
-#define UI_LCD_POSX 131 /* x position of lcd */
-#define UI_LCD_POSY 38 /* y position of lcd */
-
#elif defined(CREATIVE_ZVM) || defined(CREATIVE_ZVM60GB)
#ifdef CREATIVE_ZVM
#define UI_TITLE "Creative Zen Vision:M 30GB"
diff --git a/firmware/target/mips/ingenic_jz47xx/app.lds b/firmware/target/mips/ingenic_jz47xx/app.lds
index bec8671ec9..89deb63f89 100644
--- a/firmware/target/mips/ingenic_jz47xx/app.lds
+++ b/firmware/target/mips/ingenic_jz47xx/app.lds
@@ -66,7 +66,7 @@ SECTIONS
KEEP(*(.vectors.4));
KEEP(*(.vectors));
- *(.icode);
+ *(.icode*);
*(.irodata);
*(.idata);
KEEP(*(.vectors))
@@ -111,6 +111,7 @@ SECTIONS
/DISCARD/ :
{
+ *(.MIPS.abiflags);
*(.eh_frame);
*(.rel.dyn);
}
diff --git a/firmware/target/mips/ingenic_jz47xx/boot.lds b/firmware/target/mips/ingenic_jz47xx/boot.lds
index 9492050695..b5a3f51c01 100644
--- a/firmware/target/mips/ingenic_jz47xx/boot.lds
+++ b/firmware/target/mips/ingenic_jz47xx/boot.lds
@@ -58,7 +58,7 @@ SECTIONS
KEEP(*(.vectors.4));
KEEP(*(.vectors));
- *(.icode);
+ *(.icode*);
*(.irodata);
*(.idata);
KEEP(*(.vectors*))
@@ -91,4 +91,11 @@ SECTIONS
. += 0x400;
irqstackend = .;
} > IRAM
+
+ /DISCARD/ :
+ {
+ *(.MIPS.abiflags);
+ *(.eh_frame);
+ *(.rel.dyn);
+ }
}
diff --git a/firmware/target/mips/ingenic_x1000/aic-x1000.c b/firmware/target/mips/ingenic_x1000/aic-x1000.c
index a0e509d3b6..1d1768d4f9 100644
--- a/firmware/target/mips/ingenic_x1000/aic-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/aic-x1000.c
@@ -31,12 +31,12 @@
* is complete if this value is less than "cnt", and may be incomplete if it
* is equal to "cnt". (Note the leading zero term is not written to "buf".)
*/
-static unsigned cf_derive(unsigned m, unsigned n, unsigned* buf, unsigned cnt)
+static uint32_t cf_derive(uint32_t m, uint32_t n, uint32_t* buf, uint32_t cnt)
{
- unsigned wrote = 0;
- unsigned a = m / n;
+ uint32_t wrote = 0;
+ uint32_t a = m / n;
while(cnt--) {
- unsigned tmp = n;
+ uint32_t tmp = n;
n = m - n * a;
if(n == 0)
break;
@@ -54,16 +54,16 @@ static unsigned cf_derive(unsigned m, unsigned n, unsigned* buf, unsigned cnt)
* calculate the rational number m/n which it represents. Returns m and n.
* If count is zero, then m and n are undefined.
*/
-static void cf_expand(const unsigned* buf, unsigned count,
- unsigned* m, unsigned* n)
+static void cf_expand(const uint32_t* buf, uint32_t count,
+ uint32_t* m, uint32_t* n)
{
if(count == 0)
return;
- unsigned i = count - 1;
- unsigned mx = 1, nx = buf[i];
+ uint32_t i = count - 1;
+ uint32_t mx = 1, nx = buf[i];
while(i--) {
- unsigned tmp = nx;
+ uint32_t tmp = nx;
nx = mx + buf[i] * nx;
mx = tmp;
}
@@ -72,48 +72,102 @@ static void cf_expand(const unsigned* buf, unsigned count,
*n = nx;
}
-int aic_i2s_set_mclk(x1000_clk_t clksrc, unsigned fs, unsigned mult)
+static int calc_i2s_clock_params(x1000_clk_t clksrc,
+ uint32_t fs, uint32_t mult,
+ uint32_t* div_m, uint32_t* div_n,
+ uint32_t* i2sdiv)
{
- /* get the input clock rate */
- uint32_t src_freq = clk_get(clksrc);
+ if(clksrc == X1000_CLK_EXCLK) {
+ /* EXCLK mode bypasses the CPM clock so it's more limited */
+ *div_m = 0;
+ *div_n = 0;
+ *i2sdiv = X1000_EXCLK_FREQ / 64 / fs;
+
+ /* clamp to maximum value */
+ if(*i2sdiv > 0x200)
+ *i2sdiv = 0x200;
+
+ return 0;
+ }
- /* reject invalid parameters */
+ /* ensure a valid clock was selected */
+ if(clksrc != X1000_CLK_SCLK_A &&
+ clksrc != X1000_CLK_MPLL)
+ return -1;
+
+ /* ensure bit clock constraint is respected */
if(mult % 64 != 0)
return -1;
- if(clksrc == X1000_EXCLK_FREQ) {
- if(mult != 0)
- return -1;
+ /* ensure master clock frequency is not too high */
+ if(fs > UINT32_MAX/mult)
+ return -1;
+
+ /* get frequencies */
+ uint32_t tgt_freq = fs * mult;
+ uint32_t src_freq = clk_get(clksrc);
+
+ /* calculate best rational approximation fitting hardware constraints */
+ uint32_t m = 0, n = 0;
+ uint32_t buf[16];
+ uint32_t cnt = cf_derive(tgt_freq, src_freq, &buf[0], 16);
+ do {
+ cf_expand(&buf[0], cnt, &m, &n);
+ cnt -= 1;
+ } while(cnt > 0 && (m > 512 || n > 8192) && (n >= 2*m));
- jz_writef(AIC_I2SCR, STPBK(1));
+ /* unrepresentable */
+ if(cnt == 0 || n == 0 || m == 0)
+ return -1;
+
+ *div_m = m;
+ *div_n = n;
+ *i2sdiv = mult / 64;
+ return 0;
+}
+
+uint32_t aic_calc_i2s_clock(x1000_clk_t clksrc, uint32_t fs, uint32_t mult)
+{
+ uint32_t m, n, i2sdiv;
+ if(calc_i2s_clock_params(clksrc, fs, mult, &m, &n, &i2sdiv))
+ return 0;
+
+ unsigned long long rate = clk_get(clksrc);
+ rate *= m;
+ rate /= n * i2sdiv; /* this multiply can't overflow. */
+
+ /* clamp */
+ if(rate > 0xffffffffull)
+ rate = 0xffffffff;
+
+ return rate;
+}
+
+int aic_set_i2s_clock(x1000_clk_t clksrc, uint32_t fs, uint32_t mult)
+{
+ uint32_t m, n, i2sdiv;
+ if(calc_i2s_clock_params(clksrc, fs, mult, &m, &n, &i2sdiv))
+ return -1;
+
+ /* turn off bit clock */
+ bool bitclock_en = !jz_readf(AIC_I2SCR, STPBK);
+ jz_writef(AIC_I2SCR, STPBK(1));
+
+ /* handle master clock */
+ if(clksrc == X1000_CLK_EXCLK) {
jz_writef(CPM_I2SCDR, CS(0), CE(0));
- REG_AIC_I2SDIV = X1000_EXCLK_FREQ / 64 / fs;
} else {
- if(mult == 0)
- return -1;
- if(fs*mult > src_freq)
- return -1;
-
- /* calculate best rational approximation that fits our constraints */
- unsigned m = 0, n = 0;
- unsigned buf[16];
- unsigned cnt = cf_derive(fs*mult, src_freq, &buf[0], 16);
- do {
- cf_expand(&buf[0], cnt, &m, &n);
- cnt -= 1;
- } while(cnt > 0 && (m > 512 || n > 8192) && (n >= 2*m));
-
- /* wrong values */
- if(cnt == 0 || n == 0 || m == 0)
- return -1;
-
- jz_writef(AIC_I2SCR, STPBK(1));
jz_writef(CPM_I2SCDR, PCS(clksrc == X1000_CLK_MPLL ? 1 : 0),
CS(1), CE(1), DIV_M(m), DIV_N(n));
jz_write(CPM_I2SCDR1, REG_CPM_I2SCDR1);
- REG_AIC_I2SDIV = (mult / 64) - 1;
}
- jz_writef(AIC_I2SCR, STPBK(0));
+ /* set bit clock divider */
+ REG_AIC_I2SDIV = i2sdiv - 1;
+
+ /* re-enable the bit clock */
+ if(bitclock_en)
+ jz_writef(AIC_I2SCR, STPBK(0));
+
return 0;
}
diff --git a/firmware/target/mips/ingenic_x1000/aic-x1000.h b/firmware/target/mips/ingenic_x1000/aic-x1000.h
index eda0f80f04..f272655b9c 100644
--- a/firmware/target/mips/ingenic_x1000/aic-x1000.h
+++ b/firmware/target/mips/ingenic_x1000/aic-x1000.h
@@ -23,24 +23,122 @@
#define __AIC_X1000_H__
#include "clk-x1000.h"
+#include "x1000/aic.h"
#include <stdbool.h>
+#include <stdint.h>
-/* Set frequency of I2S master clock supplied by AIC. Has no use if an
- * external DAC is supplying the master clock. Must be called with the
- * bit clock disabled.
- *
- * - clksrc can be one of EXCLK, SCLK_A, MPLL.
- * - This function does not modify PLL settings. It's the caller's job
- * to ensure the PLL is configured and runing.
- * - fs is the audio sampling frequency (8 KHz - 192 KHz)
- * - mult is multiplied by fs to get the master clock rate.
- * - mult must be a multiple of 64 due to AIC bit clock requirements.
- * - Note: EXCLK bypasses the decimal divider so it is not very flexible.
- * If using EXCLK you must set mult=0. If EXCLK is not a multiple of
- * the bit clock (= 64*fs), then the clock rate will be inaccurate.
- *
- * Returns zero on success and nonzero if the frequency is not achievable.
+#define AIC_I2S_MASTER_MODE 0
+#define AIC_I2S_MASTER_EXCLK_MODE 1
+#define AIC_I2S_SLAVE_MODE 2
+
+#define AIC_I2S_LEFT_CHANNEL_FIRST 0
+#define AIC_I2S_RIGHT_CHANNEL_FIRST 1
+
+/* Nb. the functions below are intended to serve as "documentation" and make
+ * target audiohw code clearer, they should normally be called with immediate
+ * constant arguments so they are inlined to a register read-modify-write. */
+
+/* Enable/disable some kind of big-endian mode. Presumably it refers to
+ * the endianness of the samples read or written to the FIFO. */
+static inline void aic_set_big_endian_format(bool en)
+{
+ jz_writef(AIC_CFG, MSB(en ? 1 : 0));
+}
+
+/* Set whether to send the last sample (true) or a zero sample (false)
+ * if the AIC FIFO underflows during playback. */
+static inline void aic_set_play_last_sample(bool en)
+{
+ jz_writef(AIC_CFG, LSMP(en ? 1 : 0));
+}
+
+/* Select the use of the internal or external codec. */
+static inline void aic_set_external_codec(bool en)
+{
+ jz_writef(AIC_CFG, ICDC(en ? 0 : 1));
+}
+
+/* Set I2S interface mode */
+static inline void aic_set_i2s_mode(int mode)
+{
+ switch(mode) {
+ default:
+ case AIC_I2S_MASTER_MODE:
+ jz_writef(AIC_CFG, BCKD(1), SYNCD(1));
+ break;
+
+ case AIC_I2S_MASTER_EXCLK_MODE:
+ jz_writef(AIC_CFG, BCKD(0), SYNCD(1));
+ break;
+
+ case AIC_I2S_SLAVE_MODE:
+ jz_writef(AIC_CFG, BCKD(0), SYNCD(0));
+ break;
+ }
+}
+
+/* Select the channel ordering on the I2S interface (playback only). */
+static inline void aic_set_i2s_channel_order(int order)
+{
+ switch(order) {
+ default:
+ case AIC_I2S_LEFT_CHANNEL_FIRST:
+ jz_writef(AIC_I2SCR, RFIRST(0));
+ break;
+
+ case AIC_I2S_RIGHT_CHANNEL_FIRST:
+ jz_writef(AIC_I2SCR, RFIRST(1));
+ break;
+ }
+}
+
+/* Enable/disable the I2S master clock (also called 'system clock') */
+static inline void aic_enable_i2s_master_clock(bool en)
+{
+ jz_writef(AIC_I2SCR, ESCLK(en ? 1 : 0));
+}
+
+/* Enable/disable the I2S bit clock */
+static inline void aic_enable_i2s_bit_clock(bool en)
+{
+ jz_writef(AIC_I2SCR, STPBK(en ? 0 : 1));
+}
+
+/* Select whether I2S mode is used (false) or MSB-justified mode (true). */
+static inline void aic_set_msb_justified_mode(bool en)
+{
+ jz_writef(AIC_I2SCR, AMSL(en ? 1 : 0));
+}
+
+/* Calculate frequency of I2S clocks.
+ *
+ * - 'clksrc' can be one of EXCLK, SCLK_A, or MPLL.
+ * - 'fs' is the audio sampling frequency in Hz, must be 8 KHz - 192 KHz.
+ * - The master clock frequency equals 'mult * fs' Hz. Due to hardware
+ * restrictions, 'mult' must be divisible by 64.
+ *
+ * - NOTE: When using EXCLK source, the master clock equals EXCLK and the
+ * 'mult' parameter is ignored.
+ *
+ * This function returns the actual bit clock rate which would be achieved.
+ * (Note the bit clock is always 64x the effective sampling rate.)
+ *
+ * If the exact rate cannot be attained, then this will return the closest
+ * possible rate to the desired rate. In case of invalid parameters, this
+ * function will return zero. That also occurs if the chosen PLL is stopped.
+ */
+extern uint32_t aic_calc_i2s_clock(x1000_clk_t clksrc,
+ uint32_t fs, uint32_t mult);
+
+/* Set the I2S clock frequency.
+ *
+ * Parameters are the same as 'aic_calc_i2s_clock()' except this function
+ * will set the clocks. If the bit clock is running, it will be automatically
+ * stopped and restarted properly.
+ *
+ * Returns zero on success. If an invalid state occurs (due to bad settings)
+ * then this function will do nothing and return a nonzero value.
*/
-extern int aic_i2s_set_mclk(x1000_clk_t clksrc, unsigned fs, unsigned mult);
+extern int aic_set_i2s_clock(x1000_clk_t clksrc, uint32_t fs, uint32_t mult);
#endif /* __AIC_X1000_H__ */
diff --git a/firmware/target/mips/ingenic_x1000/app.lds b/firmware/target/mips/ingenic_x1000/app.lds
index 0f6352b8ee..26b2854728 100644
--- a/firmware/target/mips/ingenic_x1000/app.lds
+++ b/firmware/target/mips/ingenic_x1000/app.lds
@@ -1,30 +1,21 @@
#include "config.h"
+#include "cpu.h"
OUTPUT_FORMAT("elf32-littlemips")
OUTPUT_ARCH(MIPS)
ENTRY(_start)
STARTUP(target/mips/ingenic_x1000/crt0.o)
-/* Stub area is used for loading new firmware via RoLo */
-#define STUBSIZE 0x4000
-#define SDRAM_ORIG 0x80000000
-
-/* IRAM contains stub, DRAM contains main app */
-#define IRAMORIG SDRAM_ORIG
-#define IRAMSIZE STUBSIZE
-#define DRAMORIG (SDRAM_ORIG + STUBSIZE)
-#define DRAMSIZE (MEMORYSIZE * 0x100000 - STUBSIZE)
-
/* End of the audio buffer, where the codec buffer starts */
-#define ENDAUDIOADDR (DRAMORIG + DRAMSIZE - PLUGIN_BUFFER_SIZE - CODEC_SIZE)
+#define ENDAUDIOADDR (X1000_DRAM_END - PLUGIN_BUFFER_SIZE - CODEC_SIZE)
/* Where the codec buffer ends, and the plugin buffer starts */
#define ENDCODECADDR (ENDAUDIOADDR + CODEC_SIZE)
MEMORY
{
- IRAM : ORIGIN = IRAMORIG, LENGTH = IRAMSIZE
- DRAM : ORIGIN = DRAMORIG, LENGTH = DRAMSIZE
+ IRAM : ORIGIN = X1000_IRAM_BASE, LENGTH = X1000_IRAM_SIZE
+ DRAM : ORIGIN = X1000_DRAM_BASE, LENGTH = X1000_DRAM_SIZE
}
SECTIONS
@@ -50,7 +41,7 @@ SECTIONS
*(.sdata*);
} > DRAM
- .iram IRAMORIG: AT (_bssbegin)
+ .iram X1000_IRAM_BASE: AT (_bssbegin)
{
_iramstart = .;
. = 0x000; /* TLB refill */
@@ -63,7 +54,7 @@ SECTIONS
KEEP(*(.vectors.4));
KEEP(*(.vectors));
- *(.icode);
+ *(.icode*);
*(.irodata);
*(.idata);
_iramend = .;
@@ -75,10 +66,10 @@ SECTIONS
{
*(.stack);
stackbegin = .;
- . += 0x1E00;
+ . += X1000_STACKSIZE;
stackend = .;
_irqstackbegin = .;
- . += 0x300;
+ . += X1000_IRQSTACKSIZE;
_irqstackend = .;
} > IRAM
@@ -93,26 +84,21 @@ SECTIONS
_end = .;
} > DRAM
-#ifdef BOOTLOADER
- . = ALIGN(4);
- loadbuffer = .;
- . += 0x100000 * 4; /* Allow 4 MiB for the rockbox binary */
- loadbufferend = .;
-#else
-
.audiobuf :
{
- . = ALIGN(4); /* XXX might need more alignment here */
+ . = ALIGN(4);
audiobuffer = .;
+ loadbuffer = .;
} > DRAM
+ loadbufferend = ENDAUDIOADDR;
audiobufend = ENDAUDIOADDR;
codecbuf = ENDAUDIOADDR;
pluginbuf = ENDCODECADDR;
-#endif
/DISCARD/ :
{
+ *(.MIPS.abiflags);
*(.eh_frame);
*(.rel.dyn);
}
diff --git a/firmware/target/mips/ingenic_x1000/boot.lds b/firmware/target/mips/ingenic_x1000/boot.lds
index 81468a95fc..c274d69aab 100644
--- a/firmware/target/mips/ingenic_x1000/boot.lds
+++ b/firmware/target/mips/ingenic_x1000/boot.lds
@@ -1,5 +1 @@
-#ifdef BOOTLOADER_SPL
-# include "spl.lds"
-#else
-# include "app.lds"
-#endif
+#include "app.lds"
diff --git a/firmware/target/mips/ingenic_x1000/clk-x1000.c b/firmware/target/mips/ingenic_x1000/clk-x1000.c
index 390d9722ac..6cc18fb113 100644
--- a/firmware/target/mips/ingenic_x1000/clk-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/clk-x1000.c
@@ -25,99 +25,129 @@
#include "x1000/msc.h"
#include "x1000/aic.h"
-static uint32_t pll_get(uint32_t pllreg, uint32_t onbit)
+struct clk_info {
+ uint8_t mux_reg; /* offset from CPM_BASE for mux register */
+ uint8_t mux_shift; /* shift to get mux */
+ uint8_t mux_mask; /* mask to get mux after shifting */
+ uint8_t mux_type; /* type of mux, maps register bits to clock source */
+ uint8_t div_reg; /* offset from CPM_BASE for divider register */
+ uint8_t div_shift; /* shift to get divider */
+ uint8_t div_mask; /* mask to get divider after shifting */
+ uint8_t miscbits; /* inclk shift, clkgr bit, and fake mux value */
+};
+
+/* Ugliness to pack/unpack stuff in clk_info->miscbits */
+#define INCLK_SHIFT(n) ((n) & 1)
+#define CLKGR_BIT(n) (((n) & 0x1f) << 1)
+#define FAKEMUX(n) (((n) & 3) << 6)
+#define GET_INCLK_SHIFT(miscbits) ((miscbits) & 1)
+#define GET_CLKGR_BIT(miscbits) (((miscbits) >> 1) & 0x1f)
+#define GET_FAKEMUX(miscbits) (((miscbits) >> 6) & 3)
+
+/* Clock sources -- the order here is important! */
+#define S_STOP 0
+#define S_EXCLK 1
+#define S_APLL 2
+#define S_MPLL 3
+#define S_SCLK_A 4
+
+/* Muxes */
+#define MUX_TWOBIT 0
+#define MUX_ONEBIT 1
+#define MUX_USB 2
+#define MUX_PHONY 3
+#define MUX_NUM_TYPES 4
+
+/* Ugliness to define muxes */
+#define MKSEL(x,i) (((x) & 0xf) << ((i)*4))
+#define GETSEL(x,i) (((x) >> ((i)*4)) & 0xf)
+#define STOP(i) MKSEL(S_STOP, i)
+#define EXCLK(i) MKSEL(S_EXCLK, i)
+#define APLL(i) MKSEL(S_APLL, i)
+#define MPLL(i) MKSEL(S_MPLL, i)
+#define SCLK_A(i) MKSEL(S_SCLK_A, i)
+#define MKMUX(a,b,c,d) (a(0)|b(1)|c(2)|d(3))
+
+/* Ugliness to shorten the clk_info table */
+#define JA(x) (JA_CPM_##x & 0xff)
+#define BM(x) ((BM_CPM_##x) >> (BP_CPM_##x))
+#define BP(x) (BP_CPM_##x)
+#define CG(x) CLKGR_BIT(BP_CPM_CLKGR_##x)
+#define M(r,f,t) JA(r), BP(r##_##f), BM(r##_##f), t
+#define D(r,f) JA(r), BP(r##_##f), BM(r##_##f)
+
+static const uint16_t clk_mux[MUX_NUM_TYPES] = {
+ /* 00 01 10 11 */
+ MKMUX(STOP, SCLK_A, MPLL, STOP), /* MUX_TWOBIT */
+ MKMUX(SCLK_A, MPLL, STOP, STOP), /* MUX_ONEBIT */
+ MKMUX(EXCLK, EXCLK, SCLK_A, MPLL), /* MUX_USB */
+ MKMUX(EXCLK, APLL, MPLL, SCLK_A), /* MUX_PHONY */
+};
+
+/* Keep in order with enum x1000_clk_t */
+const struct clk_info clk_info[X1000_NUM_SIMPLE_CLKS] = {
+ {0, 0, 0, MUX_PHONY, 0, 0, 0, CG(CPU_BIT)|FAKEMUX(0)},
+ {0, 0, 0, MUX_PHONY, 0, 0, 0, CG(CPU_BIT)|FAKEMUX(1)},
+ {0, 0, 0, MUX_PHONY, 0, 0, 0, CG(CPU_BIT)|FAKEMUX(2)},
+ {0, 0, 0, MUX_PHONY, 0, 0, 0, CG(CPU_BIT)|FAKEMUX(3)},
+ {M(CCR, SEL_CPLL, MUX_TWOBIT), D(CCR, CDIV), CG(CPU_BIT)},
+ {M(CCR, SEL_CPLL, MUX_TWOBIT), D(CCR, L2DIV), CG(CPU_BIT)},
+ {M(CCR, SEL_H0PLL, MUX_TWOBIT), D(CCR, H0DIV), CG(AHB0)},
+ {M(CCR, SEL_H2PLL, MUX_TWOBIT), D(CCR, H2DIV), CG(APB0)},
+ {M(CCR, SEL_H2PLL, MUX_TWOBIT), D(CCR, PDIV), CG(APB0)},
+ {M(DDRCDR, CLKSRC, MUX_TWOBIT), D(DDRCDR, CLKDIV), CG(DDR)},
+ {M(LPCDR, CLKSRC, MUX_ONEBIT), D(LPCDR, CLKDIV), CG(LCD)},
+ {M(MSC0CDR, CLKSRC, MUX_ONEBIT), D(MSC0CDR, CLKDIV), CG(MSC0)|INCLK_SHIFT(1)},
+ {M(MSC0CDR, CLKSRC, MUX_ONEBIT), D(MSC1CDR, CLKDIV), CG(MSC1)|INCLK_SHIFT(1)},
+ {M(SSICDR, SFC_CS, MUX_ONEBIT), D(SSICDR, CLKDIV), CG(SFC)},
+ {M(USBCDR, CLKSRC, MUX_USB), D(USBCDR, CLKDIV), CG(OTG)},
+};
+
+static uint32_t clk_get_in_rate(uint8_t mux_type, uint32_t mux)
{
- if((pllreg & (1 << onbit)) == 0)
- return 0;
-
- /* Both PLL registers share the same layout of N/M/OD bits.
- * The max multiplier is 128 and max EXCLK is 26 MHz, so the
- * multiplication should fit within 32 bits without overflow.
- */
- uint32_t rate = X1000_EXCLK_FREQ;
- rate *= jz_vreadf(pllreg, CPM_APCR, PLLM) + 1;
- rate /= jz_vreadf(pllreg, CPM_APCR, PLLN) + 1;
- rate >>= jz_vreadf(pllreg, CPM_APCR, PLLOD);
- return rate;
-}
-
-static uint32_t sclk_a_get(void)
-{
- switch(jz_readf(CPM_CCR, SEL_SRC)) {
- case 1: return X1000_EXCLK_FREQ;
- case 2: return clk_get(X1000_CLK_APLL);
- default: return 0;
+ uint32_t reg, onbit;
+ uint32_t src = GETSEL(clk_mux[mux_type], mux);
+ again:
+ switch(src) {
+ default: return 0;
+ case S_EXCLK: return X1000_EXCLK_FREQ;
+ case S_APLL: reg = REG_CPM_APCR; onbit = BM_CPM_APCR_ON; break;
+ case S_MPLL: reg = REG_CPM_MPCR; onbit = BM_CPM_MPCR_ON; break;
+ case S_SCLK_A: src = jz_readf(CPM_CCR, SEL_SRC); goto again;
}
-}
-
-static uint32_t ccr_get(uint32_t selbit, uint32_t divbit)
-{
- uint32_t reg = REG_CPM_CCR;
- uint32_t sel = (reg >> selbit) & 0x3;
- uint32_t div = (reg >> divbit) & 0xf;
-
- switch(sel) {
- case 1: return clk_get(X1000_CLK_SCLK_A) / (div + 1);
- case 2: return clk_get(X1000_CLK_MPLL) / (div + 1);
- default: return 0;
- }
-}
-
-static uint32_t ddr_get(void)
-{
- uint32_t reg = REG_CPM_DDRCDR;
- uint32_t div = jz_vreadf(reg, CPM_DDRCDR, CLKDIV);
-
- switch(jz_vreadf(reg, CPM_DDRCDR, CLKSRC)) {
- case 1: return clk_get(X1000_CLK_SCLK_A) / (div + 1);
- case 2: return clk_get(X1000_CLK_MPLL) / (div + 1);
- default: return 0;
- }
-}
-static uint32_t lcd_get(void)
-{
- if(jz_readf(CPM_CLKGR, LCD))
+ if(!(reg & onbit))
return 0;
- uint32_t reg = REG_CPM_LPCDR;
- uint32_t rate;
- switch(jz_vreadf(reg, CPM_LPCDR, CLKSRC)) {
- case 0: rate = clk_get(X1000_CLK_SCLK_A); break;
- case 1: rate = clk_get(X1000_CLK_MPLL); break;
- default: return 0;
- }
-
- rate /= jz_vreadf(reg, CPM_LPCDR, CLKDIV) + 1;
+ uint32_t rate = X1000_EXCLK_FREQ;
+ rate *= jz_vreadf(reg, CPM_APCR, PLLM) + 1;
+ rate /= jz_vreadf(reg, CPM_APCR, PLLN) + 1;
+ rate >>= jz_vreadf(reg, CPM_APCR, PLLOD);
return rate;
}
-static uint32_t msc_get(int msc)
+static uint32_t clk_get_simple(const struct clk_info* info)
{
- if((msc == 0 && jz_readf(CPM_CLKGR, MSC0)) ||
- (msc == 1 && jz_readf(CPM_CLKGR, MSC1)))
+ if(REG_CPM_CLKGR & (1 << GET_CLKGR_BIT(info->miscbits)))
return 0;
- uint32_t reg = REG_CPM_MSC0CDR;
- uint32_t rate;
- switch(jz_vreadf(reg, CPM_MSC0CDR, CLKSRC)) {
- case 0: rate = clk_get(X1000_CLK_SCLK_A); break;
- case 1: rate = clk_get(X1000_CLK_MPLL); break;
- default: return 0;
- }
+ uint32_t base = 0xb0000000;
+ uint32_t mux_reg = *(const volatile uint32_t*)(base + info->mux_reg);
+ uint32_t div_reg = *(const volatile uint32_t*)(base + info->div_reg);
- uint32_t div;
- if(msc == 0)
- div = jz_readf(CPM_MSC0CDR, CLKDIV);
- else
- div = jz_readf(CPM_MSC1CDR, CLKDIV);
+ uint32_t mux = (mux_reg >> info->mux_shift) & info->mux_mask;
+ uint32_t div = (div_reg >> info->div_shift) & info->div_mask;
- rate /= 2 * (div + 1);
- rate >>= REG_MSC_CLKRT(msc);
+ mux |= GET_FAKEMUX(info->miscbits);
+
+ uint32_t rate = clk_get_in_rate(info->mux_type, mux);
+ rate >>= GET_INCLK_SHIFT(info->miscbits);
+ rate /= (div + 1);
return rate;
}
-static uint32_t i2s_mclk_get(void)
+#ifndef BOOTLOADER
+static uint32_t clk_get_i2s_mclk(void)
{
if(jz_readf(CPM_CLKGR, AIC))
return 0;
@@ -143,48 +173,29 @@ static uint32_t i2s_mclk_get(void)
return rate;
}
-static uint32_t i2s_bclk_get(void)
+static uint32_t clk_get_i2s_bclk(void)
{
- return i2s_mclk_get() / (REG_AIC_I2SDIV + 1);
+ return clk_get_i2s_mclk() / (REG_AIC_I2SDIV + 1);
}
-static uint32_t sfc_get(void)
+static uint32_t clk_get_decimal(x1000_clk_t clk)
{
- if(jz_readf(CPM_CLKGR, SFC))
- return 0;
-
- uint32_t reg = REG_CPM_SSICDR;
- uint32_t rate;
- if(jz_vreadf(reg, CPM_SSICDR, SFC_CS) == 0)
- rate = clk_get(X1000_CLK_SCLK_A);
- else
- rate = clk_get(X1000_CLK_MPLL);
-
- rate /= jz_vreadf(reg, CPM_SSICDR, CLKDIV) + 1;
- return rate;
+ switch(clk) {
+ case X1000_CLK_I2S_MCLK: return clk_get_i2s_mclk();
+ case X1000_CLK_I2S_BCLK: return clk_get_i2s_bclk();
+ default: return 0;
+ }
}
+#endif
uint32_t clk_get(x1000_clk_t clk)
{
- switch(clk) {
- case X1000_CLK_EXCLK: return X1000_EXCLK_FREQ;
- case X1000_CLK_APLL: return pll_get(REG_CPM_APCR, BP_CPM_APCR_ON);
- case X1000_CLK_MPLL: return pll_get(REG_CPM_MPCR, BP_CPM_MPCR_ON);
- case X1000_CLK_SCLK_A: return sclk_a_get();
- case X1000_CLK_CPU: return ccr_get(BP_CPM_CCR_SEL_CPLL, BP_CPM_CCR_CDIV);
- case X1000_CLK_L2CACHE: return ccr_get(BP_CPM_CCR_SEL_CPLL, BP_CPM_CCR_L2DIV);
- case X1000_CLK_AHB0: return ccr_get(BP_CPM_CCR_SEL_H0PLL, BP_CPM_CCR_H0DIV);
- case X1000_CLK_AHB2: return ccr_get(BP_CPM_CCR_SEL_H2PLL, BP_CPM_CCR_H2DIV);
- case X1000_CLK_PCLK: return ccr_get(BP_CPM_CCR_SEL_H2PLL, BP_CPM_CCR_PDIV);
- case X1000_CLK_DDR: return ddr_get();
- case X1000_CLK_LCD: return lcd_get();
- case X1000_CLK_MSC0: return msc_get(0);
- case X1000_CLK_MSC1: return msc_get(1);
- case X1000_CLK_I2S_MCLK: return i2s_mclk_get();
- case X1000_CLK_I2S_BCLK: return i2s_bclk_get();
- case X1000_CLK_SFC: return sfc_get();
- default: return 0;
- }
+#ifndef BOOTLOADER
+ if(clk >= X1000_NUM_SIMPLE_CLKS)
+ return clk_get_decimal(clk);
+#endif
+
+ return clk_get_simple(&clk_info[clk]);
}
const char* clk_get_name(x1000_clk_t clk)
@@ -204,9 +215,10 @@ const char* clk_get_name(x1000_clk_t clk)
CASE(LCD);
CASE(MSC0);
CASE(MSC1);
+ CASE(SFC);
+ CASE(USB);
CASE(I2S_MCLK);
CASE(I2S_BCLK);
- CASE(SFC);
#undef CASE
default:
return "NONE";
diff --git a/firmware/target/mips/ingenic_x1000/clk-x1000.h b/firmware/target/mips/ingenic_x1000/clk-x1000.h
index 76413b90d2..2ff602db9f 100644
--- a/firmware/target/mips/ingenic_x1000/clk-x1000.h
+++ b/firmware/target/mips/ingenic_x1000/clk-x1000.h
@@ -45,9 +45,11 @@ typedef enum x1000_clk_t {
X1000_CLK_LCD,
X1000_CLK_MSC0,
X1000_CLK_MSC1,
- X1000_CLK_I2S_MCLK,
- X1000_CLK_I2S_BCLK,
X1000_CLK_SFC,
+ X1000_CLK_USB,
+ X1000_NUM_SIMPLE_CLKS,
+ X1000_CLK_I2S_MCLK = X1000_NUM_SIMPLE_CLKS,
+ X1000_CLK_I2S_BCLK,
X1000_CLK_COUNT,
} x1000_clk_t;
diff --git a/firmware/target/mips/ingenic_x1000/crt0.S b/firmware/target/mips/ingenic_x1000/crt0.S
index b717f96692..b36500b462 100644
--- a/firmware/target/mips/ingenic_x1000/crt0.S
+++ b/firmware/target/mips/ingenic_x1000/crt0.S
@@ -34,33 +34,6 @@
.section .init.text
_start:
- /* Clear data watchpoint */
- mtc0 zero, C0_WATCHLO
- mtc0 zero, C0_WATCHHI
-
- /* Set BEV, ERL, mask interrupts */
- li v0, 0x40fc04
- mtc0 v0, C0_Status
-
- /* Set Cause_IV to 1 (use special interrupt vector) */
- li v0, M_CauseIV
- mtc0 v0, C0_Cause
-
- /* Set CPU_MODE and BUS_MODE to 1 in CPM_OPCR (Ingenic does this) */
- lui v0, 0xb000
- lw v1, 0x24(v0)
- ori v1, v1, 0x22
- sw v1, 0x24(v0)
-
- /* Enable kseg0 cacheability */
- li v0, 3
- mtc0 v0, C0_Config
- nop
-
- /* According to ingenic: "enable idx-store-data cache insn" */
- li v0, 0x20000000
- mtc0 v0, C0_ErrCtl
-
/* Cache init */
li v0, 0x80000000
ori v1, v0, 0x4000
@@ -80,7 +53,6 @@ _cache_loop:
mtc0 v0, C0_Config, 7
nop
-#ifndef BOOTLOADER_SPL
/* Copy IRAM from BSS to low memory. */
la t0, _iramcopy
la t1, _iramstart
@@ -91,7 +63,6 @@ _iram_loop:
addiu t0, 4
bne t1, t2, _iram_loop
sw t3, -4(t1)
-#endif
/* Clear the BSS segment (needed to zero-initialize C static values) */
la t0, _bssbegin
@@ -103,7 +74,6 @@ _bss_loop:
sw zero, -4(t0)
_bss_done:
-#ifndef BOOTLOADER_SPL
/* Set stack pointer and clear the stack */
la sp, stackend
la t0, stackbegin
@@ -120,13 +90,11 @@ _irqstack_loop:
addiu t0, 4
bne t0, k0, _irqstack_loop
sw t1, -4(t0)
-#endif
/* Jump to C code */
j main
nop
-#ifndef BOOTLOADER_SPL
/* Exception entry points */
.section .vectors.1, "ax", %progbits
j tlb_refill_handler
@@ -260,6 +228,5 @@ _exception_return:
lw sp, 0x80(sp)
eret
nop
-#endif
.set pop
diff --git a/firmware/target/mips/ingenic_x1000/debug-x1000.c b/firmware/target/mips/ingenic_x1000/debug-x1000.c
index 74bbcd77a6..fe469b1a72 100644
--- a/firmware/target/mips/ingenic_x1000/debug-x1000.c
+++ b/firmware/target/mips/ingenic_x1000/debug-x1000.c
@@ -148,7 +148,9 @@ static bool dbg_cpuidle(void)
#ifdef FIIO_M3K
extern bool dbg_fiiom3k_touchpad(void);
-extern bool axp173_debug_menu(void);
+#endif
+#ifdef HAVE_AXP_PMU
+extern bool axp_debug_menu(void);
#endif
/* Menu definition */
@@ -164,7 +166,9 @@ static const struct {
{"Audio", &dbg_audio},
#ifdef FIIO_M3K
{"Touchpad", &dbg_fiiom3k_touchpad},
- {"Power stats", &axp173_debug_menu},
+#endif
+#ifdef HAVE_AXP_PMU
+ {"Power stats", &axp_debug_menu},
#endif
};
diff --git a/firmware/target/mips/ingenic_x1000/dma-x1000.h b/firmware/target/mips/ingenic_x1000/dma-x1000.h
index d836a0cf54..8bb5f1ddaa 100644
--- a/firmware/target/mips/ingenic_x1000/dma-x1000.h
+++ b/firmware/target/mips/ingenic_x1000/dma-x1000.h
@@ -43,8 +43,9 @@
* cannot be used safely.
*/
#define DMA_CHANNEL_AUDIO 0
-#define DMA_CHANNEL_FBCOPY 1
-#define DMA_NUM_USED_CHANNELS 2
+#define DMA_CHANNEL_RECORD 1
+#define DMA_CHANNEL_FBCOPY 2
+#define DMA_NUM_USED_CHANNELS 3
struct dma_desc {
uint32_t cm; /* meaning and layout same as DMA_CHN_CM */
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
index 2f43809523..8528b803f7 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/audiohw-fiiom3k.c
@@ -22,30 +22,36 @@
#include "audiohw.h"
#include "system.h"
#include "pcm_sampr.h"
-#include "logf.h"
#include "aic-x1000.h"
#include "i2c-x1000.h"
#include "gpio-x1000.h"
-#include "x1000/aic.h"
-#include "x1000/cpm.h"
+#include "logf.h"
-void audiohw_init(void)
+static int cur_fsel = HW_FREQ_48;
+static int cur_power_mode = 0;
+
+static void set_ak_freqmode(void)
{
- /* Configure AIC for I2S operation */
- jz_writef(CPM_CLKGR, AIC(0));
- gpio_config(GPIO_B, 0x1f, GPIO_DEVICE(1));
- jz_writef(AIC_I2SCR, STPBK(1));
+ int freq = hw_freq_sampr[cur_fsel];
+ int mult = freq >= SAMPR_176 ? 128 : 256;
- /* Operate as I2S master, use external codec */
- jz_writef(AIC_CFG, AUSEL(1), ICDC(0), BCKD(1), SYNCD(1), LSMP(1));
- jz_writef(AIC_I2SCR, ESCLK(1), AMSL(0));
+ aic_enable_i2s_bit_clock(false);
+ aic_set_i2s_clock(X1000_CLK_SCLK_A, freq, mult);
+ ak4376_set_freqmode(cur_fsel, mult, cur_power_mode);
+ aic_enable_i2s_bit_clock(true);
+}
- /* Stereo audio, packed 16 bit samples */
- jz_writef(AIC_CCR, PACK16(1), CHANNEL(1), OSS(1));
+void audiohw_init(void)
+{
+ /* Configure AIC */
+ aic_set_external_codec(true);
+ aic_set_i2s_mode(AIC_I2S_MASTER_MODE);
+ aic_enable_i2s_master_clock(true);
/* Initialize DAC */
i2c_x1000_set_freq(AK4376_BUS, I2C_FREQ_400K);
- ak4376_init();
+ ak4376_open();
+ set_ak_freqmode();
}
void audiohw_postinit(void)
@@ -57,25 +63,29 @@ void audiohw_close(void)
ak4376_close();
}
-void ak4376_set_pdn_pin(int level)
+void audiohw_set_volume(int vol_l, int vol_r)
{
- gpio_config(GPIO_A, 1 << 16, GPIO_OUTPUT(level ? 1 : 0));
+ ak4376_set_volume(vol_l, vol_r);
}
-int ak4376_set_mclk_freq(int hw_freq, bool enabled)
+void audiohw_set_filter_roll_off(int val)
{
- /* Get the multiplier */
- int freq = hw_freq_sampr[hw_freq];
- int mult = freq >= SAMPR_176 ? 128 : 256;
+ ak4376_set_filter_roll_off(val);
+}
- if(enabled) {
- /* Set the new frequency; clock is enabled afterward */
- if(aic_i2s_set_mclk(X1000_CLK_SCLK_A, freq, mult))
- logf("WARNING: unachievable audio rate %d x %d!?", freq, mult);
- } else {
- /* Shut off the clock */
- jz_writef(AIC_I2SCR, STPBK(1));
- }
+void audiohw_set_frequency(int fsel)
+{
+ cur_fsel = fsel;
+ set_ak_freqmode();
+}
- return mult;
+void audiohw_set_power_mode(int mode)
+{
+ cur_power_mode = mode;
+ set_ak_freqmode();
+}
+
+void ak4376_set_pdn_pin(int level)
+{
+ gpio_set_level(GPIO_AK4