0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/atomic.h>
0009 #include <linux/bug.h>
0010 #include <linux/completion.h>
0011 #include <linux/device.h>
0012 #include <linux/mutex.h>
0013 #include <linux/slab.h>
0014
0015 #include "internals.h"
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 int i3c_device_do_priv_xfers(struct i3c_device *dev,
0032 struct i3c_priv_xfer *xfers,
0033 int nxfers)
0034 {
0035 int ret, i;
0036
0037 if (nxfers < 1)
0038 return 0;
0039
0040 for (i = 0; i < nxfers; i++) {
0041 if (!xfers[i].len || !xfers[i].data.in)
0042 return -EINVAL;
0043 }
0044
0045 i3c_bus_normaluse_lock(dev->bus);
0046 ret = i3c_dev_do_priv_xfers_locked(dev->desc, xfers, nxfers);
0047 i3c_bus_normaluse_unlock(dev->bus);
0048
0049 return ret;
0050 }
0051 EXPORT_SYMBOL_GPL(i3c_device_do_priv_xfers);
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 void i3c_device_get_info(struct i3c_device *dev,
0062 struct i3c_device_info *info)
0063 {
0064 if (!info)
0065 return;
0066
0067 i3c_bus_normaluse_lock(dev->bus);
0068 if (dev->desc)
0069 *info = dev->desc->info;
0070 i3c_bus_normaluse_unlock(dev->bus);
0071 }
0072 EXPORT_SYMBOL_GPL(i3c_device_get_info);
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 int i3c_device_disable_ibi(struct i3c_device *dev)
0084 {
0085 int ret = -ENOENT;
0086
0087 i3c_bus_normaluse_lock(dev->bus);
0088 if (dev->desc) {
0089 mutex_lock(&dev->desc->ibi_lock);
0090 ret = i3c_dev_disable_ibi_locked(dev->desc);
0091 mutex_unlock(&dev->desc->ibi_lock);
0092 }
0093 i3c_bus_normaluse_unlock(dev->bus);
0094
0095 return ret;
0096 }
0097 EXPORT_SYMBOL_GPL(i3c_device_disable_ibi);
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 int i3c_device_enable_ibi(struct i3c_device *dev)
0113 {
0114 int ret = -ENOENT;
0115
0116 i3c_bus_normaluse_lock(dev->bus);
0117 if (dev->desc) {
0118 mutex_lock(&dev->desc->ibi_lock);
0119 ret = i3c_dev_enable_ibi_locked(dev->desc);
0120 mutex_unlock(&dev->desc->ibi_lock);
0121 }
0122 i3c_bus_normaluse_unlock(dev->bus);
0123
0124 return ret;
0125 }
0126 EXPORT_SYMBOL_GPL(i3c_device_enable_ibi);
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 int i3c_device_request_ibi(struct i3c_device *dev,
0140 const struct i3c_ibi_setup *req)
0141 {
0142 int ret = -ENOENT;
0143
0144 if (!req->handler || !req->num_slots)
0145 return -EINVAL;
0146
0147 i3c_bus_normaluse_lock(dev->bus);
0148 if (dev->desc) {
0149 mutex_lock(&dev->desc->ibi_lock);
0150 ret = i3c_dev_request_ibi_locked(dev->desc, req);
0151 mutex_unlock(&dev->desc->ibi_lock);
0152 }
0153 i3c_bus_normaluse_unlock(dev->bus);
0154
0155 return ret;
0156 }
0157 EXPORT_SYMBOL_GPL(i3c_device_request_ibi);
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 void i3c_device_free_ibi(struct i3c_device *dev)
0168 {
0169 i3c_bus_normaluse_lock(dev->bus);
0170 if (dev->desc) {
0171 mutex_lock(&dev->desc->ibi_lock);
0172 i3c_dev_free_ibi_locked(dev->desc);
0173 mutex_unlock(&dev->desc->ibi_lock);
0174 }
0175 i3c_bus_normaluse_unlock(dev->bus);
0176 }
0177 EXPORT_SYMBOL_GPL(i3c_device_free_ibi);
0178
0179
0180
0181
0182
0183
0184
0185 struct device *i3cdev_to_dev(struct i3c_device *i3cdev)
0186 {
0187 return &i3cdev->dev;
0188 }
0189 EXPORT_SYMBOL_GPL(i3cdev_to_dev);
0190
0191
0192
0193
0194
0195
0196
0197 struct i3c_device *dev_to_i3cdev(struct device *dev)
0198 {
0199 return container_of(dev, struct i3c_device, dev);
0200 }
0201 EXPORT_SYMBOL_GPL(dev_to_i3cdev);
0202
0203
0204
0205
0206
0207
0208
0209
0210 const struct i3c_device_id *
0211 i3c_device_match_id(struct i3c_device *i3cdev,
0212 const struct i3c_device_id *id_table)
0213 {
0214 struct i3c_device_info devinfo;
0215 const struct i3c_device_id *id;
0216 u16 manuf, part, ext_info;
0217 bool rndpid;
0218
0219 i3c_device_get_info(i3cdev, &devinfo);
0220
0221 manuf = I3C_PID_MANUF_ID(devinfo.pid);
0222 part = I3C_PID_PART_ID(devinfo.pid);
0223 ext_info = I3C_PID_EXTRA_INFO(devinfo.pid);
0224 rndpid = I3C_PID_RND_LOWER_32BITS(devinfo.pid);
0225
0226 for (id = id_table; id->match_flags != 0; id++) {
0227 if ((id->match_flags & I3C_MATCH_DCR) &&
0228 id->dcr != devinfo.dcr)
0229 continue;
0230
0231 if ((id->match_flags & I3C_MATCH_MANUF) &&
0232 id->manuf_id != manuf)
0233 continue;
0234
0235 if ((id->match_flags & I3C_MATCH_PART) &&
0236 (rndpid || id->part_id != part))
0237 continue;
0238
0239 if ((id->match_flags & I3C_MATCH_EXTRA_INFO) &&
0240 (rndpid || id->extra_info != ext_info))
0241 continue;
0242
0243 return id;
0244 }
0245
0246 return NULL;
0247 }
0248 EXPORT_SYMBOL_GPL(i3c_device_match_id);
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260 int i3c_driver_register_with_owner(struct i3c_driver *drv, struct module *owner)
0261 {
0262 drv->driver.owner = owner;
0263 drv->driver.bus = &i3c_bus_type;
0264
0265 if (!drv->probe) {
0266 pr_err("Trying to register an i3c driver without probe callback\n");
0267 return -EINVAL;
0268 }
0269
0270 return driver_register(&drv->driver);
0271 }
0272 EXPORT_SYMBOL_GPL(i3c_driver_register_with_owner);
0273
0274
0275
0276
0277
0278
0279
0280
0281 void i3c_driver_unregister(struct i3c_driver *drv)
0282 {
0283 driver_unregister(&drv->driver);
0284 }
0285 EXPORT_SYMBOL_GPL(i3c_driver_unregister);