diff mbox series

[1/2] iio: chemical: bme680: Add device-tree support

Message ID 20190111193141.20607-1-sebastien.bourdelin@gmail.com (mailing list archive)
State New, archived
Headers show
Series [1/2] iio: chemical: bme680: Add device-tree support | expand

Commit Message

Sebastien Bourdelin Jan. 11, 2019, 7:31 p.m. UTC
This commit allow the driver to work with device-tree.

Signed-off-by: Sebastien Bourdelin <sebastien.bourdelin@gmail.com>
---
 drivers/iio/chemical/bme680_i2c.c | 7 +++++++
 drivers/iio/chemical/bme680_spi.c | 7 +++++++
 2 files changed, 14 insertions(+)

Comments

kernel test robot Jan. 13, 2019, 10:59 p.m. UTC | #1
Hi Sebastien,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on iio/togreg]
[also build test ERROR on v5.0-rc1 next-20190111]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Sebastien-Bourdelin/iio-chemical-bme680-Add-device-tree-support/20190114-063618
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: i386-randconfig-x007-201902 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/acpi.h:41:0,
                    from drivers/iio/chemical/bme680_spi.c:7:
   include/linux/module.h:213:1: error: expected ',' or ';' before 'extern'
    extern typeof(name) __mod_##type##__##name##_device_table  \
    ^
>> drivers/iio/chemical/bme680_spi.c:117:1: note: in expansion of macro 'MODULE_DEVICE_TABLE'
    MODULE_DEVICE_TABLE(of, bme680_of_spi_match);
    ^~~~~~~~~~~~~~~~~~~
>> drivers/iio/chemical/bme680_spi.c:123:22: error: implicit declaration of function 'of_match_ptr'; did you mean 'hash_ptr'? [-Werror=implicit-function-declaration]
      .of_match_table  = of_match_ptr(bme680_of_spi_match),
                         ^~~~~~~~~~~~
                         hash_ptr
>> drivers/iio/chemical/bme680_spi.c:123:22: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
   drivers/iio/chemical/bme680_spi.c:123:22: note: (near initialization for 'bme680_spi_driver.driver.of_match_table')
>> drivers/iio/chemical/bme680_spi.c:123:22: error: initializer element is not constant
   drivers/iio/chemical/bme680_spi.c:123:22: note: (near initialization for 'bme680_spi_driver.driver.of_match_table')
   cc1: some warnings being treated as errors

vim +123 drivers/iio/chemical/bme680_spi.c

   > 7	#include <linux/acpi.h>
     8	#include <linux/module.h>
     9	#include <linux/regmap.h>
    10	#include <linux/spi/spi.h>
    11	
    12	#include "bme680.h"
    13	
    14	static int bme680_regmap_spi_write(void *context, const void *data,
    15					   size_t count)
    16	{
    17		struct spi_device *spi = context;
    18		u8 buf[2];
    19	
    20		memcpy(buf, data, 2);
    21		/*
    22		 * The SPI register address (= full register address without bit 7)
    23		 * and the write command (bit7 = RW = '0')
    24		 */
    25		buf[0] &= ~0x80;
    26	
    27		return spi_write_then_read(spi, buf, 2, NULL, 0);
    28	}
    29	
    30	static int bme680_regmap_spi_read(void *context, const void *reg,
    31					  size_t reg_size, void *val, size_t val_size)
    32	{
    33		struct spi_device *spi = context;
    34	
    35		return spi_write_then_read(spi, reg, reg_size, val, val_size);
    36	}
    37	
    38	static struct regmap_bus bme680_regmap_bus = {
    39		.write = bme680_regmap_spi_write,
    40		.read = bme680_regmap_spi_read,
    41		.reg_format_endian_default = REGMAP_ENDIAN_BIG,
    42		.val_format_endian_default = REGMAP_ENDIAN_BIG,
    43	};
    44	
    45	static int bme680_spi_probe(struct spi_device *spi)
    46	{
    47		const struct spi_device_id *id = spi_get_device_id(spi);
    48		struct regmap *regmap;
    49		unsigned int val;
    50		int ret;
    51	
    52		spi->bits_per_word = 8;
    53		ret = spi_setup(spi);
    54		if (ret < 0) {
    55			dev_err(&spi->dev, "spi_setup failed!\n");
    56			return ret;
    57		}
    58	
    59		regmap = devm_regmap_init(&spi->dev, &bme680_regmap_bus,
    60					  &spi->dev, &bme680_regmap_config);
    61		if (IS_ERR(regmap)) {
    62			dev_err(&spi->dev, "Failed to register spi regmap %d\n",
    63					(int)PTR_ERR(regmap));
    64			return PTR_ERR(regmap);
    65		}
    66	
    67		ret = regmap_write(regmap, BME680_REG_SOFT_RESET_SPI,
    68				   BME680_CMD_SOFTRESET);
    69		if (ret < 0) {
    70			dev_err(&spi->dev, "Failed to reset chip\n");
    71			return ret;
    72		}
    73	
    74		/* after power-on reset, Page 0(0x80-0xFF) of spi_mem_page is active */
    75		ret = regmap_read(regmap, BME680_REG_CHIP_SPI_ID, &val);
    76		if (ret < 0) {
    77			dev_err(&spi->dev, "Error reading SPI chip ID\n");
    78			return ret;
    79		}
    80	
    81		if (val != BME680_CHIP_ID_VAL) {
    82			dev_err(&spi->dev, "Wrong chip ID, got %x expected %x\n",
    83					val, BME680_CHIP_ID_VAL);
    84			return -ENODEV;
    85		}
    86		/*
    87		 * select Page 1 of spi_mem_page to enable access to
    88		 * to registers from address 0x00 to 0x7F.
    89		 */
    90		ret = regmap_write_bits(regmap, BME680_REG_STATUS,
    91					BME680_SPI_MEM_PAGE_BIT,
    92					BME680_SPI_MEM_PAGE_1_VAL);
    93		if (ret < 0) {
    94			dev_err(&spi->dev, "failed to set page 1 of spi_mem_page\n");
    95			return ret;
    96		}
    97	
    98		return bme680_core_probe(&spi->dev, regmap, id->name);
    99	}
   100	
   101	static const struct spi_device_id bme680_spi_id[] = {
   102		{"bme680", 0},
   103		{},
   104	};
   105	MODULE_DEVICE_TABLE(spi, bme680_spi_id);
   106	
   107	static const struct acpi_device_id bme680_acpi_match[] = {
   108		{"BME0680", 0},
   109		{},
   110	};
   111	MODULE_DEVICE_TABLE(acpi, bme680_acpi_match);
   112	
   113	static const struct of_device_id bme680_of_spi_match[] = {
   114		{ .compatible = "bosch,bme680", },
   115		{},
   116	}
 > 117	MODULE_DEVICE_TABLE(of, bme680_of_spi_match);
   118	
   119	static struct spi_driver bme680_spi_driver = {
   120		.driver = {
   121			.name			= "bme680_spi",
   122			.acpi_match_table	= ACPI_PTR(bme680_acpi_match),
 > 123			.of_match_table		= of_match_ptr(bme680_of_spi_match),
   124		},
   125		.probe = bme680_spi_probe,
   126		.id_table = bme680_spi_id,
   127	};
   128	module_spi_driver(bme680_spi_driver);
   129	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot Jan. 13, 2019, 10:59 p.m. UTC | #2
Hi Sebastien,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on iio/togreg]
[also build test ERROR on v5.0-rc1 next-20190111]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Sebastien-Bourdelin/iio-chemical-bme680-Add-device-tree-support/20190114-063618
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
config: x86_64-randconfig-x013-201902 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/acpi.h:41:0,
                    from drivers/iio/chemical/bme680_i2c.c:14:
>> include/linux/module.h:213:1: error: expected ',' or ';' before 'extern'
    extern typeof(name) __mod_##type##__##name##_device_table  \
    ^
>> drivers/iio/chemical/bme680_i2c.c:77:1: note: in expansion of macro 'MODULE_DEVICE_TABLE'
    MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
    ^~~~~~~~~~~~~~~~~~~
--
   In file included from include/linux/acpi.h:41:0,
                    from drivers/iio//chemical/bme680_i2c.c:14:
>> include/linux/module.h:213:1: error: expected ',' or ';' before 'extern'
    extern typeof(name) __mod_##type##__##name##_device_table  \
    ^
   drivers/iio//chemical/bme680_i2c.c:77:1: note: in expansion of macro 'MODULE_DEVICE_TABLE'
    MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
    ^~~~~~~~~~~~~~~~~~~

vim +/MODULE_DEVICE_TABLE +77 drivers/iio/chemical/bme680_i2c.c

  > 14	#include <linux/acpi.h>
    15	#include <linux/i2c.h>
    16	#include <linux/module.h>
    17	#include <linux/regmap.h>
    18	
    19	#include "bme680.h"
    20	
    21	static int bme680_i2c_probe(struct i2c_client *client,
    22				    const struct i2c_device_id *id)
    23	{
    24		struct regmap *regmap;
    25		const char *name = NULL;
    26		unsigned int val;
    27		int ret;
    28	
    29		regmap = devm_regmap_init_i2c(client, &bme680_regmap_config);
    30		if (IS_ERR(regmap)) {
    31			dev_err(&client->dev, "Failed to register i2c regmap %d\n",
    32					(int)PTR_ERR(regmap));
    33			return PTR_ERR(regmap);
    34		}
    35	
    36		ret = regmap_write(regmap, BME680_REG_SOFT_RESET_I2C,
    37				   BME680_CMD_SOFTRESET);
    38		if (ret < 0) {
    39			dev_err(&client->dev, "Failed to reset chip\n");
    40			return ret;
    41		}
    42	
    43		ret = regmap_read(regmap, BME680_REG_CHIP_I2C_ID, &val);
    44		if (ret < 0) {
    45			dev_err(&client->dev, "Error reading I2C chip ID\n");
    46			return ret;
    47		}
    48	
    49		if (val != BME680_CHIP_ID_VAL) {
    50			dev_err(&client->dev, "Wrong chip ID, got %x expected %x\n",
    51					val, BME680_CHIP_ID_VAL);
    52			return -ENODEV;
    53		}
    54	
    55		if (id)
    56			name = id->name;
    57	
    58		return bme680_core_probe(&client->dev, regmap, name);
    59	}
    60	
    61	static const struct i2c_device_id bme680_i2c_id[] = {
    62		{"bme680", 0},
    63		{},
    64	};
    65	MODULE_DEVICE_TABLE(i2c, bme680_i2c_id);
    66	
    67	static const struct acpi_device_id bme680_acpi_match[] = {
    68		{"BME0680", 0},
    69		{},
    70	};
    71	MODULE_DEVICE_TABLE(acpi, bme680_acpi_match);
    72	
    73	static const struct of_device_id bme680_of_i2c_match[] = {
    74		{ .compatible = "bosch,bme680", },
    75		{},
    76	}
  > 77	MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
    78	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/iio/chemical/bme680_i2c.c b/drivers/iio/chemical/bme680_i2c.c
index 06d4be539d2e..94a36ebdf0b2 100644
--- a/drivers/iio/chemical/bme680_i2c.c
+++ b/drivers/iio/chemical/bme680_i2c.c
@@ -70,10 +70,17 @@  static const struct acpi_device_id bme680_acpi_match[] = {
 };
 MODULE_DEVICE_TABLE(acpi, bme680_acpi_match);
 
+static const struct of_device_id bme680_of_i2c_match[] = {
+	{ .compatible = "bosch,bme680", },
+	{},
+}
+MODULE_DEVICE_TABLE(of, bme680_of_i2c_match);
+
 static struct i2c_driver bme680_i2c_driver = {
 	.driver = {
 		.name			= "bme680_i2c",
 		.acpi_match_table       = ACPI_PTR(bme680_acpi_match),
+		.of_match_table		= of_match_ptr(bme680_of_i2c_match),
 	},
 	.probe = bme680_i2c_probe,
 	.id_table = bme680_i2c_id,
diff --git a/drivers/iio/chemical/bme680_spi.c b/drivers/iio/chemical/bme680_spi.c
index c9fb05e8d0b9..45bd4e93a891 100644
--- a/drivers/iio/chemical/bme680_spi.c
+++ b/drivers/iio/chemical/bme680_spi.c
@@ -110,10 +110,17 @@  static const struct acpi_device_id bme680_acpi_match[] = {
 };
 MODULE_DEVICE_TABLE(acpi, bme680_acpi_match);
 
+static const struct of_device_id bme680_of_spi_match[] = {
+	{ .compatible = "bosch,bme680", },
+	{},
+}
+MODULE_DEVICE_TABLE(of, bme680_of_spi_match);
+
 static struct spi_driver bme680_spi_driver = {
 	.driver = {
 		.name			= "bme680_spi",
 		.acpi_match_table	= ACPI_PTR(bme680_acpi_match),
+		.of_match_table		= of_match_ptr(bme680_of_spi_match),
 	},
 	.probe = bme680_spi_probe,
 	.id_table = bme680_spi_id,