add support for detecting Axon models via chip_select of first board
authorMiroslav Ondra <ondra@faster.cz>
Wed, 5 Sep 2018 13:19:49 +0000 (15:19 +0200)
committerMiroslav Ondra <ondra@faster.cz>
Wed, 5 Sep 2018 13:19:49 +0000 (15:19 +0200)
modules/unipi/src/unipi_platform.c
modules/unipi/src/unipi_platform.h
modules/unipi/src/unipi_spi.c

index 94d2ca6f6e17f1cea35c8afac38a34913cafd75d..2bb26434d3024a8fde61216f2d898bfeea7ce705 100644 (file)
@@ -1566,61 +1566,61 @@ struct neuronspi_board_entry NEURONSPI_BOARDTABLE[NEURONSPI_BOARDTABLE_LEN] = {
 
 // Module table
 struct neuronspi_model_definition NEURONSPI_MODELTABLE[NEURONSPI_MODELTABLE_LEN] = {
-               {.eeprom_length = 4, .eeprom_name = "S103", .name_length = 11, .model_name = "Neuron S103",
+               {.eeprom_length = 4, .eeprom_name = "S103", .name_length = 11, .model_name = "Neuron S103", .first_cs = 1,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S103_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S103", .name_length = 13, .model_name = "Neuron S103-G",
+               {.eeprom_length = 4, .eeprom_name = "S103", .name_length = 13, .model_name = "Neuron S103-G", .first_cs = 1,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S103G_HW_DEFINITION_BOARD},
-               {.eeprom_length = 6, .eeprom_name = "S103IQ", .name_length = 16, .model_name = "Neuron S103-IQRF",
+               {.eeprom_length = 6, .eeprom_name = "S103IQ", .name_length = 16, .model_name = "Neuron S103-IQRF", .first_cs = 1,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S103IQ_HW_DEFINITION_BOARD},
-               {.eeprom_length = 6, .eeprom_name = "S103EO", .name_length = 7, .model_name = "Neuron HOUM Enocean S103",
+               {.eeprom_length = 6, .eeprom_name = "S103EO", .name_length = 7, .model_name = "Neuron HOUM Enocean S103", .first_cs = 1,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S103EO_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S105", .name_length = 9, .model_name = "Axon S105",
+               {.eeprom_length = 4, .eeprom_name = "S105", .name_length = 9, .model_name = "Axon S105", .first_cs = 0,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S105_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S115", .name_length = 9, .model_name = "Axon S115",
+               {.eeprom_length = 4, .eeprom_name = "S115", .name_length = 9, .model_name = "Axon S115", .first_cs = 0,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S115_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S155", .name_length = 9, .model_name = "Axon S155",
+               {.eeprom_length = 4, .eeprom_name = "S155", .name_length = 9, .model_name = "Axon S155", .first_cs = 0,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S155_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S205", .name_length = 9, .model_name = "Axon S205",
+               {.eeprom_length = 4, .eeprom_name = "S205", .name_length = 9, .model_name = "Axon S205", .first_cs = 0,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S205_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S215", .name_length = 9, .model_name = "Axon S215",
+               {.eeprom_length = 4, .eeprom_name = "S215", .name_length = 9, .model_name = "Axon S215", .first_cs = 0,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S215_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S505", .name_length = 9, .model_name = "Axon S505",
+               {.eeprom_length = 4, .eeprom_name = "S505", .name_length = 9, .model_name = "Axon S505", .first_cs = 0,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S505_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S515", .name_length = 9, .model_name = "Axon S515",
+               {.eeprom_length = 4, .eeprom_name = "S515", .name_length = 9, .model_name = "Axon S515", .first_cs = 0,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S515_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "S605", .name_length = 9, .model_name = "Axon S605",
+               {.eeprom_length = 4, .eeprom_name = "S605", .name_length = 9, .model_name = "Axon S605", .first_cs = 0,
                                .combination_count = 1, .combinations = NEURONSPI_MODEL_S605_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M103", .name_length = 11, .model_name = "Neuron M103",
+               {.eeprom_length = 4, .eeprom_name = "M103", .name_length = 11, .model_name = "Neuron M103", .first_cs = 1,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M103_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M203", .name_length = 11, .model_name = "Neuron M203",
+               {.eeprom_length = 4, .eeprom_name = "M203", .name_length = 11, .model_name = "Neuron M203", .first_cs = 1,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M203_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M303", .name_length = 11, .model_name = "Neuron M303",
+               {.eeprom_length = 4, .eeprom_name = "M303", .name_length = 11, .model_name = "Neuron M303", .first_cs = 1,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M303_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M403", .name_length = 11, .model_name = "Neuron M403",
+               {.eeprom_length = 4, .eeprom_name = "M403", .name_length = 11, .model_name = "Neuron M403", .first_cs = 1,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M403_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M503", .name_length = 11, .model_name = "Neuron M503",
+               {.eeprom_length = 4, .eeprom_name = "M503", .name_length = 11, .model_name = "Neuron M503", .first_cs = 1,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M503_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M603", .name_length = 11, .model_name = "Neuron M603",
+               {.eeprom_length = 4, .eeprom_name = "M603", .name_length = 11, .model_name = "Neuron M603", .first_cs = 1,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M603_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M205", .name_length = 9, .model_name = "Axon M205",
+               {.eeprom_length = 4, .eeprom_name = "M205", .name_length = 9, .model_name = "Axon M205", .first_cs = 0,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M205_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M505", .name_length = 9, .model_name = "Axon M505",
+               {.eeprom_length = 4, .eeprom_name = "M505", .name_length = 9, .model_name = "Axon M505", .first_cs = 0,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M505_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "M515", .name_length = 11, .model_name = "Neuron M515",
+               {.eeprom_length = 4, .eeprom_name = "M515", .name_length = 11, .model_name = "Neuron M515", .first_cs = 1,
                                .combination_count = 2, .combinations = NEURONSPI_MODEL_M515_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "L203", .name_length = 11, .model_name = "Neuron L203",
+               {.eeprom_length = 4, .eeprom_name = "L203", .name_length = 11, .model_name = "Neuron L203", .first_cs = 0,
                                .combination_count = 3, .combinations = NEURONSPI_MODEL_L203_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "L303", .name_length = 11, .model_name = "Neuron L303",
+               {.eeprom_length = 4, .eeprom_name = "L303", .name_length = 11, .model_name = "Neuron L303", .first_cs = 0,
                                .combination_count = 3, .combinations = NEURONSPI_MODEL_L303_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "L403", .name_length = 11, .model_name = "Neuron L403",
+               {.eeprom_length = 4, .eeprom_name = "L403", .name_length = 11, .model_name = "Neuron L403", .first_cs = 0,
                                .combination_count = 3, .combinations = NEURONSPI_MODEL_L403_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "L503", .name_length = 11, .model_name = "Neuron L503",
+               {.eeprom_length = 4, .eeprom_name = "L503", .name_length = 11, .model_name = "Neuron L503", .first_cs = 0,
                                .combination_count = 3, .combinations = NEURONSPI_MODEL_L503_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "L513", .name_length = 11, .model_name = "Neuron L513",
+               {.eeprom_length = 4, .eeprom_name = "L513", .name_length = 11, .model_name = "Neuron L513", .first_cs = 0,
                                .combination_count = 3, .combinations = NEURONSPI_MODEL_L513_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "L205", .name_length = 9, .model_name = "Axon L205",
+               {.eeprom_length = 4, .eeprom_name = "L205", .name_length = 9, .model_name = "Axon L205", .first_cs = 1,
                                .combination_count = 3, .combinations = NEURONSPI_MODEL_L205_HW_DEFINITION_BOARD},
-               {.eeprom_length = 4, .eeprom_name = "L505", .name_length = 9, .model_name = "Axon L503",
+               {.eeprom_length = 4, .eeprom_name = "L505", .name_length = 9, .model_name = "Axon L503", .first_cs = 1,
                                .combination_count = 3, .combinations = NEURONSPI_MODEL_L505_HW_DEFINITION_BOARD}
 };
 
@@ -1978,7 +1978,18 @@ s32 neuronspi_find_model_id(u32 probe_count)
 {
        struct neuronspi_driver_data *n_spi;
        int i,j, ret = -1;
+    int chip_select;
        u8 *inv = kzalloc(sizeof(*inv) * NEURONSPI_MODELTABLE_LEN, GFP_ATOMIC);
+
+       if (neuronspi_s_dev[0]) {
+        chip_select = neuronspi_s_dev[0]->chip_select;
+        for (j = 0; j < NEURONSPI_MODELTABLE_LEN; j++) {
+            if (NEURONSPI_MODELTABLE[j].first_cs != chip_select) {
+                               inv[j] = 1;
+            }
+        }
+    }
+
        for (i = 0; i < probe_count; i++) {
                if (neuronspi_s_dev[i]) {
                        n_spi = spi_get_drvdata(neuronspi_s_dev[i]);
@@ -1987,7 +1998,7 @@ s32 neuronspi_find_model_id(u32 probe_count)
                                        inv[j] = 1;
                                } else if (NEURONSPI_MODELTABLE[j].combinations[i].combination_board_id != n_spi->combination_id) {
                                        inv[j] = 1;
-                               }
+                }
                        }
                } else {
                        for (j = 0; j < NEURONSPI_MODELTABLE_LEN; j++) {
index 464eb8778e890c3aa338d1759a96cf00adec3471..5d84ef74d8c24048b0ad5c70d31150b5093d368d 100644 (file)
@@ -133,6 +133,7 @@ struct neuronspi_model_definition
        const char*                                                     model_name;
        u32                                                                     combination_count;
        struct neuronspi_board_combination      *combinations;
+    u32                                 first_cs;
 };
 
 /***************
index 6452c6f653ff621aab7ccf3f04352128b9c38add..50b70b549c650c3e816bad10155e382438b40430 100644 (file)
@@ -906,10 +906,10 @@ s32 neuronspi_spi_probe(struct spi_device *spi)
     n_spi->combination_id = 0xff;
        if (first_probe[0] != 0) {
         // Board found, try to find model in table
-        n_spi->firmware_version = REG1000(first_probe,1000);
+        n_spi->firmware_version = REG1000   (first_probe,1000);
                uart_count              = REG1000_lo(first_probe,1002) & 0xf;
         hardware_model          = REG1000_hi(first_probe,1003);
-        lower_board             = REG1000(first_probe,1004);
+        lower_board             = REG1000   (first_probe,1004) & 0xfff0;
                for (i = 0; i < NEURONSPI_BOARDTABLE_LEN; i++) {
                        if (hardware_model == NEURONSPI_BOARDTABLE[i].index) {
                 //if ((lower_board>>8) != NEURONSPI_BOARDTABLE[i].lower_board_id) { // strange combination  //break;
@@ -920,8 +920,8 @@ s32 neuronspi_spi_probe(struct spi_device *spi)
                 break;
                        }
                }
-        n_spi->ideal_frequency = (neuronspi_is_noirq_model((lower_board & 0xfff0))) ? NEURONSPI_SLOWER_FREQ : NEURONSPI_COMMON_FREQ; 
-        no_irq = neuronspi_is_noirq_model((lower_board & 0xfff0));
+        n_spi->ideal_frequency = (neuronspi_is_noirq_model(lower_board) ? NEURONSPI_SLOWER_FREQ : NEURONSPI_COMMON_FREQ; 
+        no_irq = neuronspi_is_noirq_model(lower_board);
 
         printk(KERN_INFO "UNIPISPI: Detected UniPi Board %s (L:%x U:%x C:%x) at CS%d (nspi%d)\n\t\t\tFw: v%d.%d Uarts:%d, reg1001-4: %04x %04x %04x %04x\n",
                                board_name, hi(lower_board), upper_board, hardware_model, spi->chip_select, n_spi->neuron_index,
@@ -930,7 +930,6 @@ s32 neuronspi_spi_probe(struct spi_device *spi)
 
        } else if (probe_always_succeeds) {
         // dummy board
-        lower_board = 0xff;
         if (always_create_uart) uart_count = 1;
         n_spi->ideal_frequency = NEURONSPI_SLOWER_FREQ;
                no_irq = 1;