Thomas Gleixner | fda8d26 | 2019-05-28 09:57:06 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 2 | /* |
| 3 | * STMicroelectronics pressures driver |
| 4 | * |
| 5 | * Copyright 2013 STMicroelectronics Inc. |
| 6 | * |
| 7 | * Denis Ciocca <denis.ciocca@st.com> |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/slab.h> |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 13 | #include <linux/acpi.h> |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 14 | #include <linux/i2c.h> |
| 15 | #include <linux/iio/iio.h> |
| 16 | |
| 17 | #include <linux/iio/common/st_sensors.h> |
| 18 | #include <linux/iio/common/st_sensors_i2c.h> |
| 19 | #include "st_pressure.h" |
| 20 | |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 21 | #ifdef CONFIG_OF |
| 22 | static const struct of_device_id st_press_of_match[] = { |
| 23 | { |
| 24 | .compatible = "st,lps001wp-press", |
| 25 | .data = LPS001WP_PRESS_DEV_NAME, |
| 26 | }, |
| 27 | { |
| 28 | .compatible = "st,lps25h-press", |
| 29 | .data = LPS25H_PRESS_DEV_NAME, |
| 30 | }, |
| 31 | { |
| 32 | .compatible = "st,lps331ap-press", |
| 33 | .data = LPS331AP_PRESS_DEV_NAME, |
| 34 | }, |
Gregor Boirie | e039e2f | 2016-04-19 11:18:32 +0200 | [diff] [blame] | 35 | { |
| 36 | .compatible = "st,lps22hb-press", |
| 37 | .data = LPS22HB_PRESS_DEV_NAME, |
| 38 | }, |
Lorenzo Bianconi | b954d77 | 2017-09-02 19:39:14 +0200 | [diff] [blame] | 39 | { |
| 40 | .compatible = "st,lps33hw", |
| 41 | .data = LPS33HW_PRESS_DEV_NAME, |
| 42 | }, |
| 43 | { |
| 44 | .compatible = "st,lps35hw", |
| 45 | .data = LPS35HW_PRESS_DEV_NAME, |
| 46 | }, |
mario tesi | e5aab7b | 2019-01-14 18:24:20 +0100 | [diff] [blame] | 47 | { |
| 48 | .compatible = "st,lps22hh", |
| 49 | .data = LPS22HH_PRESS_DEV_NAME, |
| 50 | }, |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 51 | {}, |
| 52 | }; |
| 53 | MODULE_DEVICE_TABLE(of, st_press_of_match); |
| 54 | #else |
| 55 | #define st_press_of_match NULL |
| 56 | #endif |
| 57 | |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 58 | #ifdef CONFIG_ACPI |
| 59 | static const struct acpi_device_id st_press_acpi_match[] = { |
| 60 | {"SNO9210", LPS22HB}, |
| 61 | { }, |
| 62 | }; |
| 63 | MODULE_DEVICE_TABLE(acpi, st_press_acpi_match); |
| 64 | #else |
| 65 | #define st_press_acpi_match NULL |
| 66 | #endif |
| 67 | |
| 68 | static const struct i2c_device_id st_press_id_table[] = { |
| 69 | { LPS001WP_PRESS_DEV_NAME, LPS001WP }, |
| 70 | { LPS25H_PRESS_DEV_NAME, LPS25H }, |
| 71 | { LPS331AP_PRESS_DEV_NAME, LPS331AP }, |
| 72 | { LPS22HB_PRESS_DEV_NAME, LPS22HB }, |
Lorenzo Bianconi | b954d77 | 2017-09-02 19:39:14 +0200 | [diff] [blame] | 73 | { LPS33HW_PRESS_DEV_NAME, LPS33HW }, |
| 74 | { LPS35HW_PRESS_DEV_NAME, LPS35HW }, |
mario tesi | e5aab7b | 2019-01-14 18:24:20 +0100 | [diff] [blame] | 75 | { LPS22HH_PRESS_DEV_NAME, LPS22HH }, |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 76 | {}, |
| 77 | }; |
| 78 | MODULE_DEVICE_TABLE(i2c, st_press_id_table); |
| 79 | |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 80 | static int st_press_i2c_probe(struct i2c_client *client, |
Denis Ciocca | 570c2c5 | 2019-07-18 15:53:51 -0700 | [diff] [blame] | 81 | const struct i2c_device_id *id) |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 82 | { |
Denis Ciocca | 570c2c5 | 2019-07-18 15:53:51 -0700 | [diff] [blame] | 83 | const struct st_sensor_settings *settings; |
Denis CIOCCA | a1dcf42 | 2014-10-03 17:35:40 +0200 | [diff] [blame] | 84 | struct st_sensor_data *press_data; |
Denis Ciocca | 570c2c5 | 2019-07-18 15:53:51 -0700 | [diff] [blame] | 85 | struct iio_dev *indio_dev; |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 86 | int ret; |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 87 | |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 88 | if (client->dev.of_node) { |
Lorenzo Bianconi | 250bbbd | 2017-06-20 21:52:08 +0200 | [diff] [blame] | 89 | st_sensors_of_name_probe(&client->dev, st_press_of_match, |
| 90 | client->name, sizeof(client->name)); |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 91 | } else if (ACPI_HANDLE(&client->dev)) { |
| 92 | ret = st_sensors_match_acpi_device(&client->dev); |
| 93 | if ((ret < 0) || (ret >= ST_PRESS_MAX)) |
| 94 | return -ENODEV; |
| 95 | |
Dominique Martinet | cd570e6 | 2018-07-13 03:25:34 +0200 | [diff] [blame] | 96 | strlcpy(client->name, st_press_id_table[ret].name, |
Denis Ciocca | 570c2c5 | 2019-07-18 15:53:51 -0700 | [diff] [blame] | 97 | sizeof(client->name)); |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 98 | } else if (!id) |
| 99 | return -ENODEV; |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 100 | |
Denis Ciocca | 570c2c5 | 2019-07-18 15:53:51 -0700 | [diff] [blame] | 101 | settings = st_press_get_settings(client->name); |
| 102 | if (!settings) { |
| 103 | dev_err(&client->dev, "device name %s not recognized.\n", |
| 104 | client->name); |
| 105 | return -ENODEV; |
| 106 | } |
| 107 | |
| 108 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data)); |
| 109 | if (!indio_dev) |
| 110 | return -ENOMEM; |
| 111 | |
| 112 | press_data = iio_priv(indio_dev); |
| 113 | press_data->sensor_settings = (struct st_sensor_settings *)settings; |
| 114 | |
Denis Ciocca | 062809e | 2019-07-18 15:53:53 -0700 | [diff] [blame] | 115 | ret = st_sensors_i2c_configure(indio_dev, client); |
| 116 | if (ret < 0) |
| 117 | return ret; |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 118 | |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 119 | ret = st_press_common_probe(indio_dev); |
| 120 | if (ret < 0) |
| 121 | return ret; |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 122 | |
| 123 | return 0; |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static int st_press_i2c_remove(struct i2c_client *client) |
| 127 | { |
| 128 | st_press_common_remove(i2c_get_clientdata(client)); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 133 | static struct i2c_driver st_press_driver = { |
| 134 | .driver = { |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 135 | .name = "st-press-i2c", |
Linus Walleij | 2d7768a | 2014-08-07 08:16:00 +0100 | [diff] [blame] | 136 | .of_match_table = of_match_ptr(st_press_of_match), |
Shrirang Bagul | 9d31772 | 2016-11-24 13:33:45 +0800 | [diff] [blame] | 137 | .acpi_match_table = ACPI_PTR(st_press_acpi_match), |
Denis CIOCCA | 217494e | 2013-06-03 15:58:00 +0100 | [diff] [blame] | 138 | }, |
| 139 | .probe = st_press_i2c_probe, |
| 140 | .remove = st_press_i2c_remove, |
| 141 | .id_table = st_press_id_table, |
| 142 | }; |
| 143 | module_i2c_driver(st_press_driver); |
| 144 | |
| 145 | MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); |
| 146 | MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver"); |
| 147 | MODULE_LICENSE("GPL v2"); |