| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* Hardware monitoring driver for Maxim MAX15301 |
| 4 |
* |
| 5 |
* Copyright (c) 2021 Flextronics International Sweden AB |
| 6 |
* |
| 7 |
* Even though the specification does not specifically mention it, |
| 8 |
* extensive empirical testing has revealed that auto-detection of |
| 9 |
* limit-registers will fail in a random fashion unless the delay |
| 10 |
* parameter is set to above about 80us. The default delay is set |
| 11 |
* to 100us to include some safety margin. |
| 12 |
*/ |
| 13 |
|
| 14 |
#include <linux/kernel.h> |
| 15 |
#include <linux/module.h> |
| 16 |
#include <linux/init.h> |
| 17 |
#include <linux/err.h> |
| 18 |
#include <linux/slab.h> |
| 19 |
#include <linux/i2c.h> |
| 20 |
#include <linux/ktime.h> |
| 21 |
#include <linux/delay.h> |
| 22 |
#include <linux/pmbus.h> |
| 23 |
#include "pmbus.h" |
| 24 |
|
| 25 |
static const struct i2c_device_id max15301_id[] = { |
| 26 |
{ "bmr461" }, |
| 27 |
{ "max15301" }, |
| 28 |
{ "max15303" }, |
| 29 |
{} |
| 30 |
}; |
| 31 |
MODULE_DEVICE_TABLE(i2c, max15301_id); |
| 32 |
|
| 33 |
struct max15301_data { |
| 34 |
int id; |
| 35 |
struct pmbus_driver_info info; |
| 36 |
}; |
| 37 |
|
| 38 |
#define to_max15301_data(x) container_of(x, struct max15301_data, info) |
| 39 |
|
| 40 |
#define MAX15301_WAIT_TIME 100 /* us */ |
| 41 |
|
| 42 |
static ushort delay = MAX15301_WAIT_TIME; |
| 43 |
module_param(delay, ushort, 0644); |
| 44 |
MODULE_PARM_DESC(delay, "Delay between chip accesses in us"); |
| 45 |
|
| 46 |
static struct max15301_data max15301_data = { |
| 47 |
.info = { |
| 48 |
.pages = 1, |
| 49 |
.func[0] = PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
| 50 |
| PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT |
| 51 |
| PMBUS_HAVE_TEMP | PMBUS_HAVE_TEMP2 |
| 52 |
| PMBUS_HAVE_STATUS_TEMP |
| 53 |
| PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT, |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
static int max15301_probe(struct i2c_client *client) |
| 58 |
{ |
| 59 |
int status; |
| 60 |
u8 device_id[I2C_SMBUS_BLOCK_MAX + 1]; |
| 61 |
const struct i2c_device_id *mid; |
| 62 |
struct pmbus_driver_info *info = &max15301_data.info; |
| 63 |
|
| 64 |
if (!i2c_check_functionality(client->adapter, |
| 65 |
I2C_FUNC_SMBUS_READ_BYTE_DATA |
| 66 |
| I2C_FUNC_SMBUS_BLOCK_DATA)) |
| 67 |
return -ENODEV; |
| 68 |
|
| 69 |
status = i2c_smbus_read_block_data(client, PMBUS_IC_DEVICE_ID, device_id); |
| 70 |
if (status < 0) { |
| 71 |
dev_err(&client->dev, "Failed to read Device Id\n"); |
| 72 |
return status; |
| 73 |
} |
| 74 |
for (mid = max15301_id; mid->name[0]; mid++) { |
| 75 |
if (!strncasecmp(mid->name, device_id, strlen(mid->name))) |
| 76 |
break; |
| 77 |
} |
| 78 |
if (!mid->name[0]) { |
| 79 |
dev_err(&client->dev, "Unsupported device\n"); |
| 80 |
return -ENODEV; |
| 81 |
} |
| 82 |
|
| 83 |
info->access_delay = delay; |
| 84 |
|
| 85 |
return pmbus_do_probe(client, info); |
| 86 |
} |
| 87 |
|
| 88 |
static struct i2c_driver max15301_driver = { |
| 89 |
.driver = { |
| 90 |
.name = "max15301", |
| 91 |
}, |
| 92 |
.probe = max15301_probe, |
| 93 |
.id_table = max15301_id, |
| 94 |
}; |
| 95 |
|
| 96 |
module_i2c_driver(max15301_driver); |
| 97 |
|
| 98 |
MODULE_AUTHOR("Erik Rosen <[email protected]>"); |
| 99 |
MODULE_DESCRIPTION("PMBus driver for Maxim MAX15301"); |
| 100 |
MODULE_LICENSE("GPL"); |
| 101 |
MODULE_IMPORT_NS("PMBUS"); |