1 /* 2 * STMicroelectronics pressures driver 3 * 4 * Copyright 2013 STMicroelectronics Inc. 5 * 6 * Denis Ciocca <denis.ciocca@st.com> 7 * 8 * Licensed under the GPL-2. 9 */ 10 11 #include <linux/kernel.h> 12 #include <linux/module.h> 13 #include <linux/slab.h> 14 #include <linux/acpi.h> 15 #include <linux/i2c.h> 16 #include <linux/iio/iio.h> 17 18 #include <linux/iio/common/st_sensors.h> 19 #include <linux/iio/common/st_sensors_i2c.h> 20 #include "st_pressure.h" 21 22 #ifdef CONFIG_OF 23 static const struct of_device_id st_press_of_match[] = { 24 { 25 .compatible = "st,lps001wp-press", 26 .data = LPS001WP_PRESS_DEV_NAME, 27 }, 28 { 29 .compatible = "st,lps25h-press", 30 .data = LPS25H_PRESS_DEV_NAME, 31 }, 32 { 33 .compatible = "st,lps331ap-press", 34 .data = LPS331AP_PRESS_DEV_NAME, 35 }, 36 { 37 .compatible = "st,lps22hb-press", 38 .data = LPS22HB_PRESS_DEV_NAME, 39 }, 40 { 41 .compatible = "st,lps33hw", 42 .data = LPS33HW_PRESS_DEV_NAME, 43 }, 44 { 45 .compatible = "st,lps35hw", 46 .data = LPS35HW_PRESS_DEV_NAME, 47 }, 48 {}, 49 }; 50 MODULE_DEVICE_TABLE(of, st_press_of_match); 51 #else 52 #define st_press_of_match NULL 53 #endif 54 55 #ifdef CONFIG_ACPI 56 static const struct acpi_device_id st_press_acpi_match[] = { 57 {"SNO9210", LPS22HB}, 58 { }, 59 }; 60 MODULE_DEVICE_TABLE(acpi, st_press_acpi_match); 61 #else 62 #define st_press_acpi_match NULL 63 #endif 64 65 static const struct i2c_device_id st_press_id_table[] = { 66 { LPS001WP_PRESS_DEV_NAME, LPS001WP }, 67 { LPS25H_PRESS_DEV_NAME, LPS25H }, 68 { LPS331AP_PRESS_DEV_NAME, LPS331AP }, 69 { LPS22HB_PRESS_DEV_NAME, LPS22HB }, 70 { LPS33HW_PRESS_DEV_NAME, LPS33HW }, 71 { LPS35HW_PRESS_DEV_NAME, LPS35HW }, 72 {}, 73 }; 74 MODULE_DEVICE_TABLE(i2c, st_press_id_table); 75 76 static int st_press_i2c_probe(struct i2c_client *client, 77 const struct i2c_device_id *id) 78 { 79 struct iio_dev *indio_dev; 80 struct st_sensor_data *press_data; 81 int ret; 82 83 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data)); 84 if (!indio_dev) 85 return -ENOMEM; 86 87 press_data = iio_priv(indio_dev); 88 89 if (client->dev.of_node) { 90 st_sensors_of_name_probe(&client->dev, st_press_of_match, 91 client->name, sizeof(client->name)); 92 } else if (ACPI_HANDLE(&client->dev)) { 93 ret = st_sensors_match_acpi_device(&client->dev); 94 if ((ret < 0) || (ret >= ST_PRESS_MAX)) 95 return -ENODEV; 96 97 strlcpy(client->name, st_press_id_table[ret].name, 98 sizeof(client->name)); 99 } else if (!id) 100 return -ENODEV; 101 102 st_sensors_i2c_configure(indio_dev, client, press_data); 103 104 ret = st_press_common_probe(indio_dev); 105 if (ret < 0) 106 return ret; 107 108 return 0; 109 } 110 111 static int st_press_i2c_remove(struct i2c_client *client) 112 { 113 st_press_common_remove(i2c_get_clientdata(client)); 114 115 return 0; 116 } 117 118 static struct i2c_driver st_press_driver = { 119 .driver = { 120 .name = "st-press-i2c", 121 .of_match_table = of_match_ptr(st_press_of_match), 122 .acpi_match_table = ACPI_PTR(st_press_acpi_match), 123 }, 124 .probe = st_press_i2c_probe, 125 .remove = st_press_i2c_remove, 126 .id_table = st_press_id_table, 127 }; 128 module_i2c_driver(st_press_driver); 129 130 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 131 MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver"); 132 MODULE_LICENSE("GPL v2"); 133