Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 2 | /* I2C access for DA9055 PMICs. |
| 3 | * |
| 4 | * Copyright(c) 2012 Dialog Semiconductor Ltd. |
| 5 | * |
| 6 | * Author: David Dajun Chen <dchen@diasemi.com> |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/device.h> |
| 11 | #include <linux/i2c.h> |
| 12 | #include <linux/err.h> |
Adam Thomson | d9a33515 | 2014-03-05 14:18:35 +0000 | [diff] [blame] | 13 | #include <linux/of.h> |
| 14 | #include <linux/of_device.h> |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 15 | |
| 16 | #include <linux/mfd/da9055/core.h> |
| 17 | |
Uwe Kleine-König | d429772 | 2022-11-18 23:42:41 +0100 | [diff] [blame] | 18 | static int da9055_i2c_probe(struct i2c_client *i2c) |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 19 | { |
| 20 | struct da9055 *da9055; |
| 21 | int ret; |
| 22 | |
| 23 | da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL); |
| 24 | if (!da9055) |
| 25 | return -ENOMEM; |
| 26 | |
| 27 | da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config); |
| 28 | if (IS_ERR(da9055->regmap)) { |
| 29 | ret = PTR_ERR(da9055->regmap); |
| 30 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
| 31 | ret); |
| 32 | return ret; |
| 33 | } |
| 34 | |
| 35 | da9055->dev = &i2c->dev; |
| 36 | da9055->chip_irq = i2c->irq; |
| 37 | |
| 38 | i2c_set_clientdata(i2c, da9055); |
| 39 | |
| 40 | return da9055_device_init(da9055); |
| 41 | } |
| 42 | |
Uwe Kleine-König | ed5c2f5 | 2022-08-15 10:02:30 +0200 | [diff] [blame] | 43 | static void da9055_i2c_remove(struct i2c_client *i2c) |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 44 | { |
| 45 | struct da9055 *da9055 = i2c_get_clientdata(i2c); |
| 46 | |
| 47 | da9055_device_exit(da9055); |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 48 | } |
| 49 | |
Adam Thomson | 07b0e5b | 2014-02-06 18:03:07 +0000 | [diff] [blame] | 50 | /* |
| 51 | * DO NOT change the device Ids. The naming is intentionally specific as both |
| 52 | * the PMIC and CODEC parts of this chip are instantiated separately as I2C |
| 53 | * devices (both have configurable I2C addresses, and are to all intents and |
| 54 | * purposes separate). As a result there are specific DA9055 ids for PMIC |
| 55 | * and CODEC, which must be different to operate together. |
| 56 | */ |
Arvind Yadav | 6af42e5 | 2017-08-20 00:59:37 +0530 | [diff] [blame] | 57 | static const struct i2c_device_id da9055_i2c_id[] = { |
Adam Thomson | 07b0e5b | 2014-02-06 18:03:07 +0000 | [diff] [blame] | 58 | {"da9055-pmic", 0}, |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 59 | { } |
| 60 | }; |
Adam Thomson | 07b0e5b | 2014-02-06 18:03:07 +0000 | [diff] [blame] | 61 | MODULE_DEVICE_TABLE(i2c, da9055_i2c_id); |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 62 | |
Adam Thomson | d9a33515 | 2014-03-05 14:18:35 +0000 | [diff] [blame] | 63 | static const struct of_device_id da9055_of_match[] = { |
| 64 | { .compatible = "dlg,da9055-pmic", }, |
| 65 | { } |
| 66 | }; |
| 67 | |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 68 | static struct i2c_driver da9055_i2c_driver = { |
Uwe Kleine-König | d429772 | 2022-11-18 23:42:41 +0100 | [diff] [blame] | 69 | .probe_new = da9055_i2c_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 70 | .remove = da9055_i2c_remove, |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 71 | .id_table = da9055_i2c_id, |
| 72 | .driver = { |
Adam Thomson | 07b0e5b | 2014-02-06 18:03:07 +0000 | [diff] [blame] | 73 | .name = "da9055-pmic", |
Krzysztof Kozlowski | 62e7407 | 2020-11-20 17:21:19 +0100 | [diff] [blame] | 74 | .of_match_table = da9055_of_match, |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 75 | }, |
| 76 | }; |
| 77 | |
| 78 | static int __init da9055_i2c_init(void) |
| 79 | { |
| 80 | int ret; |
| 81 | |
| 82 | ret = i2c_add_driver(&da9055_i2c_driver); |
| 83 | if (ret != 0) { |
| 84 | pr_err("DA9055 I2C registration failed %d\n", ret); |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | subsys_initcall(da9055_i2c_init); |
| 91 | |
| 92 | static void __exit da9055_i2c_exit(void) |
| 93 | { |
| 94 | i2c_del_driver(&da9055_i2c_driver); |
| 95 | } |
| 96 | module_exit(da9055_i2c_exit); |
| 97 | |
| 98 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); |
| 99 | MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC"); |
| 100 | MODULE_LICENSE("GPL"); |