From: Tom Knot Date: Mon, 16 Apr 2018 10:41:30 +0000 (+0200) Subject: Minor fixes: X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=6f046ec3206bdb955a897576bf3b291f00cbde2a;p=graphit%2Funipi-kernel.git Minor fixes: - Added version string to SYSFS - Error code for direct SPI reads - Model names should now correspond to DB names --- diff --git a/modules/unipi/src/unipi_common.h b/modules/unipi/src/unipi_common.h index c530417..4ea3748 100644 --- a/modules/unipi/src/unipi_common.h +++ b/modules/unipi/src/unipi_common.h @@ -51,7 +51,7 @@ #ifdef NEURONSPI_SCHED_REQUIRED #include #endif -#define NEURONSPI_MAJOR_VERSIONSTRING "Development Beta Version 0.04:05:04:2018" +#define NEURONSPI_MAJOR_VERSIONSTRING "Development Beta Version 0.05:16:04:2018" #define NEURONSPI_MAX_DEVS 3 #define NEURONSPI_MAX_UART 128 diff --git a/modules/unipi/src/unipi_platform.c b/modules/unipi/src/unipi_platform.c index f6ddf30..afd107a 100644 --- a/modules/unipi/src/unipi_platform.c +++ b/modules/unipi/src/unipi_platform.c @@ -1446,35 +1446,35 @@ 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 = 4, .model_name = "S103", + {.eeprom_length = 4, .eeprom_name = "S103", .name_length = 4, .model_name = "Neuron S103", .combination_count = 1, .combinations = NEURONSPI_MODEL_S103_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "S103", .name_length = 6, .model_name = "S103-G", + {.eeprom_length = 4, .eeprom_name = "S103", .name_length = 6, .model_name = "Neuron S103-G", .combination_count = 1, .combinations = NEURONSPI_MODEL_S103G_HW_DEFINITION_BOARD}, - {.eeprom_length = 6, .eeprom_name = "S103IQ", .name_length = 7, .model_name = "S103-IQ", + {.eeprom_length = 6, .eeprom_name = "S103IQ", .name_length = 7, .model_name = "Neuron S103-IQRF", .combination_count = 1, .combinations = NEURONSPI_MODEL_S103IQ_HW_DEFINITION_BOARD}, - {.eeprom_length = 6, .eeprom_name = "S103EO", .name_length = 7, .model_name = "S103-EO", + {.eeprom_length = 6, .eeprom_name = "S103EO", .name_length = 7, .model_name = "Neuron HOUM Enocean S103", .combination_count = 1, .combinations = NEURONSPI_MODEL_S103EO_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "M103", .name_length = 4, .model_name = "M103", + {.eeprom_length = 4, .eeprom_name = "M103", .name_length = 4, .model_name = "Neuron M103", .combination_count = 2, .combinations = NEURONSPI_MODEL_M103_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "M203", .name_length = 4, .model_name = "M203", + {.eeprom_length = 4, .eeprom_name = "M203", .name_length = 4, .model_name = "Neuron M203", .combination_count = 2, .combinations = NEURONSPI_MODEL_M203_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "M303", .name_length = 4, .model_name = "M303", + {.eeprom_length = 4, .eeprom_name = "M303", .name_length = 4, .model_name = "Neuron M303", .combination_count = 2, .combinations = NEURONSPI_MODEL_M303_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "M403", .name_length = 4, .model_name = "M403", + {.eeprom_length = 4, .eeprom_name = "M403", .name_length = 4, .model_name = "Neuron M403", .combination_count = 2, .combinations = NEURONSPI_MODEL_M403_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "M503", .name_length = 4, .model_name = "M503", + {.eeprom_length = 4, .eeprom_name = "M503", .name_length = 4, .model_name = "Neuron M503", .combination_count = 2, .combinations = NEURONSPI_MODEL_M503_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "M603", .name_length = 4, .model_name = "M603", + {.eeprom_length = 4, .eeprom_name = "M603", .name_length = 4, .model_name = "Neuron M603", .combination_count = 2, .combinations = NEURONSPI_MODEL_M603_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "L203", .name_length = 4, .model_name = "L203", + {.eeprom_length = 4, .eeprom_name = "L203", .name_length = 4, .model_name = "Neuron L203", .combination_count = 3, .combinations = NEURONSPI_MODEL_L203_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "L303", .name_length = 4, .model_name = "L303", + {.eeprom_length = 4, .eeprom_name = "L303", .name_length = 4, .model_name = "Neuron L303", .combination_count = 3, .combinations = NEURONSPI_MODEL_L303_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "L403", .name_length = 4, .model_name = "L403", + {.eeprom_length = 4, .eeprom_name = "L403", .name_length = 4, .model_name = "Neuron L403", .combination_count = 3, .combinations = NEURONSPI_MODEL_L403_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "L503", .name_length = 4, .model_name = "L503", + {.eeprom_length = 4, .eeprom_name = "L503", .name_length = 4, .model_name = "Neuron L503", .combination_count = 3, .combinations = NEURONSPI_MODEL_L503_HW_DEFINITION_BOARD}, - {.eeprom_length = 4, .eeprom_name = "L513", .name_length = 4, .model_name = "L513", + {.eeprom_length = 4, .eeprom_name = "L513", .name_length = 4, .model_name = "Neuron L513", .combination_count = 3, .combinations = NEURONSPI_MODEL_L513_HW_DEFINITION_BOARD} }; @@ -1579,9 +1579,13 @@ int neuronspi_regmap_hw_reg_read(void *context, unsigned int reg, unsigned int * struct neuronspi_driver_data *n_spi = spi_get_drvdata(spi); u8 *inp_buf; u8 *outp_buf; - int write_length; + int write_length, i; write_length = neuronspi_spi_compose_single_register_read(reg, &inp_buf, &outp_buf); - neuronspi_spi_send_message(spi, inp_buf, outp_buf, write_length, n_spi->ideal_frequency, 25, 1); + if (neuronspi_spi_send_message(spi, inp_buf, outp_buf, write_length, n_spi->ideal_frequency, 25, 1)) { + for (i = 0; i < write_length; i++) { + outp_buf[i] = 0; + } + } memcpy(val, &outp_buf[NEURONSPI_HEADER_LENGTH], sizeof(u16)); kfree(inp_buf); kfree(outp_buf); @@ -1600,9 +1604,13 @@ int neuronspi_regmap_hw_reg_write(void *context, unsigned int reg, unsigned int struct neuronspi_driver_data *n_spi = spi_get_drvdata(spi); u8 *inp_buf; u8 *outp_buf; - int write_length; + int write_length, i; write_length = neuronspi_spi_compose_single_register_write(reg, &inp_buf, &outp_buf, (val >> 8)); - neuronspi_spi_send_message(spi, inp_buf, outp_buf, write_length, n_spi->ideal_frequency, 25, 1); + if (neuronspi_spi_send_message(spi, inp_buf, outp_buf, write_length, n_spi->ideal_frequency, 25, 1)) { + for (i = 0; i < write_length; i++) { + outp_buf[i] = 0; + } + } memcpy(&val, &outp_buf[NEURONSPI_HEADER_LENGTH], sizeof(u16)); kfree(inp_buf); kfree(outp_buf); @@ -1735,7 +1743,7 @@ int neuronspi_regmap_hw_read(void *context, const void *reg_buf, size_t reg_size struct neuronspi_driver_data *n_spi; u8 *inp_buf; u8 *outp_buf; - int i, write_length; + int i, j, write_length; int block_counter = 0; if (context == NULL) { return 0; @@ -1749,7 +1757,11 @@ int neuronspi_regmap_hw_read(void *context, const void *reg_buf, size_t reg_size // Check for continuity and read the largest possible continuous block if (block_counter == ((reg_size / 2) - 1) || ((mb_reg_buf[i] + 1) != mb_reg_buf[i + 1])) { write_length = neuronspi_spi_compose_multiple_register_read(block_counter + 1, mb_reg_buf[i - block_counter], &inp_buf, &outp_buf); - neuronspi_spi_send_message(spi, inp_buf, outp_buf, write_length, n_spi->ideal_frequency, 125, 1); + if (neuronspi_spi_send_message(spi, inp_buf, outp_buf, write_length, n_spi->ideal_frequency, 125, 1)) { + for (j = 0; j < write_length; j++) { + outp_buf[j] = 0; + } + } memcpy(&mb_val_buf[i - block_counter], &outp_buf[NEURONSPI_HEADER_LENGTH], (block_counter + 1) * 2); kfree(inp_buf); kfree(outp_buf); diff --git a/modules/unipi/src/unipi_spi.c b/modules/unipi/src/unipi_spi.c index c4e6abf..6fc873f 100644 --- a/modules/unipi/src/unipi_spi.c +++ b/modules/unipi/src/unipi_spi.c @@ -667,7 +667,7 @@ static s32 neuronspi_spi_watchdog(void *data) -void neuronspi_spi_send_message(struct spi_device* spi_dev, u8 *send_buf, u8 *recv_buf, s32 len, s32 freq, s32 delay, s32 send_header) +int neuronspi_spi_send_message(struct spi_device* spi_dev, u8 *send_buf, u8 *recv_buf, s32 len, s32 freq, s32 delay, s32 send_header) { s32 i = 0; u16 recv_crc1 = 0; diff --git a/modules/unipi/src/unipi_spi.h b/modules/unipi/src/unipi_spi.h index 9edb27d..18fef46 100644 --- a/modules/unipi/src/unipi_spi.h +++ b/modules/unipi/src/unipi_spi.h @@ -168,7 +168,7 @@ s32 char_unregister_driver(void); irqreturn_t neuronspi_spi_irq(s32 irq, void *dev_id); s32 neuronspi_spi_probe(struct spi_device *spi); s32 neuronspi_spi_remove(struct spi_device *spi); -void neuronspi_spi_send_message(struct spi_device *spi_dev, u8 *send_buf, u8 *recv_buf, s32 len, s32 freq, s32 delay, s32 send_header); +int neuronspi_spi_send_message(struct spi_device *spi_dev, u8 *send_buf, u8 *recv_buf, s32 len, s32 freq, s32 delay, s32 send_header); s32 neuronspi_spi_uart_write(struct spi_device *spi, u8 *send_buf, u8 length, u8 uart_index); void neuronspi_spi_uart_read(struct spi_device* spi_dev, u8 *send_buf, u8 *recv_buf, s32 len, u8 uart_index); void neuronspi_spi_set_irqs(struct spi_device* spi_dev, u16 to); diff --git a/modules/unipi/src/unipi_sysfs.c b/modules/unipi/src/unipi_sysfs.c index 56f422a..3bc08ba 100644 --- a/modules/unipi/src/unipi_sysfs.c +++ b/modules/unipi/src/unipi_sysfs.c @@ -31,6 +31,17 @@ static ssize_t neuronspi_show_model(struct device *dev, struct device_attribute return ret; } +static ssize_t neuronspi_show_driver_version(struct device *dev, struct device_attribute *attr, char *buf) +{ + ssize_t ret = 0; +#ifdef NEURONSPI_MAJOR_VERSIONSTRING + ret = scnprintf(buf, 255, "%s\n", NEURONSPI_MAJOR_VERSIONSTRING); +#else + ret = scnprintf(buf, 255, "%s\n", "Unspecified Driver Version"); +#endif + return ret; +} + static ssize_t neuronspi_show_eeprom(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t ret = 0; @@ -925,6 +936,7 @@ err_end: static DEVICE_ATTR(model_name, 0440, neuronspi_show_model, NULL); static DEVICE_ATTR(sys_eeprom_name, 0440, neuronspi_show_eeprom, NULL); +static DEVICE_ATTR(driver_version, 0440, neuronspi_show_driver_version, NULL); static DEVICE_ATTR(register_read, 0660, neuronspi_show_regmap, neuronspi_store_regmap); static DEVICE_ATTR(sys_board_serial, 0440, neuronspi_spi_show_serial, NULL); static DEVICE_ATTR(sys_board_name, 0440, neuronspi_spi_show_board, NULL); @@ -965,6 +977,7 @@ static DEVICE_ATTR(mode_ao_type_b, 0660, neuronspi_iio_show_secondary_ao_mode, n static struct attribute *neuron_plc_attrs[] = { &dev_attr_model_name.attr, &dev_attr_sys_eeprom_name.attr, + &dev_attr_driver_version.attr, NULL, };