From 97238092e739f090a8b72ce539fc28b66d41a332 Mon Sep 17 00:00:00 2001 From: Tom Knot Date: Mon, 5 Mar 2018 20:54:28 +0100 Subject: [PATCH] - Added the neuron-probe-always-succeeds sysfs flag - Improved checks for sysfs attribute creation to prevent possible leaks - Added new overlay source and binaries to include the probe flag (it does not have to be included) - Removed unnecessary printk statement --- .settings/org.eclipse.cdt.codan.core.prefs | 3 +- device_tree/neuron-spi-new.dtbo | Bin 3839 -> 3928 bytes device_tree/neuron-spi-new.dts | 150 +++++++++++---------- modules/unipi/src/unipi_common.h | 1 + modules/unipi/src/unipi_spi.c | 23 ++-- modules/unipi/src/unipi_sysfs.c | 72 +++++----- 6 files changed, 129 insertions(+), 120 deletions(-) diff --git a/.settings/org.eclipse.cdt.codan.core.prefs b/.settings/org.eclipse.cdt.codan.core.prefs index cf61d79..cf4eae3 100644 --- a/.settings/org.eclipse.cdt.codan.core.prefs +++ b/.settings/org.eclipse.cdt.codan.core.prefs @@ -66,8 +66,9 @@ org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params= org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused static function\\")",macro\=>true} org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning -org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused variable declaration in file scope\\")",macro\=>true,exceptions\=>("@(\#)","$Id")} +org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused variable declaration in file scope\\")",macro\=>false,exceptions\=>("@(\#)","$Id")} org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Symbol is not resolved\\")"} org.eclipse.cdt.qt.core.qtproblem=Warning org.eclipse.cdt.qt.core.qtproblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>false,RUN_ON_INC_BUILD\=>false,RUN_ON_FILE_OPEN\=>true,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>null} +useParentScope=false diff --git a/device_tree/neuron-spi-new.dtbo b/device_tree/neuron-spi-new.dtbo index 8f96f1d7b599ead3c64709ea676a9db9b97856c3..6d5a204204e2bcf415a3b2428ad334eac140e460 100644 GIT binary patch delta 860 zcmew_dqYm+0`I@K3=I4c3=9kw3=F(WfV2h>3j(nK5CZ|@7NB^}M2!-bdu#W-pSU2v z21J7}P?8yl4S?7V%I5%SfU?<<*b*@IWF1C(AzmPlp)@bEAX6tVwX`Tdk705pV=>tL z$sZV<8COhJVZy4akO`{l1(P%D3Xmz26_~BDnU~27Rr!D!rc#2%1L_6w$<-`|5bHLu z_<$LcSoIl?PBvhb7Ca9$l@W+RUSk2`yOU#BwH1#7S<*~tkNfc9+ z2pdF|7+zHkZ2peVfht&%i*?frGV_bAOc+3+npBjWt5cAfS8N3ebcpQ=KpGSk2(^Z0 zV8xRK*u_P^qsW*TKxAy#rFH+K$QW6mSpZB85c3s*!NEScgOnk7 zI+XS(UMe2z(H=ZXPo*dERK$}Y_E7LqpMSwCgNiCKNu2QFAaC$=ph3I7#zA-$4pAhE z3u~(@#d4{D8&HZ9@()!S}qIee?Vto7R0CcOhYsOn?2 zIxe(<4)dH66= z-SLYY+I)HFeW|cg9#08=Ka2(3%|A_rk+iJ5Tb*AXEES6E^ji1QdeP)fC0o2BqiiPd zHF}7b#QH}^vn_ra1`(2GZhnoYfni15;lIFh(6A?%g9w7{;Cj#khg2UP1#Re)>Vnh| zsW_U31zF4+G0Ye)ydjl=Ss8yf98}C_(1orUheg?I#&ls#s%>)%K1nrUg^v5JG{6qd z*>TvzEjxxM#@Qyn8N>f8{8S7-=I3DeF<+O#F%RiA2Lv8;KX)fHO*!DXV6acA6A$bo IEQD_#0Dg; frag0: __overlay__ { #address-cells = <1>; #size-cells = <0>; status = "okay"; - pinctrl-0 = <&spi0_pins &spi0_cs_pins>; - cs-gpios = <&gpio 8 1>, <&gpio 7 1>, <&gpio 24 1>, <&gpio 25 1>; - neuronspi0: neuronspi@0 { - compatible = "neuronspi"; - reg = <1>; - #address-cells = <1>; - #size-cells = <0>; - spi-max-frequency = <12000000>; - pinctrl-0 = <&neuron_0_irq_pin>; - pinctrl-names = "default"; - interrupt-parent = <&gpio>; - interrupts = <27 0x1>; - status = "okay"; - }; - neuronspi1: neuronspi@1 { - compatible = "neuronspi"; - reg = <2>; - #address-cells = <1>; - #size-cells = <0>; - spi-max-frequency = <1200000>; - pinctrl-0 = <&neuron_1_irq_pin>; - pinctrl-names = "default"; - interrupt-parent = <&gpio>; - interrupts = <23 0x1>; - status = "okay"; - }; - neuronspi2: neuronspi@2 { - compatible = "neuronspi"; - reg = <3>; - #address-cells = <1>; - #size-cells = <0>; - spi-max-frequency = <1200000>; - pinctrl-names = "default"; - pinctrl-0 = <&neuron_2_irq_pin>; - interrupt-parent = <&gpio>; - interrupts = <22 0x1>; - status = "okay"; - }; + pinctrl-0 = <&spi0_pins &spi0_cs_pins>; + cs-gpios = <&gpio 8 1>, <&gpio 7 1>, <&gpio 24 1>, <&gpio 25 1>; + neuronspi0: neuronspi@0 { + compatible = "unipi,neuron"; + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + spi-max-frequency = <12000000>; + pinctrl-0 = <&neuron_0_irq_pin>; + pinctrl-names = "default"; + interrupt-parent = <&gpio>; + interrupts = <27 0x1>; + status = "okay"; + neuron-board-index = <0>; + neuron-probe-always-succeeds = <0>; + }; + neuronspi1: neuronspi@1 { + compatible = "unipi,neuron"; + reg = <2>; + #address-cells = <1>; + #size-cells = <0>; + spi-max-frequency = <1200000>; + pinctrl-0 = <&neuron_1_irq_pin>; + pinctrl-names = "default"; + interrupt-parent = <&gpio>; + interrupts = <23 0x1>; + status = "okay"; + neuron-board-index = <1>; + neuron-probe-always-succeeds = <0>; + }; + neuronspi2: neuronspi@2 { + compatible = "unipi,neuron"; + reg = <3>; + #address-cells = <1>; + #size-cells = <0>; + spi-max-frequency = <1200000>; + pinctrl-names = "default"; + pinctrl-0 = <&neuron_2_irq_pin>; + interrupt-parent = <&gpio>; + interrupts = <22 0x1>; + status = "okay"; + neuron-board-index = <2>; + neuron-probe-always-succeeds = <0>; + }; }; }; fragment@1 { target = <&spidev0>; - __overlay__ { - status = "okay"; - }; + __overlay__ { + status = "okay"; + }; }; fragment@2 { target = <&spidev1>; - __overlay__ { - status = "disabled"; - }; + __overlay__ { + status = "disabled"; + }; }; fragment@3 { target = <&gpio>; - __overlay__ { - spi0_cs_pins { - brcm,pins = <8 7 24 25>; - brcm,function = <1>; - brcm,pull = <0>; - }; - neuron_0_irq_pin: neuron_0_irq_pin { - brcm,pins = <27>; - brcm,function = <0>; - brcm,pull = <1>; + __overlay__ { + spi0_cs_pins { + brcm,pins = <8 7 24 25>; + brcm,function = <1>; + brcm,pull = <0>; + }; + neuron_0_irq_pin: neuron_0_irq_pin { + brcm,pins = <27>; + brcm,function = <0>; + brcm,pull = <1>; + }; + neuron_1_irq_pin: neuron_1_irq_pin { + brcm,pins = <23>; + brcm,function = <0>; + brcm,pull = <1>; + }; + neuron_2_irq_pin: neuron_2_irq_pin { + brcm,pins = <22>; + brcm,function = <0>; + brcm,pull = <1>; + }; }; - neuron_1_irq_pin: neuron_1_irq_pin { - brcm,pins = <23>; - brcm,function = <0>; - brcm,pull = <1>; - }; - neuron_2_irq_pin: neuron_2_irq_pin { - brcm,pins = <22>; - brcm,function = <0>; - brcm,pull = <1>; - }; - }; - }; __overrides__ { cs0_pin = <&frag0>,"cs-gpios:4", <&spi0_cs_pins>, "brcm,pins:0"; - cs1_pin = <&frag0>,"cs-gpios:16", <&spi0_cs_pins>,"brcm,pins:4"; - cs2_pin = <&frag0>,"cs-gpios:40", <&spi0_cs_pins>,"brcm,pins:12"; - cs3_pin = <&frag0>,"cs-gpios:28", <&spi0_cs_pins>,"brcm,pins:8"; - neuron_irq_0 = <&neuronspi0>,"interrupts:0", <&neuron_0_irq_pin>,"brcm,pins:0"; - neuron_irq_1 = <&neuronspi1>,"interrupts:0", <&neuron_1_irq_pin>,"brcm,pins:0"; - neuron_irq_2 = <&neuronspi2>,"interrupts:0", <&neuron_2_irq_pin>,"brcm,pins:0"; + cs1_pin = <&frag0>,"cs-gpios:16", <&spi0_cs_pins>,"brcm,pins:4"; + cs2_pin = <&frag0>,"cs-gpios:40", <&spi0_cs_pins>,"brcm,pins:12"; + cs3_pin = <&frag0>,"cs-gpios:28", <&spi0_cs_pins>,"brcm,pins:8"; + neuron_irq_0 = <&neuronspi0>,"interrupts:0", <&neuron_0_irq_pin>,"brcm,pins:0"; + neuron_irq_1 = <&neuronspi1>,"interrupts:0", <&neuron_1_irq_pin>,"brcm,pins:0"; + neuron_irq_2 = <&neuronspi2>,"interrupts:0", <&neuron_2_irq_pin>,"brcm,pins:0"; }; }; diff --git a/modules/unipi/src/unipi_common.h b/modules/unipi/src/unipi_common.h index f7646a3..a1bd74f 100644 --- a/modules/unipi/src/unipi_common.h +++ b/modules/unipi/src/unipi_common.h @@ -172,6 +172,7 @@ struct neuronspi_driver_data struct neuronspi_board_regstart_table *regstart_table; struct spinlock sysfs_regmap_lock; char platform_name[sizeof("io_group0")]; + u32 probe_always_succeeds; u8 *send_buf; u8 *recv_buf; u8 *first_probe_reply; diff --git a/modules/unipi/src/unipi_spi.c b/modules/unipi/src/unipi_spi.c index d58c5c4..e9f3490 100644 --- a/modules/unipi/src/unipi_spi.c +++ b/modules/unipi/src/unipi_spi.c @@ -956,7 +956,7 @@ s32 neuronspi_spi_probe(struct spi_device *spi) return -ENODEV; } of_property_read_u32_array(spi->dev.of_node, "neuron-board-index", &(n_spi->neuron_index), 1); - //print_device_tree_node(spi->dev.of_node->parent, 0); + of_property_read_u32_array(spi->dev.of_node, "neuron-probe-always-succeeds", &(n_spi->probe_always_succeeds), 1); devtype = (struct neuronspi_devtype *)of_id->data; #if NEURONSPI_DETAILED_DEBUG > 0 printk(KERN_INFO "DEVICE TREE NODE FOUND %d\n", n_spi->neuron_index); @@ -1021,7 +1021,7 @@ s32 neuronspi_spi_probe(struct spi_device *spi) } } } - } else { + } else if (!n_spi->probe_always_succeeds) { ret = -5; kfree(n_spi); printk(KERN_INFO "NEURONSPI: Probe did not detect a valid Neuron device on CS %d\n", spi->chip_select); @@ -1066,10 +1066,11 @@ reg1001: %x, reg1002: %x, reg1003: %x, reg1004: %x\n", n_spi->first_probe_reply[15] << 8 | n_spi->first_probe_reply[14], n_spi->first_probe_reply[17] << 8 | n_spi->first_probe_reply[16], n_spi->first_probe_reply[19] << 8 | n_spi->first_probe_reply[18]); } - printk(KERN_INFO "NEURONSPI: Neuron device %s on CS %d uses SPI communication freq. %d Hz\n", - NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->combination_name, - spi->chip_select, n_spi->ideal_frequency); - + if (n_spi->combination_id != 0xFF) { + printk(KERN_INFO "NEURONSPI: Neuron device %s on CS %d uses SPI communication freq. %d Hz\n", + NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->combination_name, + spi->chip_select, n_spi->ideal_frequency); + } n_spi->reg_map = regmap_init(&(spi->dev), &neuronspi_regmap_bus, spi, &neuronspi_regmap_config_default); spin_lock_init(&n_spi->sysfs_regmap_lock); if (n_spi->features) { @@ -1134,7 +1135,6 @@ reg1001: %x, reg1002: %x, reg1003: %x, reg1004: %x\n", neuronspi_s_dev[n_spi->neuron_index] = spi; spi_set_drvdata(neuronspi_s_dev[n_spi->neuron_index], n_spi); if (neuronspi_probe_count == NEURONSPI_MAX_DEVS) { - printk(KERN_INFO "NEURONSPI: MAXPROBECOUNT\n"); neuronspi_model_id = neuronspi_find_model_id(neuronspi_probe_count); } spin_unlock(&neuronspi_probe_spinlock); @@ -1148,7 +1148,9 @@ reg1001: %x, reg1002: %x, reg1003: %x, reg1004: %x\n", n_spi->platform_name[8] = n_spi->neuron_index + '1'; n_spi->board_device = platform_device_alloc(n_spi->platform_name, -1); n_spi->board_device->dev.parent = &(neuron_plc_dev->dev); - n_spi->board_device->dev.groups = neuron_board_attr_groups; + if (n_spi->combination_id != 0xFF) { + n_spi->board_device->dev.groups = neuron_board_attr_groups; + } n_spi->board_device->dev.driver = &neuronspi_spi_driver.driver; platform_device_add(n_spi->board_device); platform_set_drvdata(n_spi->board_device, n_spi); @@ -1556,7 +1558,8 @@ static s32 __init neuronspi_init(void) } return ret; } -__attribute__((unused)) module_init(neuronspi_init); + +module_init(neuronspi_init); static void __exit neuronspi_exit(void) { @@ -1580,7 +1583,7 @@ static void __exit neuronspi_exit(void) kfree(neuronspi_spi_w_spinlock); printk(KERN_INFO "NEURONSPI: SPI Driver Unregistered\n"); } -__attribute__((unused)) module_exit(neuronspi_exit); +module_exit(neuronspi_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Tomas Knot "); diff --git a/modules/unipi/src/unipi_sysfs.c b/modules/unipi/src/unipi_sysfs.c index e82f957..484ea9e 100644 --- a/modules/unipi/src/unipi_sysfs.c +++ b/modules/unipi/src/unipi_sysfs.c @@ -47,7 +47,7 @@ static ssize_t neuronspi_spi_show_serial(struct device *dev, struct device_attri struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->sys_serial_num, val); regmap_read(n_spi->reg_map, n_spi->regstart_table->sys_serial_num + 1, &(val[1])); ret = scnprintf(buf, 255, "%d\n", val[0]); @@ -62,7 +62,7 @@ static ssize_t neuronspi_spi_show_hw_version(struct device *dev, struct device_a struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->sys_hw_ver, &val); ret = scnprintf(buf, 255, "%x.%x\n", (val & 0xF0) >> 4, val & 0xF); } @@ -76,7 +76,7 @@ static ssize_t neuronspi_spi_show_hw_flash_version(struct device *dev, struct de struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->sys_hw_flash_ver, &val); ret = scnprintf(buf, 255, "%x.%x\n", (val & 0xF0) >> 4, val & 0xF); } @@ -90,7 +90,7 @@ static ssize_t neuronspi_spi_show_fw_version(struct device *dev, struct device_a struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->sys_sw_ver, &val); ret = scnprintf(buf, 255, "%x.%x%x\n", (val & 0xF00) >> 8, (val & 0xF0) >> 4, val & 0xF); } @@ -104,7 +104,7 @@ static ssize_t neuronspi_spi_show_uart_queue_length(struct device *dev, struct d struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map && n_spi->regstart_table->uart_queue_reg) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->regstart_table->uart_queue_reg) { regmap_read(n_spi->reg_map, n_spi->regstart_table->uart_queue_reg, &val); ret = scnprintf(buf, 255, "%d\n", val); } @@ -118,7 +118,7 @@ static ssize_t neuronspi_spi_show_uart_config(struct device *dev, struct device_ struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map && n_spi->regstart_table->uart_conf_reg) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->regstart_table->uart_conf_reg) { regmap_read(n_spi->reg_map, n_spi->regstart_table->uart_conf_reg, &val); ret = scnprintf(buf, 255, "%x\n", val); } @@ -134,7 +134,7 @@ static ssize_t neuronspi_spi_store_uart_config(struct device *dev, struct device n_spi = platform_get_drvdata(plat); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map && n_spi->regstart_table->uart_conf_reg) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->regstart_table->uart_conf_reg) { regmap_write(n_spi->reg_map, n_spi->regstart_table->uart_conf_reg, val); } err_end: @@ -148,7 +148,7 @@ static ssize_t neuronspi_spi_show_watchdog_status(struct device *dev, struct dev struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->wd_val_reg, &val); ret = scnprintf(buf, 255, "%x\n", val); } @@ -164,7 +164,7 @@ static ssize_t neuronspi_spi_store_watchdog_status(struct device *dev, struct de n_spi = platform_get_drvdata(plat); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->wd_val_reg, val); } err_end: @@ -178,7 +178,7 @@ static ssize_t neuronspi_spi_show_watchdog_timeout(struct device *dev, struct de struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->wd_timeout_reg, &val); ret = scnprintf(buf, 255, "%d\n", val); } @@ -194,7 +194,7 @@ static ssize_t neuronspi_spi_store_watchdog_timeout(struct device *dev, struct d n_spi = platform_get_drvdata(plat); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->wd_timeout_reg, val); } err_end: @@ -210,7 +210,7 @@ static ssize_t neuronspi_spi_gpio_show_pwm_presc(struct device *dev, struct devi struct platform_device *plat = to_platform_device(dev); n_do = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_do->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->do_pwm_ps_reg, &val); ret = scnprintf(buf, 255, "%d\n", val); } @@ -228,7 +228,7 @@ static ssize_t neuronspi_spi_gpio_store_pwm_presc(struct device *dev, struct dev n_spi = spi_get_drvdata(n_do->spi); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->do_pwm_ps_reg, val); } err_end: @@ -244,7 +244,7 @@ static ssize_t neuronspi_spi_gpio_show_pwm_freq(struct device *dev, struct devic struct platform_device *plat = to_platform_device(dev); n_do = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_do->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->do_pwm_c_reg, &val); ret = scnprintf(buf, 255, "%d\n", val); } @@ -262,7 +262,7 @@ static ssize_t neuronspi_spi_gpio_store_pwm_freq(struct device *dev, struct devi n_spi = spi_get_drvdata(n_do->spi); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->do_pwm_c_reg, val); } err_end: @@ -278,7 +278,7 @@ static ssize_t neuronspi_spi_gpio_show_pwm_cycle(struct device *dev, struct devi struct platform_device *plat = to_platform_device(dev); n_do = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_do->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->do_pwm_reg + n_do->do_index, &val); ret = scnprintf(buf, 255, "%d\n", val); } @@ -296,7 +296,7 @@ static ssize_t neuronspi_spi_gpio_store_pwm_cycle(struct device *dev, struct dev n_spi = spi_get_drvdata(n_do->spi); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->do_pwm_reg + n_do->do_index, val); } err_end: @@ -312,7 +312,7 @@ static ssize_t neuronspi_spi_gpio_di_show_counter(struct device *dev, struct dev struct platform_device *plat = to_platform_device(dev); n_di = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_di->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + (2 * n_di->di_index), &val); ret = scnprintf(buf, 255, "%d\n", val); } @@ -330,7 +330,7 @@ static ssize_t neuronspi_spi_gpio_di_store_counter(struct device *dev, struct de n_spi = spi_get_drvdata(n_di->spi); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->di_counter_reg + (2 * n_di->di_index), val); } err_end: @@ -346,7 +346,7 @@ static ssize_t neuronspi_spi_gpio_di_show_debounce(struct device *dev, struct de struct platform_device *plat = to_platform_device(dev); n_di = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_di->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map && n_spi->features && n_spi->features->di_count > n_di->di_index) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->features && n_spi->features->di_count > n_di->di_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_deboun_reg + n_di->di_index, &val); ret = scnprintf(buf, 255, "%d\n", val); } @@ -364,7 +364,7 @@ static ssize_t neuronspi_spi_gpio_di_store_debounce(struct device *dev, struct d n_spi = spi_get_drvdata(n_di->spi); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map && n_spi->features && n_spi->features->di_count > n_di->di_index) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map && n_spi->features && n_spi->features->di_count > n_di->di_index) { regmap_write(n_spi->reg_map, n_spi->regstart_table->di_deboun_reg + n_di->di_index, val); } err_end: @@ -380,7 +380,7 @@ static ssize_t neuronspi_spi_gpio_di_show_value(struct device *dev, struct devic struct platform_device *plat = to_platform_device(dev); n_di = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_di->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->di_count > n_di->di_index) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->di_count > n_di->di_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_val_reg + (n_di->di_index / 16), &val); val &= 0x1 << (n_di->di_index % 15); val = val >> (n_di->di_index % 15); @@ -398,7 +398,7 @@ static ssize_t neuronspi_spi_gpio_do_show_value(struct device *dev, struct devic struct platform_device *plat = to_platform_device(dev); n_do = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_do->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->do_count > n_do->do_index) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->do_count > n_do->do_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->do_index / 16), &val); val &= 0x1 << (n_do->do_index % 15); val = val >> (n_do->do_index % 15); @@ -422,7 +422,7 @@ static ssize_t neuronspi_spi_gpio_do_store_value(struct device *dev, struct devi if (inp > 1 || inp < 0) { goto err_end; } - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->do_count > n_do->do_index) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->do_count > n_do->do_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->do_val_reg + (n_do->do_index / 16), &val); val &= ~(0x1 << (n_do->do_index % 15)); val |= inp << (n_do->do_index % 15); @@ -441,7 +441,7 @@ static ssize_t neuronspi_spi_gpio_ro_show_value(struct device *dev, struct devic struct platform_device *plat = to_platform_device(dev); n_ro = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_ro->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ro_count > n_ro->ro_index) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ro_count > n_ro->ro_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->ro_index / 16), &val); val &= 0x1 << (n_ro->ro_index % 15); val = val >> (n_ro->ro_index % 15); @@ -465,7 +465,7 @@ static ssize_t neuronspi_spi_gpio_ro_store_value(struct device *dev, struct devi if (inp > 1 || inp < 0) { goto err_end; } - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ro_count > n_ro->ro_index) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ro_count > n_ro->ro_index) { regmap_read(n_spi->reg_map, n_spi->regstart_table->ro_val_reg + (n_ro->ro_index / 16), &val); val &= ~(0x1 << (n_ro->ro_index % 15)); val |= inp << (n_ro->ro_index % 15); @@ -485,7 +485,7 @@ static ssize_t neuronspi_spi_gpio_show_ds_enable(struct device *dev, struct devi struct platform_device *plat = to_platform_device(dev); n_di = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_di->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ds_count) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_direct_reg + (n_di->di_index / 16), &val); val &= 0x1 << (n_di->di_index % 15); val = val >> (n_di->di_index % 15); @@ -503,7 +503,7 @@ static ssize_t neuronspi_spi_gpio_show_ds_toggle(struct device *dev, struct devi struct platform_device *plat = to_platform_device(dev); n_di = platform_get_drvdata(plat); n_spi = spi_get_drvdata(n_di->spi); - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ds_count) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->di_index / 16), &val); val &= 0x1 << (n_di->di_index % 15); val = val >> (n_di->di_index % 15); @@ -570,7 +570,7 @@ static ssize_t neuronspi_spi_gpio_store_ds_toggle(struct device *dev, struct dev if (inp > 1 || inp < 0) { goto err_end; } - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ds_count) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_toggle_reg + (n_di->di_index / 16), &val); val &= ~(0x1 << (n_di->di_index % 15)); val |= inp << (n_di->di_index % 15); @@ -595,7 +595,7 @@ static ssize_t neuronspi_spi_gpio_store_ds_polarity(struct device *dev, struct d if (inp > 1 || inp < 0) { goto err_end; } - if (n_spi && n_spi->combination_id != -1 && n_spi->features && n_spi->features->ds_count) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->features && n_spi->features->ds_count) { regmap_read(n_spi->reg_map, n_spi->regstart_table->di_polar_reg + (n_di->di_index / 16), &val); val &= ~(0x1 << (n_di->di_index % 15)); val |= inp << (n_di->di_index % 15); @@ -645,7 +645,7 @@ static ssize_t neuronspi_spi_show_board(struct device *dev, struct device_attrib struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi->combination_id != -1 && n_spi->combination_id < NEURONSPI_BOARDTABLE_LEN) { + if (n_spi->combination_id != 0xFF && n_spi->combination_id < NEURONSPI_BOARDTABLE_LEN) { ret = scnprintf(buf, 255, "%s\n", NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->combination_name); } return ret; @@ -657,7 +657,7 @@ static ssize_t neuronspi_spi_show_lboard_id(struct device *dev, struct device_at struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi->combination_id != -1 && n_spi->combination_id < NEURONSPI_BOARDTABLE_LEN) { + if (n_spi->combination_id != 0xFF && n_spi->combination_id < NEURONSPI_BOARDTABLE_LEN) { ret = scnprintf(buf, 255, "%d\n", NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->lower_board_id); } return ret; @@ -669,7 +669,7 @@ static ssize_t neuronspi_spi_show_uboard_id(struct device *dev, struct device_at struct neuronspi_driver_data *n_spi; struct platform_device *plat = to_platform_device(dev); n_spi = platform_get_drvdata(plat); - if (n_spi->combination_id != -1 && n_spi->combination_id < NEURONSPI_BOARDTABLE_LEN) { + if (n_spi->combination_id != 0xFF && n_spi->combination_id < NEURONSPI_BOARDTABLE_LEN) { ret = scnprintf(buf, 255, "%d\n", NEURONSPI_BOARDTABLE[n_spi->combination_id].definition->upper_board_id); } return ret; @@ -825,7 +825,7 @@ static ssize_t neuronspi_iio_store_primary_ai_mode(struct device *dev, struct de struct neuronspi_driver_data *n_spi = spi_get_drvdata(spi); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->stm_ai_mode_reg, val); } err_end: @@ -884,7 +884,7 @@ static ssize_t neuronspi_iio_store_secondary_ai_mode(struct device *dev, struct struct neuronspi_driver_data *n_spi = spi_get_drvdata(spi); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->sec_ai_mode_reg + ai_data->index, val); } err_end: @@ -912,7 +912,7 @@ static ssize_t neuronspi_iio_store_secondary_ao_mode(struct device *dev, struct struct neuronspi_driver_data *n_spi = spi_get_drvdata(spi); err = kstrtouint(buf, 0, &val); if (err < 0) goto err_end; - if (n_spi && n_spi->combination_id != -1 && n_spi->reg_map) { + if (n_spi && n_spi->combination_id != 0xFF && n_spi->reg_map) { regmap_write(n_spi->reg_map, n_spi->regstart_table->sec_ao_mode_reg + ao_data->index, val); } err_end: -- 2.34.1