laforge has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/15152 )

Change subject: fw: Add support for Huawei GTM900-B modules
......................................................................

fw: Add support for Huawei GTM900-B modules

Both MG01GSMT and MG01GSMT hardware variants are
supported and automatically detected based on the
flash manufacturer.

Change-Id: I3a770ea93fc72c4e9b63078e253602f204b5be23
---
M src/target/firmware/Makefile
A src/target/firmware/board/gtm900b/init.c
A src/target/firmware/board/gtm900b/keymap.h
A src/target/firmware/board/gtm900b/rf_power.c
A src/target/firmware/board/gtm900b/rffe_gtm900b.c
5 files changed, 464 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/src/target/firmware/Makefile b/src/target/firmware/Makefile
index 2f44a20..f7235ac 100644
--- a/src/target/firmware/Makefile
+++ b/src/target/firmware/Makefile
@@ -24,7 +24,7 @@
 #

 # List of all supported boards (meant to be overridden on command line)
-BOARDS?=compal_e88 compal_e86 compal_e99 se_j100 gta0x fcdev3b pirelli_dpl10
+BOARDS?=compal_e88 compal_e86 compal_e99 se_j100 gta0x gtm900b fcdev3b 
pirelli_dpl10

 # Framebuffer support, board specific drivers
 FB_OBJS=fb/framebuffer.o fb/font.o fb/helvR08.o fb/helvB14.o fb/c64.o \
@@ -46,6 +46,12 @@
        battery/dummy.o $(FB_dummy_OBJS)
 BOARD_gta0x_ENVIRONMENTS=highram

+# Huawei GTM900-B
+BOARD_gtm900b_OBJS=$(calypso_COMMON_OBJS) board/gtm900b/init.o \
+       board/gtm900b/rffe_gtm900b.o board/gtm900b/rf_power.o \
+       battery/dummy.o $(FB_dummy_OBJS)
+BOARD_gtm900b_ENVIRONMENTS=highram
+
 # FreeCalypso FCDEV3B
 BOARD_fcdev3b_OBJS=$(calypso_COMMON_OBJS) board/fcdev3b/init.o \
        board/gta0x/rffe_gta0x_triband.o board/gta0x/rf_power.o \
diff --git a/src/target/firmware/board/gtm900b/init.c 
b/src/target/firmware/board/gtm900b/init.c
new file mode 100644
index 0000000..38ede10
--- /dev/null
+++ b/src/target/firmware/board/gtm900b/init.c
@@ -0,0 +1,140 @@
+/* Initialization for the Huawei GTM900-B modem */
+
+/* (C) 2010 by Harald Welte <[email protected]>
+ * (C) 2010-19 by Steve Markgraf <[email protected]>
+ *
+ * All Rights Reserved
+ *
+ * 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 program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include <debug.h>
+#include <ctors.h>
+#include <memory.h>
+#include <board.h>
+#include <keypad.h>
+#include <console.h>
+#include <flash/cfi_flash.h>
+#include <tiffs.h>
+
+#include <calypso/irq.h>
+#include <calypso/clock.h>
+#include <calypso/dma.h>
+#include <calypso/rtc.h>
+#include <calypso/timer.h>
+#include <uart.h>
+#include <calypso/backlight.h>
+
+#include <comm/sercomm.h>
+#include <comm/timer.h>
+
+#include <abb/twl3025.h>
+#include <rf/trf6151.h>
+#include "keymap.h"
+
+#define ARMIO_LATCH_OUT 0xfffe4802
+#define IO_CNTL_REG    0xfffe4804
+#define ASIC_CONF_REG  0xfffef008
+#define IO_CONF_REG    0xfffef00a
+#define LPG_LCR_REG    0xfffe7800
+#define LPG_PM_REG     0xfffe7801
+
+static void board_io_init(void)
+{
+       uint16_t reg;
+
+       reg = readw(ASIC_CONF_REG);
+       /* Set LPG pin mux for power LED */
+       reg |= (1 << 6);
+       /* TWL3025: Set SPI+RIF RX clock to rising edge */
+       reg |= (1 << 13) | (1 << 14);
+       writew(reg, ASIC_CONF_REG);
+
+       /*
+        * Most Calypso peripheral interface signals are unconnected
+        * on this modem.  We configure them to be GPIOs in IO_CONF_REG,
+        * then configure them to be outputs in IO_CNTL_REG, then set
+        * the outputs to 0 in ARMIO_LATCH_OUT.
+        */
+       writew(0x03F5, IO_CONF_REG);
+       writew(0xC000, IO_CNTL_REG);
+       writew(0x0000, ARMIO_LATCH_OUT);
+
+       /* Set LPG output permanently on (power LED) */
+       writew(1, LPG_PM_REG);
+       writew((1 << 7), LPG_LCR_REG);
+}
+
+void board_init(int with_irq)
+{
+       /* Configure the memory interface */
+       calypso_mem_cfg(CALYPSO_nCS0, 3, CALYPSO_MEM_16bit, 1);
+       calypso_mem_cfg(CALYPSO_nCS1, 3, CALYPSO_MEM_16bit, 1);
+       calypso_mem_cfg(CALYPSO_nCS2, 5, CALYPSO_MEM_16bit, 1);
+       calypso_mem_cfg(CALYPSO_nCS3, 5, CALYPSO_MEM_16bit, 1);
+       calypso_mem_cfg(CALYPSO_CS4, 0, CALYPSO_MEM_8bit, 1);
+       calypso_mem_cfg(CALYPSO_nCS6, 0, CALYPSO_MEM_32bit, 1);
+       calypso_mem_cfg(CALYPSO_nCS7, 0, CALYPSO_MEM_32bit, 0);
+
+       /* Set VTCXO_DIV2 = 1, configure PLL for 104 MHz and give ARM half of 
that */
+       calypso_clock_set(2, CALYPSO_PLL13_104_MHZ, ARM_MCLK_DIV_2);
+
+       /* Configure the RHEA bridge with some sane default values */
+       calypso_rhea_cfg(0, 0, 0xff, 0, 1, 0, 0);
+
+       /* Initialize board-specific GPIO */
+       board_io_init();
+
+       /* Enable bootrom mapping to route exception vectors to RAM */
+       calypso_bootrom(with_irq);
+       calypso_exceptions_install();
+
+       /* Initialize interrupt controller */
+       if (with_irq)
+               irq_init();
+
+       sercomm_bind_uart(UART_IRDA);
+       cons_bind_uart(UART_MODEM);
+
+       /* initialize IRDA UART to be used for sercomm */
+       uart_init(UART_IRDA, with_irq);
+       uart_baudrate(UART_IRDA, UART_115200);
+
+       /* Initialize MODEM UART to be used for old-school console code. */
+       uart_init(UART_MODEM, with_irq);
+       uart_baudrate(UART_MODEM, UART_115200);
+
+       /* Initialize hardware timers */
+       hwtimer_init();
+
+       /* Initialize DMA controller */
+       dma_init();
+
+       /* Initialize real time clock */
+       rtc_init();
+
+       /* Initialize system timers (uses hwtimer 2) */
+       timer_init();
+
+       /* Initialize keypad driver */
+       keypad_init(keymap, with_irq);
+
+       /* Initialize ABB driver (uses SPI) */
+       twl3025_init();
+}
diff --git a/src/target/firmware/board/gtm900b/keymap.h 
b/src/target/firmware/board/gtm900b/keymap.h
new file mode 100644
index 0000000..07a19e0
--- /dev/null
+++ b/src/target/firmware/board/gtm900b/keymap.h
@@ -0,0 +1,29 @@
+/* keymap for the Huawei GTM900-B */
+
+static const uint8_t keymap[] = {
+       [KEY_0]         = 0,
+       [KEY_1]         = 0,
+       [KEY_2]         = 0,
+       [KEY_3]         = 0,
+       [KEY_4]         = 0,
+       [KEY_5]         = 0,
+       [KEY_6]         = 0,
+       [KEY_7]         = 0,
+       [KEY_8]         = 0,
+       [KEY_9]         = 0,
+       [KEY_STAR]      = 0,
+       [KEY_HASH]      = 0,
+       [KEY_MENU]      = 0,
+       [KEY_LEFT_SB]   = 0,
+       [KEY_RIGHT_SB]  = 0,
+       [KEY_UP]        = 0,
+       [KEY_DOWN]      = 0,
+       [KEY_LEFT]      = 0,
+       [KEY_RIGHT]     = 0,
+       [KEY_OK]        = 0,
+/* power button is not connected to keypad scan matrix but to TWL3025 */
+       [KEY_POWER]     = 31,
+       [KEY_MINUS]     = 0,
+       [KEY_PLUS]      = 0,
+       [KEY_CAMERA]    = 0,
+};
diff --git a/src/target/firmware/board/gtm900b/rf_power.c 
b/src/target/firmware/board/gtm900b/rf_power.c
new file mode 100644
index 0000000..cd47ddf
--- /dev/null
+++ b/src/target/firmware/board/gtm900b/rf_power.c
@@ -0,0 +1,63 @@
+/* Tx RF power calibration for the Huawei GTM900-B */
+
+/* (C) 2010 by Harald Welte <[email protected]>
+ *
+ * All Rights Reserved
+ *
+ * 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 program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdint.h>
+#include <osmocom/core/utils.h>
+
+/* GSM900 ARFCN 33, Measurements by Steve Markgraf / May 2010 */
+/* FIXME those are from the Compal phones, do measurements with the GTM900-B */
+const int16_t dbm2apc_gsm900[] = {
+       [0]     = 151,
+       [1]     = 152,
+       [2]     = 153,
+       [3]     = 155,
+       [4]     = 156,
+       [5]     = 158,
+       [6]     = 160,
+       [7]     = 162,
+       [8]     = 164,
+       [9]     = 167,
+       [10]    = 170,
+       [11]    = 173,
+       [12]    = 177,
+       [13]    = 182,
+       [14]    = 187,
+       [15]    = 192,
+       [16]    = 199,
+       [17]    = 206,
+       [18]    = 214,
+       [19]    = 223,
+       [20]    = 233,
+       [21]    = 244,
+       [22]    = 260,
+       [23]    = 271,
+       [24]    = 288,
+       [25]    = 307,
+       [26]    = 327,
+       [27]    = 350,
+       [28]    = 376,
+       [29]    = 407,
+       [30]    = 456,
+       [31]    = 575,
+};
+
+const int dbm2apc_gsm900_max = ARRAY_SIZE(dbm2apc_gsm900) - 1;
diff --git a/src/target/firmware/board/gtm900b/rffe_gtm900b.c 
b/src/target/firmware/board/gtm900b/rffe_gtm900b.c
new file mode 100644
index 0000000..633c637
--- /dev/null
+++ b/src/target/firmware/board/gtm900b/rffe_gtm900b.c
@@ -0,0 +1,225 @@
+/* RF frontend driver for Huawei GTM900-B modems, supporting both
+ * MG01GSMT and MG01GSMT hardware variants */
+
+/* (C) 2019 by Steve Markgraf <[email protected]>
+ *
+ * All Rights Reserved
+ *
+ * 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 program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include <debug.h>
+#include <memory.h>
+#include <rffe.h>
+#include <calypso/tsp.h>
+#include <rf/trf6151.h>
+#include <flash/cfi_flash.h>
+
+/* This is a value that has been measured for the GTM900-B: 74dBm,
+   it is the difference between the input level at the antenna and what
+   the DSP reports, subtracted by the total gain of the TRF6151 */
+#define SYSTEM_INHERENT_GAIN   74
+
+/* describe how the RF frontend is wired on the Huawei GTM900-B */
+#define                IOTA_STROBE     TSPEN(0)        /* Strobe for the Iota 
TSP */
+#define                RITA_STROBE     TSPEN(2)        /* Strobe for the Rita 
TSP */
+
+#define                RITA_RESET      TSPACT(0)       /* Reset of the Rita 
TRF6151 */
+#define                PA_BAND_SELECT  TSPACT(3)       /* Low: 850/900, High: 
1800/1900 */
+#define                PA_TX_ENABLE    TSPACT(9)       /* Enable the Power 
Amplifier */
+
+/* MGC2GSMT Ver. BRF specific antenna switch signals, low active */
+#define                ASM_VC1         TSPACT(1)       /* low on GSM900 TX */
+#define                ASM_VC2         TSPACT(2)       /* low on DCS1800 TX */
+
+/* MG01GSMT Ver. C specific antenna switch signals, low active */
+#define                CXG_CTLA        TSPACT(4)       /* CXG1192UR CTLA input 
*/
+#define                CXG_CTLB        TSPACT(1)       /* CXG1192UR CTLB input 
*/
+#define                CXG_CTLC        TSPACT(2)       /* CXG1192UR CTLC input 
*/
+
+/*
+ * The Sony CXG1192UR switch is wired as follows on the MG01GSMT Ver. C:
+ *
+ * Rx1: GSM850 RX filter (Epcos B5013)
+ * Rx2: GSM900 RX filter (Epcos B7710)
+ * Rx3: DCS1800 RX filter (Epcos 7714)
+ * Rx4: PCS1900 RX filter (not populated)
+ * Tx1: low band PA output
+ * Tx2: high band PA output
+ */
+
+typedef enum rffe_var {
+       RFFE_MGC2GSMT,
+       RFFE_MG01GSMT
+} rffe_var_t;
+
+static rffe_var_t rffe_variant = RFFE_MGC2GSMT;
+
+static inline void rffe_mode_mgc2gsmt(enum gsm_band band, int tx)
+{
+       uint16_t tspact = tsp_act_state();
+
+       /* First we mask off all bits from the state cache */
+       tspact &= ~(PA_BAND_SELECT | PA_TX_ENABLE);
+       tspact |=  (ASM_VC1 | ASM_VC2); /* low-active */
+
+#ifdef CONFIG_TX_ENABLE
+       /* Then we selectively set the bits on, if required */
+       if (tx) {
+               tspact |= PA_TX_ENABLE;
+               tspact &= ~CXG_CTLA;
+
+               if (band == GSM_BAND_1800 || band == GSM_BAND_1900) {
+                       tspact |= PA_BAND_SELECT;
+                       tspact &= ~ASM_VC2;
+               } else {
+                       tspact &= ~ASM_VC1;
+               }
+       }
+#endif /* TRANSMIT_SUPPORT */
+
+       tsp_act_update(tspact);
+}
+
+static inline void rffe_mode_mg01gsmt(enum gsm_band band, int tx)
+{
+       uint16_t tspact = tsp_act_state();
+
+       /* First we mask off all bits from the state cache */
+       tspact &= ~(PA_BAND_SELECT | PA_TX_ENABLE);
+       tspact |=  (CXG_CTLA | CXG_CTLB | CXG_CTLC);    /* low-active */
+
+       switch (band) {
+       case GSM_BAND_850:
+               tspact &= ~CXG_CTLB;              /* select Ant1 - Rx1 */
+               break;
+       case GSM_BAND_900:
+               tspact &= ~CXG_CTLC;              /* select Ant1 - Rx2 */
+               break;
+       case GSM_BAND_1800:                       /* select Ant2 - Rx3 */
+               break;
+       case GSM_BAND_1900:
+               tspact &= ~(CXG_CTLB | CXG_CTLC); /* select Ant2 - Rx4 */
+               break;
+       default:
+               break;
+       }
+
+#ifdef CONFIG_TX_ENABLE
+       /* Then we selectively set the bits on, if required */
+       if (tx) {
+               tspact |= PA_TX_ENABLE;
+               tspact &= ~CXG_CTLA;
+
+               if (band == GSM_BAND_1800 || band == GSM_BAND_1900) {
+                       tspact |= PA_BAND_SELECT;
+                       tspact &= ~CXG_CTLB;
+               }
+       }
+#endif /* TRANSMIT_SUPPORT */
+
+       tsp_act_update(tspact);
+}
+
+/* switch RF Frontend Mode */
+void rffe_mode(enum gsm_band band, int tx)
+{
+       if (rffe_variant == RFFE_MGC2GSMT)
+               rffe_mode_mgc2gsmt(band, tx);
+       else
+               rffe_mode_mg01gsmt(band, tx);
+}
+
+uint32_t rffe_get_rx_ports(void)
+{
+       return (1 << PORT_LO) | (1 << PORT_DCS1800) | (1 << PORT_PCS1900);
+}
+
+uint32_t rffe_get_tx_ports(void)
+{
+       return (1 << PORT_LO) | (1 << PORT_HI);
+}
+
+/* Returns need for IQ swap */
+int rffe_iq_swapped(uint16_t band_arfcn, int tx)
+{
+       return trf6151_iq_swapped(band_arfcn, tx);
+}
+
+#define ARM_CONF_REG   0xfffef006
+
+void rffe_init(void)
+{
+       uint16_t reg;
+       uint16_t manufacturer_id = 0;
+
+       reg = readw(ARM_CONF_REG);
+       reg &= ~ (1 << 7);      /* TSPACT4 I/O function, not nRDYMEM */
+       writew(reg, ARM_CONF_REG);
+
+       /* Configure the TSPEN which is connected to the TWL3025 */
+       tsp_setup(IOTA_STROBE, 1, 0, 0);
+
+       trf6151_init(RITA_STROBE, RITA_RESET);
+
+       /* Detect the used RFFE variant based on the used flash chip.
+        * The MGC2GSMT uses a Samsung flash, whereas the MG01GSMT uses
+        * a Spansion flash. We use an address above the Calpso bootrom
+        * so we do not need to unmap it to access the flash. */
+       flash_get_id((void *)0x40000, &manufacturer_id, NULL);
+
+       switch (manufacturer_id) {
+       case CFI_MANUF_SPANSION:
+               printf("Detected MG01GSMT module\n\n");
+               rffe_variant = RFFE_MG01GSMT;
+               break;
+       case CFI_MANUF_SAMSUNG:
+               printf("Detected MGC2GSMT module\n\n");
+               rffe_variant = RFFE_MGC2GSMT;
+               break;
+       default:
+               printf("Unknown module detected, flash ID 0x%4.4x\n"
+                      "Please contact mailing list!\n\n", manufacturer_id);
+               rffe_variant = RFFE_MGC2GSMT;
+               break;
+       }
+}
+
+uint8_t rffe_get_gain(void)
+{
+       return trf6151_get_gain();
+}
+
+void rffe_set_gain(uint8_t dbm)
+{
+       trf6151_set_gain(dbm);
+}
+
+const uint8_t system_inherent_gain = SYSTEM_INHERENT_GAIN;
+
+/* Given the expected input level of exp_inp dBm/8 and the target of target_bb
+ * dBm8, configure the RF Frontend with the respective gain */
+void rffe_compute_gain(int16_t exp_inp, int16_t target_bb)
+{
+       trf6151_compute_gain(exp_inp, target_bb);
+}
+
+void rffe_rx_win_ctrl(int16_t exp_inp, int16_t target_bb)
+{
+       /* FIXME */
+}

--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/15152
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I3a770ea93fc72c4e9b63078e253602f204b5be23
Gerrit-Change-Number: 15152
Gerrit-PatchSet: 1
Gerrit-Owner: steve-m <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-MessageType: merged

Reply via email to