1217494e5SDenis CIOCCA /* 2217494e5SDenis CIOCCA * STMicroelectronics pressures driver 3217494e5SDenis CIOCCA * 4217494e5SDenis CIOCCA * Copyright 2013 STMicroelectronics Inc. 5217494e5SDenis CIOCCA * 6217494e5SDenis CIOCCA * Denis Ciocca <denis.ciocca@st.com> 7217494e5SDenis CIOCCA * 8217494e5SDenis CIOCCA * Licensed under the GPL-2. 9217494e5SDenis CIOCCA */ 10217494e5SDenis CIOCCA 11217494e5SDenis CIOCCA #include <linux/kernel.h> 12217494e5SDenis CIOCCA #include <linux/module.h> 13217494e5SDenis CIOCCA #include <linux/slab.h> 14217494e5SDenis CIOCCA #include <linux/i2c.h> 15217494e5SDenis CIOCCA #include <linux/iio/iio.h> 16217494e5SDenis CIOCCA 17217494e5SDenis CIOCCA #include <linux/iio/common/st_sensors.h> 18217494e5SDenis CIOCCA #include <linux/iio/common/st_sensors_i2c.h> 19217494e5SDenis CIOCCA #include "st_pressure.h" 20217494e5SDenis CIOCCA 21217494e5SDenis CIOCCA static int st_press_i2c_probe(struct i2c_client *client, 22217494e5SDenis CIOCCA const struct i2c_device_id *id) 23217494e5SDenis CIOCCA { 24217494e5SDenis CIOCCA struct iio_dev *indio_dev; 25217494e5SDenis CIOCCA struct st_sensor_data *pdata; 26217494e5SDenis CIOCCA int err; 27217494e5SDenis CIOCCA 28217494e5SDenis CIOCCA indio_dev = iio_device_alloc(sizeof(*pdata)); 29217494e5SDenis CIOCCA if (indio_dev == NULL) { 30217494e5SDenis CIOCCA err = -ENOMEM; 31217494e5SDenis CIOCCA goto iio_device_alloc_error; 32217494e5SDenis CIOCCA } 33217494e5SDenis CIOCCA 34217494e5SDenis CIOCCA pdata = iio_priv(indio_dev); 35217494e5SDenis CIOCCA pdata->dev = &client->dev; 36217494e5SDenis CIOCCA 37217494e5SDenis CIOCCA st_sensors_i2c_configure(indio_dev, client, pdata); 38217494e5SDenis CIOCCA 39*23cde4d6SDenis CIOCCA err = st_press_common_probe(indio_dev, client->dev.platform_data); 40217494e5SDenis CIOCCA if (err < 0) 41217494e5SDenis CIOCCA goto st_press_common_probe_error; 42217494e5SDenis CIOCCA 43217494e5SDenis CIOCCA return 0; 44217494e5SDenis CIOCCA 45217494e5SDenis CIOCCA st_press_common_probe_error: 46217494e5SDenis CIOCCA iio_device_free(indio_dev); 47217494e5SDenis CIOCCA iio_device_alloc_error: 48217494e5SDenis CIOCCA return err; 49217494e5SDenis CIOCCA } 50217494e5SDenis CIOCCA 51217494e5SDenis CIOCCA static int st_press_i2c_remove(struct i2c_client *client) 52217494e5SDenis CIOCCA { 53217494e5SDenis CIOCCA st_press_common_remove(i2c_get_clientdata(client)); 54217494e5SDenis CIOCCA 55217494e5SDenis CIOCCA return 0; 56217494e5SDenis CIOCCA } 57217494e5SDenis CIOCCA 58217494e5SDenis CIOCCA static const struct i2c_device_id st_press_id_table[] = { 59217494e5SDenis CIOCCA { LPS331AP_PRESS_DEV_NAME }, 60217494e5SDenis CIOCCA {}, 61217494e5SDenis CIOCCA }; 62217494e5SDenis CIOCCA MODULE_DEVICE_TABLE(i2c, st_press_id_table); 63217494e5SDenis CIOCCA 64217494e5SDenis CIOCCA static struct i2c_driver st_press_driver = { 65217494e5SDenis CIOCCA .driver = { 66217494e5SDenis CIOCCA .owner = THIS_MODULE, 67217494e5SDenis CIOCCA .name = "st-press-i2c", 68217494e5SDenis CIOCCA }, 69217494e5SDenis CIOCCA .probe = st_press_i2c_probe, 70217494e5SDenis CIOCCA .remove = st_press_i2c_remove, 71217494e5SDenis CIOCCA .id_table = st_press_id_table, 72217494e5SDenis CIOCCA }; 73217494e5SDenis CIOCCA module_i2c_driver(st_press_driver); 74217494e5SDenis CIOCCA 75217494e5SDenis CIOCCA MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 76217494e5SDenis CIOCCA MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver"); 77217494e5SDenis CIOCCA MODULE_LICENSE("GPL v2"); 78