summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2021-07-02 12:02:26 +0200
committerTomasz Moń <desowin@gmail.com>2021-07-04 07:41:44 +0000
commite11fa5f74eb49b10ebefbe8882bb50186dffb2a4 (patch)
tree295a28ca58bc4d7b5153629046c1e2894db02f5e /firmware/target
parentc9f2308a1d4401ceefaac47b1ea851530d07e47d (diff)
Sansa Connect: Initial libertas WiFi driver port
Import non-free firmware image from linux-firmware package. Firmware loading works but is disabled at compile time because just loading firmware without configuring device results in higher power consumption without any benefit to end user. Change-Id: I8fd252c49385ede1ea4e0f9b1e29adeb331ab8ae
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c10
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h2
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/wifi-sansaconnect.c130
-rw-r--r--firmware/target/arm/tms320dm320/system-dm320.c2
4 files changed, 142 insertions, 2 deletions
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
index 12058eba03..a4efe0962a 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
@@ -75,7 +75,7 @@
#define CMD_WHEEL_EN 0xD0
#define CMD_SET_INTCHRG 0xD1
#define CMD_GET_INTCHRG 0xD2
-#define CMD_UNKNOWN_D3 0xD3
+#define CMD_WIFI_PD 0xD3
#define CMD_UNKNOWN_D4 0xD4
#define CMD_UNKNOWN_D5 0xD5
#define CMD_UNKNOWN_D6 0xD6
@@ -315,7 +315,7 @@ static size_t avr_command_data_size(uint8_t opcode)
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_WIFI_PD: return 1;
case CMD_UNKNOWN_D4: return 1;
case CMD_UNKNOWN_D5: return 2;
case CMD_UNKNOWN_D6: return 2;
@@ -536,6 +536,12 @@ void avr_hid_enable_charger(void)
avr_execute_command(CMD_SET_INTCHRG, &enable, sizeof(enable));
}
+void avr_hid_wifi_pd(int high)
+{
+ uint8_t state = high ? 0x01 : 0x00;
+ avr_execute_command(CMD_WIFI_PD, &state, sizeof(state));
+}
+
static void avr_hid_lcm_power(uint8_t parameter)
{
avr_execute_command(CMD_LCM_POWER, &parameter, sizeof(parameter));
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h
index 64b44675f7..baa7083760 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h
+++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h
@@ -28,6 +28,8 @@ void avr_hid_init(void);
void avr_hid_enable_charger(void);
+void avr_hid_wifi_pd(int high);
+
void avr_hid_lcm_sleep(void);
void avr_hid_lcm_wake(void);
void avr_hid_lcm_power_on(void);
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/wifi-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/wifi-sansaconnect.c
new file mode 100644
index 0000000000..867b1da477
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/sansa-connect/wifi-sansaconnect.c
@@ -0,0 +1,130 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+* $Id$
+*
+* Copyright (C) 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
+* 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 "spi.h"
+#include "avr-sansaconnect.h"
+#include "libertas/if_spi_drv.h"
+
+#define IO_SERIAL0_XMIT (0x100)
+
+void libertas_spi_init(void)
+{
+ IO_GIO_DIR0 &= ~((1 << 4) /* CS */ | (1 << 3) /* reset */);
+ libertas_spi_reset(1);
+ libertas_spi_cs(1);
+
+ /* Enable the clock */
+ bitset16(&IO_CLK_MOD2, CLK_MOD2_SIF0);
+
+ /* Disable transmitter */
+ IO_SERIAL0_TX_ENABLE = 0x0001;
+
+ /* SELSDEN = 0, SLVEN = 0, SIOCLR = 0, SCLKM = 1, MSB = 1, MSSEL = 0,
+ * RATE = 2 -> 15MHz
+ */
+ IO_SERIAL0_MODE = 0x0601;
+
+ /* Disable the clock */
+ bitclr16(&IO_CLK_MOD2, CLK_MOD2_SIF0);
+
+ /* Make sure the SPI clock is not inverted */
+ bitclr16(&IO_CLK_INV, CLK_INV_SIF0);
+}
+
+void libertas_spi_reset(int high)
+{
+ if (high)
+ {
+ IO_GIO_BITSET0 = (1 << 3);
+ }
+ else
+ {
+ IO_GIO_BITCLR0 = (1 << 3);
+ }
+}
+
+void libertas_spi_pd(int high)
+{
+ avr_hid_wifi_pd(high);
+}
+
+void libertas_spi_cs(int high)
+{
+ if (high)
+ {
+ IO_GIO_BITSET0 = (1 << 4);
+ }
+ else
+ {
+ IO_GIO_BITCLR0 = (1 << 4);
+ }
+}
+
+void libertas_spi_tx(const uint8_t *buf, int len)
+{
+ /* Enable the clock */
+ bitset16(&IO_CLK_MOD2, CLK_MOD2_SIF0);
+ IO_SERIAL0_TX_ENABLE = 0x0001;
+
+ while (len > 0)
+ {
+ IO_SERIAL0_TX_DATA = *(buf + 1);
+ while (IO_SERIAL0_RX_DATA & IO_SERIAL0_XMIT) {};
+ IO_SERIAL0_TX_DATA = *buf;
+ while (IO_SERIAL0_RX_DATA & IO_SERIAL0_XMIT) {};
+
+ buf += 2;
+ len -= 2;
+ }
+
+ IO_SERIAL0_TX_ENABLE = 0x0000;
+
+ /* Disable the clock */
+ bitclr16(&IO_CLK_MOD2, CLK_MOD2_SIF0);
+}
+
+void libertas_spi_rx(uint8_t *buf, int len)
+{
+ /* Enable the clock */
+ bitset16(&IO_CLK_MOD2, CLK_MOD2_SIF0);
+ IO_SERIAL0_TX_ENABLE = 0x0001;
+
+ while (len > 0)
+ {
+ uint16_t data;
+ IO_SERIAL0_TX_DATA = 0;
+ while ((data = IO_SERIAL0_RX_DATA) & IO_SERIAL0_XMIT) {};
+ *(buf + 1) = data & 0xFF;
+ IO_SERIAL0_TX_DATA = 0;
+ while ((data = IO_SERIAL0_RX_DATA) & IO_SERIAL0_XMIT) {};
+ *buf = data & 0xFF;
+
+ buf += 2;
+ len -= 2;
+ }
+
+ IO_SERIAL0_TX_ENABLE = 0x0000;
+
+ /* Disable the clock */
+ bitclr16(&IO_CLK_MOD2, CLK_MOD2_SIF0);
+}
diff --git a/firmware/target/arm/tms320dm320/system-dm320.c b/firmware/target/arm/tms320dm320/system-dm320.c
index 935f3609a6..c80082afd8 100644
--- a/firmware/target/arm/tms320dm320/system-dm320.c
+++ b/firmware/target/arm/tms320dm320/system-dm320.c
@@ -369,9 +369,11 @@ void system_init(void)
#endif
#ifdef SANSA_CONNECT
+#ifndef HAVE_WIFI
/* keep WIFI CS and reset high to save power */
IO_GIO_DIR0 &= ~((1 << 4) /* CS */ | (1 << 3) /* reset */);
IO_GIO_BITSET0 = (1 << 4) | (1 << 3);
+#endif
i2c_init();
avr_hid_init();