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/i2c.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_i2c.h> 19872e79adSDenis Ciocca #include "st_magn.h" 20872e79adSDenis Ciocca 21872e79adSDenis Ciocca static int st_magn_i2c_probe(struct i2c_client *client, 22872e79adSDenis Ciocca const struct i2c_device_id *id) 23872e79adSDenis Ciocca { 24872e79adSDenis Ciocca struct iio_dev *indio_dev; 25872e79adSDenis Ciocca struct st_sensor_data *mdata; 26872e79adSDenis Ciocca int err; 27872e79adSDenis Ciocca 28872e79adSDenis Ciocca indio_dev = iio_device_alloc(sizeof(*mdata)); 29872e79adSDenis Ciocca if (indio_dev == NULL) { 30872e79adSDenis Ciocca err = -ENOMEM; 31872e79adSDenis Ciocca goto iio_device_alloc_error; 32872e79adSDenis Ciocca } 33872e79adSDenis Ciocca 34872e79adSDenis Ciocca mdata = iio_priv(indio_dev); 35872e79adSDenis Ciocca mdata->dev = &client->dev; 36872e79adSDenis Ciocca 37872e79adSDenis Ciocca st_sensors_i2c_configure(indio_dev, client, mdata); 38872e79adSDenis Ciocca 39*23cde4d6SDenis CIOCCA err = st_magn_common_probe(indio_dev, NULL); 40872e79adSDenis Ciocca if (err < 0) 41872e79adSDenis Ciocca goto st_magn_common_probe_error; 42872e79adSDenis Ciocca 43872e79adSDenis Ciocca return 0; 44872e79adSDenis Ciocca 45872e79adSDenis Ciocca st_magn_common_probe_error: 46872e79adSDenis Ciocca iio_device_free(indio_dev); 47872e79adSDenis Ciocca iio_device_alloc_error: 48872e79adSDenis Ciocca return err; 49872e79adSDenis Ciocca } 50872e79adSDenis Ciocca 51872e79adSDenis Ciocca static int st_magn_i2c_remove(struct i2c_client *client) 52872e79adSDenis Ciocca { 53872e79adSDenis Ciocca struct iio_dev *indio_dev = i2c_get_clientdata(client); 54872e79adSDenis Ciocca st_magn_common_remove(indio_dev); 55872e79adSDenis Ciocca 56872e79adSDenis Ciocca return 0; 57872e79adSDenis Ciocca } 58872e79adSDenis Ciocca 59872e79adSDenis Ciocca static const struct i2c_device_id st_magn_id_table[] = { 60872e79adSDenis Ciocca { LSM303DLHC_MAGN_DEV_NAME }, 61872e79adSDenis Ciocca { LSM303DLM_MAGN_DEV_NAME }, 62872e79adSDenis Ciocca { LIS3MDL_MAGN_DEV_NAME }, 63872e79adSDenis Ciocca {}, 64872e79adSDenis Ciocca }; 65872e79adSDenis Ciocca MODULE_DEVICE_TABLE(i2c, st_magn_id_table); 66872e79adSDenis Ciocca 67872e79adSDenis Ciocca static struct i2c_driver st_magn_driver = { 68872e79adSDenis Ciocca .driver = { 69872e79adSDenis Ciocca .owner = THIS_MODULE, 70872e79adSDenis Ciocca .name = "st-magn-i2c", 71872e79adSDenis Ciocca }, 72872e79adSDenis Ciocca .probe = st_magn_i2c_probe, 73872e79adSDenis Ciocca .remove = st_magn_i2c_remove, 74872e79adSDenis Ciocca .id_table = st_magn_id_table, 75872e79adSDenis Ciocca }; 76872e79adSDenis Ciocca module_i2c_driver(st_magn_driver); 77872e79adSDenis Ciocca 78872e79adSDenis Ciocca MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 79872e79adSDenis Ciocca MODULE_DESCRIPTION("STMicroelectronics magnetometers i2c driver"); 80872e79adSDenis Ciocca MODULE_LICENSE("GPL v2"); 81