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 27872e79adSDenis Ciocca indio_dev = iio_device_alloc(sizeof(*mdata)); 28872e79adSDenis Ciocca if (indio_dev == NULL) { 29872e79adSDenis Ciocca err = -ENOMEM; 30872e79adSDenis Ciocca goto iio_device_alloc_error; 31872e79adSDenis Ciocca } 32872e79adSDenis Ciocca 33872e79adSDenis Ciocca mdata = iio_priv(indio_dev); 34872e79adSDenis Ciocca mdata->dev = &spi->dev; 35872e79adSDenis Ciocca 36872e79adSDenis Ciocca st_sensors_spi_configure(indio_dev, spi, mdata); 37872e79adSDenis Ciocca 38*23cde4d6SDenis CIOCCA err = st_magn_common_probe(indio_dev, NULL); 39872e79adSDenis Ciocca if (err < 0) 40872e79adSDenis Ciocca goto st_magn_common_probe_error; 41872e79adSDenis Ciocca 42872e79adSDenis Ciocca return 0; 43872e79adSDenis Ciocca 44872e79adSDenis Ciocca st_magn_common_probe_error: 45872e79adSDenis Ciocca iio_device_free(indio_dev); 46872e79adSDenis Ciocca iio_device_alloc_error: 47872e79adSDenis Ciocca return err; 48872e79adSDenis Ciocca } 49872e79adSDenis Ciocca 50872e79adSDenis Ciocca static int st_magn_spi_remove(struct spi_device *spi) 51872e79adSDenis Ciocca { 52872e79adSDenis Ciocca struct iio_dev *indio_dev = spi_get_drvdata(spi); 53872e79adSDenis Ciocca st_magn_common_remove(indio_dev); 54872e79adSDenis Ciocca 55872e79adSDenis Ciocca return 0; 56872e79adSDenis Ciocca } 57872e79adSDenis Ciocca 58872e79adSDenis Ciocca static const struct spi_device_id st_magn_id_table[] = { 59872e79adSDenis Ciocca { LSM303DLHC_MAGN_DEV_NAME }, 60872e79adSDenis Ciocca { LSM303DLM_MAGN_DEV_NAME }, 61872e79adSDenis Ciocca { LIS3MDL_MAGN_DEV_NAME }, 62872e79adSDenis Ciocca {}, 63872e79adSDenis Ciocca }; 64872e79adSDenis Ciocca MODULE_DEVICE_TABLE(spi, st_magn_id_table); 65872e79adSDenis Ciocca 66872e79adSDenis Ciocca static struct spi_driver st_magn_driver = { 67872e79adSDenis Ciocca .driver = { 68872e79adSDenis Ciocca .owner = THIS_MODULE, 69872e79adSDenis Ciocca .name = "st-magn-spi", 70872e79adSDenis Ciocca }, 71872e79adSDenis Ciocca .probe = st_magn_spi_probe, 72872e79adSDenis Ciocca .remove = st_magn_spi_remove, 73872e79adSDenis Ciocca .id_table = st_magn_id_table, 74872e79adSDenis Ciocca }; 75872e79adSDenis Ciocca module_spi_driver(st_magn_driver); 76872e79adSDenis Ciocca 77872e79adSDenis Ciocca MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 78872e79adSDenis Ciocca MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver"); 79872e79adSDenis Ciocca MODULE_LICENSE("GPL v2"); 80