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 212d7768a8SLinus Walleij #ifdef CONFIG_OF 222d7768a8SLinus Walleij static const struct of_device_id st_press_of_match[] = { 232d7768a8SLinus Walleij { 242d7768a8SLinus Walleij .compatible = "st,lps001wp-press", 252d7768a8SLinus Walleij .data = LPS001WP_PRESS_DEV_NAME, 262d7768a8SLinus Walleij }, 272d7768a8SLinus Walleij { 282d7768a8SLinus Walleij .compatible = "st,lps25h-press", 292d7768a8SLinus Walleij .data = LPS25H_PRESS_DEV_NAME, 302d7768a8SLinus Walleij }, 312d7768a8SLinus Walleij { 322d7768a8SLinus Walleij .compatible = "st,lps331ap-press", 332d7768a8SLinus Walleij .data = LPS331AP_PRESS_DEV_NAME, 342d7768a8SLinus Walleij }, 352d7768a8SLinus Walleij {}, 362d7768a8SLinus Walleij }; 372d7768a8SLinus Walleij MODULE_DEVICE_TABLE(of, st_press_of_match); 382d7768a8SLinus Walleij #else 392d7768a8SLinus Walleij #define st_press_of_match NULL 402d7768a8SLinus Walleij #endif 412d7768a8SLinus Walleij 42217494e5SDenis CIOCCA static int st_press_i2c_probe(struct i2c_client *client, 43217494e5SDenis CIOCCA const struct i2c_device_id *id) 44217494e5SDenis CIOCCA { 45217494e5SDenis CIOCCA struct iio_dev *indio_dev; 46217494e5SDenis CIOCCA struct st_sensor_data *pdata; 47217494e5SDenis CIOCCA int err; 48217494e5SDenis CIOCCA 49d0fe8c8bSSachin Kamat indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*pdata)); 50d0fe8c8bSSachin Kamat if (!indio_dev) 51d0fe8c8bSSachin Kamat return -ENOMEM; 52217494e5SDenis CIOCCA 53217494e5SDenis CIOCCA pdata = iio_priv(indio_dev); 54217494e5SDenis CIOCCA pdata->dev = &client->dev; 552d7768a8SLinus Walleij st_sensors_of_i2c_probe(client, st_press_of_match); 56217494e5SDenis CIOCCA 57217494e5SDenis CIOCCA st_sensors_i2c_configure(indio_dev, client, pdata); 58217494e5SDenis CIOCCA 59*0baa3fc1SDenis CIOCCA err = st_press_common_probe(indio_dev); 60217494e5SDenis CIOCCA if (err < 0) 61d0fe8c8bSSachin Kamat return err; 62217494e5SDenis CIOCCA 63217494e5SDenis CIOCCA return 0; 64217494e5SDenis CIOCCA } 65217494e5SDenis CIOCCA 66217494e5SDenis CIOCCA static int st_press_i2c_remove(struct i2c_client *client) 67217494e5SDenis CIOCCA { 68217494e5SDenis CIOCCA st_press_common_remove(i2c_get_clientdata(client)); 69217494e5SDenis CIOCCA 70217494e5SDenis CIOCCA return 0; 71217494e5SDenis CIOCCA } 72217494e5SDenis CIOCCA 73217494e5SDenis CIOCCA static const struct i2c_device_id st_press_id_table[] = { 747885a8ceSLee Jones { LPS001WP_PRESS_DEV_NAME }, 7593187840SDenis CIOCCA { LPS25H_PRESS_DEV_NAME }, 76217494e5SDenis CIOCCA { LPS331AP_PRESS_DEV_NAME }, 77217494e5SDenis CIOCCA {}, 78217494e5SDenis CIOCCA }; 79217494e5SDenis CIOCCA MODULE_DEVICE_TABLE(i2c, st_press_id_table); 80217494e5SDenis CIOCCA 81217494e5SDenis CIOCCA static struct i2c_driver st_press_driver = { 82217494e5SDenis CIOCCA .driver = { 83217494e5SDenis CIOCCA .owner = THIS_MODULE, 84217494e5SDenis CIOCCA .name = "st-press-i2c", 852d7768a8SLinus Walleij .of_match_table = of_match_ptr(st_press_of_match), 86217494e5SDenis CIOCCA }, 87217494e5SDenis CIOCCA .probe = st_press_i2c_probe, 88217494e5SDenis CIOCCA .remove = st_press_i2c_remove, 89217494e5SDenis CIOCCA .id_table = st_press_id_table, 90217494e5SDenis CIOCCA }; 91217494e5SDenis CIOCCA module_i2c_driver(st_press_driver); 92217494e5SDenis CIOCCA 93217494e5SDenis CIOCCA MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 94217494e5SDenis CIOCCA MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver"); 95217494e5SDenis CIOCCA MODULE_LICENSE("GPL v2"); 96