Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright (C) 2020 InvenSense, Inc.
0004  */
0005 
0006 #include <linux/kernel.h>
0007 #include <linux/device.h>
0008 #include <linux/module.h>
0009 #include <linux/mod_devicetable.h>
0010 #include <linux/i2c.h>
0011 #include <linux/regmap.h>
0012 #include <linux/property.h>
0013 
0014 #include "inv_icm42600.h"
0015 
0016 static int inv_icm42600_i2c_bus_setup(struct inv_icm42600_state *st)
0017 {
0018     unsigned int mask, val;
0019     int ret;
0020 
0021     /*
0022      * setup interface registers
0023      * This register write to REG_INTF_CONFIG6 enables a spike filter that
0024      * is impacting the line and can prevent the I2C ACK to be seen by the
0025      * controller. So we don't test the return value.
0026      */
0027     regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG6,
0028                INV_ICM42600_INTF_CONFIG6_MASK,
0029                INV_ICM42600_INTF_CONFIG6_I3C_EN);
0030 
0031     ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG4,
0032                  INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY, 0);
0033     if (ret)
0034         return ret;
0035 
0036     /* set slew rates for I2C and SPI */
0037     mask = INV_ICM42600_DRIVE_CONFIG_I2C_MASK |
0038            INV_ICM42600_DRIVE_CONFIG_SPI_MASK;
0039     val = INV_ICM42600_DRIVE_CONFIG_I2C(INV_ICM42600_SLEW_RATE_12_36NS) |
0040           INV_ICM42600_DRIVE_CONFIG_SPI(INV_ICM42600_SLEW_RATE_12_36NS);
0041     ret = regmap_update_bits(st->map, INV_ICM42600_REG_DRIVE_CONFIG,
0042                  mask, val);
0043     if (ret)
0044         return ret;
0045 
0046     /* disable SPI bus */
0047     return regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG0,
0048                   INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_MASK,
0049                   INV_ICM42600_INTF_CONFIG0_UI_SIFS_CFG_SPI_DIS);
0050 }
0051 
0052 static int inv_icm42600_probe(struct i2c_client *client)
0053 {
0054     const void *match;
0055     enum inv_icm42600_chip chip;
0056     struct regmap *regmap;
0057 
0058     if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
0059         return -ENOTSUPP;
0060 
0061     match = device_get_match_data(&client->dev);
0062     if (!match)
0063         return -EINVAL;
0064     chip = (uintptr_t)match;
0065 
0066     regmap = devm_regmap_init_i2c(client, &inv_icm42600_regmap_config);
0067     if (IS_ERR(regmap))
0068         return PTR_ERR(regmap);
0069 
0070     return inv_icm42600_core_probe(regmap, chip, client->irq,
0071                        inv_icm42600_i2c_bus_setup);
0072 }
0073 
0074 static const struct of_device_id inv_icm42600_of_matches[] = {
0075     {
0076         .compatible = "invensense,icm42600",
0077         .data = (void *)INV_CHIP_ICM42600,
0078     }, {
0079         .compatible = "invensense,icm42602",
0080         .data = (void *)INV_CHIP_ICM42602,
0081     }, {
0082         .compatible = "invensense,icm42605",
0083         .data = (void *)INV_CHIP_ICM42605,
0084     }, {
0085         .compatible = "invensense,icm42622",
0086         .data = (void *)INV_CHIP_ICM42622,
0087     },
0088     {}
0089 };
0090 MODULE_DEVICE_TABLE(of, inv_icm42600_of_matches);
0091 
0092 static struct i2c_driver inv_icm42600_driver = {
0093     .driver = {
0094         .name = "inv-icm42600-i2c",
0095         .of_match_table = inv_icm42600_of_matches,
0096         .pm = &inv_icm42600_pm_ops,
0097     },
0098     .probe_new = inv_icm42600_probe,
0099 };
0100 module_i2c_driver(inv_icm42600_driver);
0101 
0102 MODULE_AUTHOR("InvenSense, Inc.");
0103 MODULE_DESCRIPTION("InvenSense ICM-426xx I2C driver");
0104 MODULE_LICENSE("GPL");