1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * STMicroelectronics st_lsm6dsx spi driver 4 * 5 * Copyright 2016 STMicroelectronics Inc. 6 * 7 * Lorenzo Bianconi <lorenzo.bianconi@st.com> 8 * Denis Ciocca <denis.ciocca@st.com> 9 */ 10 11 #include <linux/kernel.h> 12 #include <linux/module.h> 13 #include <linux/spi/spi.h> 14 #include <linux/slab.h> 15 #include <linux/regmap.h> 16 17 #include "st_lsm6dsx.h" 18 19 static const struct regmap_config st_lsm6dsx_spi_regmap_config = { 20 .reg_bits = 8, 21 .val_bits = 8, 22 }; 23 24 static int st_lsm6dsx_spi_probe(struct spi_device *spi) 25 { 26 const struct spi_device_id *id = spi_get_device_id(spi); 27 int hw_id = id->driver_data; 28 struct regmap *regmap; 29 30 regmap = devm_regmap_init_spi(spi, &st_lsm6dsx_spi_regmap_config); 31 if (IS_ERR(regmap)) { 32 dev_err(&spi->dev, "Failed to register spi regmap %d\n", 33 (int)PTR_ERR(regmap)); 34 return PTR_ERR(regmap); 35 } 36 37 return st_lsm6dsx_probe(&spi->dev, spi->irq, hw_id, regmap); 38 } 39 40 static const struct of_device_id st_lsm6dsx_spi_of_match[] = { 41 { 42 .compatible = "st,lsm6ds3", 43 .data = (void *)ST_LSM6DS3_ID, 44 }, 45 { 46 .compatible = "st,lsm6ds3h", 47 .data = (void *)ST_LSM6DS3H_ID, 48 }, 49 { 50 .compatible = "st,lsm6dsl", 51 .data = (void *)ST_LSM6DSL_ID, 52 }, 53 { 54 .compatible = "st,lsm6dsm", 55 .data = (void *)ST_LSM6DSM_ID, 56 }, 57 { 58 .compatible = "st,ism330dlc", 59 .data = (void *)ST_ISM330DLC_ID, 60 }, 61 { 62 .compatible = "st,lsm6dso", 63 .data = (void *)ST_LSM6DSO_ID, 64 }, 65 { 66 .compatible = "st,asm330lhh", 67 .data = (void *)ST_ASM330LHH_ID, 68 }, 69 { 70 .compatible = "st,lsm6dsox", 71 .data = (void *)ST_LSM6DSOX_ID, 72 }, 73 { 74 .compatible = "st,lsm6dsr", 75 .data = (void *)ST_LSM6DSR_ID, 76 }, 77 { 78 .compatible = "st,lsm6ds3tr-c", 79 .data = (void *)ST_LSM6DS3TRC_ID, 80 }, 81 { 82 .compatible = "st,ism330dhcx", 83 .data = (void *)ST_ISM330DHCX_ID, 84 }, 85 { 86 .compatible = "st,lsm9ds1-imu", 87 .data = (void *)ST_LSM9DS1_ID, 88 }, 89 { 90 .compatible = "st,lsm6ds0", 91 .data = (void *)ST_LSM6DS0_ID, 92 }, 93 { 94 .compatible = "st,lsm6dsrx", 95 .data = (void *)ST_LSM6DSRX_ID, 96 }, 97 { 98 .compatible = "st,lsm6dst", 99 .data = (void *)ST_LSM6DST_ID, 100 }, 101 {}, 102 }; 103 MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match); 104 105 static const struct spi_device_id st_lsm6dsx_spi_id_table[] = { 106 { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID }, 107 { ST_LSM6DS3H_DEV_NAME, ST_LSM6DS3H_ID }, 108 { ST_LSM6DSL_DEV_NAME, ST_LSM6DSL_ID }, 109 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID }, 110 { ST_ISM330DLC_DEV_NAME, ST_ISM330DLC_ID }, 111 { ST_LSM6DSO_DEV_NAME, ST_LSM6DSO_ID }, 112 { ST_ASM330LHH_DEV_NAME, ST_ASM330LHH_ID }, 113 { ST_LSM6DSOX_DEV_NAME, ST_LSM6DSOX_ID }, 114 { ST_LSM6DSR_DEV_NAME, ST_LSM6DSR_ID }, 115 { ST_LSM6DS3TRC_DEV_NAME, ST_LSM6DS3TRC_ID }, 116 { ST_ISM330DHCX_DEV_NAME, ST_ISM330DHCX_ID }, 117 { ST_LSM9DS1_DEV_NAME, ST_LSM9DS1_ID }, 118 { ST_LSM6DS0_DEV_NAME, ST_LSM6DS0_ID }, 119 { ST_LSM6DSRX_DEV_NAME, ST_LSM6DSRX_ID }, 120 { ST_LSM6DST_DEV_NAME, ST_LSM6DST_ID }, 121 {}, 122 }; 123 MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table); 124 125 static struct spi_driver st_lsm6dsx_driver = { 126 .driver = { 127 .name = "st_lsm6dsx_spi", 128 .pm = &st_lsm6dsx_pm_ops, 129 .of_match_table = st_lsm6dsx_spi_of_match, 130 }, 131 .probe = st_lsm6dsx_spi_probe, 132 .id_table = st_lsm6dsx_spi_id_table, 133 }; 134 module_spi_driver(st_lsm6dsx_driver); 135 136 MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>"); 137 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 138 MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver"); 139 MODULE_LICENSE("GPL v2"); 140