1872e79adSDenis Ciocca /* 2872e79adSDenis Ciocca * STMicroelectronics magnetometers driver 3872e79adSDenis Ciocca * 4872e79adSDenis Ciocca * Copyright 2012-2013 STMicroelectronics Inc. 5872e79adSDenis Ciocca * 6872e79adSDenis Ciocca * Denis Ciocca <denis.ciocca@st.com> 7872e79adSDenis Ciocca * 8872e79adSDenis Ciocca * Licensed under the GPL-2. 9872e79adSDenis Ciocca */ 10872e79adSDenis Ciocca 11872e79adSDenis Ciocca #include <linux/kernel.h> 12872e79adSDenis Ciocca #include <linux/module.h> 13872e79adSDenis Ciocca #include <linux/slab.h> 14872e79adSDenis Ciocca #include <linux/spi/spi.h> 15872e79adSDenis Ciocca #include <linux/iio/iio.h> 16872e79adSDenis Ciocca 17872e79adSDenis Ciocca #include <linux/iio/common/st_sensors.h> 18872e79adSDenis Ciocca #include <linux/iio/common/st_sensors_spi.h> 19872e79adSDenis Ciocca #include "st_magn.h" 20872e79adSDenis Ciocca 21872e79adSDenis Ciocca static int st_magn_spi_probe(struct spi_device *spi) 22872e79adSDenis Ciocca { 23872e79adSDenis Ciocca struct iio_dev *indio_dev; 24872e79adSDenis Ciocca struct st_sensor_data *mdata; 25872e79adSDenis Ciocca int err; 26872e79adSDenis Ciocca 27*7fc5ad7eSSachin Kamat indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*mdata)); 28*7fc5ad7eSSachin Kamat if (!indio_dev) 29*7fc5ad7eSSachin Kamat return -ENOMEM; 30872e79adSDenis Ciocca 31872e79adSDenis Ciocca mdata = iio_priv(indio_dev); 32872e79adSDenis Ciocca mdata->dev = &spi->dev; 33872e79adSDenis Ciocca 34872e79adSDenis Ciocca st_sensors_spi_configure(indio_dev, spi, mdata); 35872e79adSDenis Ciocca 3623cde4d6SDenis CIOCCA err = st_magn_common_probe(indio_dev, NULL); 37872e79adSDenis Ciocca if (err < 0) 38*7fc5ad7eSSachin Kamat return err; 39872e79adSDenis Ciocca 40872e79adSDenis Ciocca return 0; 41872e79adSDenis Ciocca } 42872e79adSDenis Ciocca 43872e79adSDenis Ciocca static int st_magn_spi_remove(struct spi_device *spi) 44872e79adSDenis Ciocca { 45872e79adSDenis Ciocca struct iio_dev *indio_dev = spi_get_drvdata(spi); 46872e79adSDenis Ciocca st_magn_common_remove(indio_dev); 47872e79adSDenis Ciocca 48872e79adSDenis Ciocca return 0; 49872e79adSDenis Ciocca } 50872e79adSDenis Ciocca 51872e79adSDenis Ciocca static const struct spi_device_id st_magn_id_table[] = { 52872e79adSDenis Ciocca { LSM303DLHC_MAGN_DEV_NAME }, 53872e79adSDenis Ciocca { LSM303DLM_MAGN_DEV_NAME }, 54872e79adSDenis Ciocca { LIS3MDL_MAGN_DEV_NAME }, 55872e79adSDenis Ciocca {}, 56872e79adSDenis Ciocca }; 57872e79adSDenis Ciocca MODULE_DEVICE_TABLE(spi, st_magn_id_table); 58872e79adSDenis Ciocca 59872e79adSDenis Ciocca static struct spi_driver st_magn_driver = { 60872e79adSDenis Ciocca .driver = { 61872e79adSDenis Ciocca .owner = THIS_MODULE, 62872e79adSDenis Ciocca .name = "st-magn-spi", 63872e79adSDenis Ciocca }, 64872e79adSDenis Ciocca .probe = st_magn_spi_probe, 65872e79adSDenis Ciocca .remove = st_magn_spi_remove, 66872e79adSDenis Ciocca .id_table = st_magn_id_table, 67872e79adSDenis Ciocca }; 68872e79adSDenis Ciocca module_spi_driver(st_magn_driver); 69872e79adSDenis Ciocca 70872e79adSDenis Ciocca MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 71872e79adSDenis Ciocca MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver"); 72872e79adSDenis Ciocca MODULE_LICENSE("GPL v2"); 73