|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +/* |
| 3 | + * Copyright (c) 2025 Analog Devices, Inc. |
| 4 | + * ADI regulator driver for MAX77675. |
| 5 | + */ |
| 6 | + |
| 7 | +#include <linux/module.h> |
| 8 | +#include <linux/i2c.h> |
| 9 | +#include <linux/regulator/driver.h> |
| 10 | +#include <linux/of_device.h> |
| 11 | +#include <linux/regmap.h> |
| 12 | + |
| 13 | +#define MAX77675_NUM_REGULATORS 4 |
| 14 | + |
| 15 | +struct max77675_regulator { |
| 16 | + struct device *dev; |
| 17 | + struct regulator_dev *rdev[MAX77675_NUM_REGULATORS]; |
| 18 | + struct regmap *regmap; |
| 19 | +}; |
| 20 | + |
| 21 | +static const struct regulator_ops max77675_regulator_ops = { |
| 22 | + .enable = regulator_enable_regmap, |
| 23 | + .disable = regulator_disable_regmap, |
| 24 | + .is_enabled = regulator_is_enabled_regmap, |
| 25 | + .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 26 | + .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 27 | +}; |
| 28 | + |
| 29 | +static const struct regulator_desc max77675_regulators[] = { |
| 30 | + { |
| 31 | + .name = "simo0", |
| 32 | + .id = 0, |
| 33 | + .ops = &max77675_regulator_ops, |
| 34 | + .type = REGULATOR_VOLTAGE, |
| 35 | + .owner = THIS_MODULE, |
| 36 | + .n_voltages = 64, |
| 37 | + .min_uV = 500000, |
| 38 | + .uV_step = 50000, |
| 39 | + .vsel_reg = 0x10, // example value : SIMO0 VOUT |
| 40 | + .vsel_mask = 0x3F, |
| 41 | + .enable_reg = 0x20, // example value : SIMO0 ENABLE |
| 42 | + .enable_mask = 0x01, |
| 43 | + }, |
| 44 | +}; |
| 45 | + |
| 46 | +static int max77675_probe(struct i2c_client *client, const struct i2c_device_id *id) |
| 47 | +{ |
| 48 | + struct max77675_regulator *priv; |
| 49 | + int i, ret; |
| 50 | + |
| 51 | + priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); |
| 52 | + if (!priv) |
| 53 | + return -ENOMEM; |
| 54 | + |
| 55 | + i2c_set_clientdata(client, priv); |
| 56 | + |
| 57 | + priv->regmap = devm_regmap_init_i2c(client, &some_regmap_config); |
| 58 | + if (IS_ERR(priv->regmap)) |
| 59 | + return dev_err_probe(&client->dev, PTR_ERR(priv->regmap), "regmap init failed"); |
| 60 | + |
| 61 | + for (i = 0; i < MAX77675_NUM_REGULATORS; i++) { |
| 62 | + struct regulator_config config = {}; |
| 63 | + config.dev = &client->dev; |
| 64 | + config.regmap = priv->regmap; |
| 65 | + |
| 66 | + priv->rdev[i] = devm_regulator_register(&client->dev, |
| 67 | + &max77675_regulators[i], &config); |
| 68 | + if (IS_ERR(priv->rdev[i])) { |
| 69 | + dev_err(&client->dev, "Failed to register regulator %d\n", i); |
| 70 | + return PTR_ERR(priv->rdev[i]); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + dev_info(&client->dev, "MAX77675 regulator driver loaded\n"); |
| 75 | + return 0; |
| 76 | +} |
| 77 | + |
| 78 | +static const struct of_device_id max77675_of_match[] = { |
| 79 | + { .compatible = "maxim,max77675", }, |
| 80 | + { /* sentinel */ } |
| 81 | +}; |
| 82 | +MODULE_DEVICE_TABLE(of, max77675_of_match); |
| 83 | + |
| 84 | +static const struct i2c_device_id max77675_id[] = { |
| 85 | + { "max77675", 0 }, |
| 86 | + { } |
| 87 | +}; |
| 88 | +MODULE_DEVICE_TABLE(i2c, max77675_id); |
| 89 | + |
| 90 | +static struct i2c_driver max77675_driver = { |
| 91 | + .driver = { |
| 92 | + .name = "max77675", |
| 93 | + .of_match_table = max77675_of_match, |
| 94 | + }, |
| 95 | + .probe = max77675_probe, |
| 96 | + .id_table = max77675_id, |
| 97 | +}; |
| 98 | + |
| 99 | +module_i2c_driver(max77675_driver); |
| 100 | + |
| 101 | +MODULE_AUTHOR("joan.na@analog.com"); |
| 102 | +MODULE_DESCRIPTION("MAX77675 Regulator Driver"); |
| 103 | +MODULE_LICENSE("GPL"); |
| 104 | + |
0 commit comments