blob: bc60433b68db7d128d3019addda77fd6d2eb376b [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Ashish Jangam28964342012-09-14 18:54:50 +05302 /* I2C access for DA9055 PMICs.
3 *
4 * Copyright(c) 2012 Dialog Semiconductor Ltd.
5 *
6 * Author: David Dajun Chen <dchen@diasemi.com>
Ashish Jangam28964342012-09-14 18:54:50 +05307 */
8
9#include <linux/module.h>
10#include <linux/device.h>
11#include <linux/i2c.h>
12#include <linux/err.h>
Adam Thomsond9a335152014-03-05 14:18:35 +000013#include <linux/of.h>
14#include <linux/of_device.h>
Ashish Jangam28964342012-09-14 18:54:50 +053015
16#include <linux/mfd/da9055/core.h>
17
Bill Pembertonf791be42012-11-19 13:23:04 -050018static int da9055_i2c_probe(struct i2c_client *i2c,
Ashish Jangam28964342012-09-14 18:54:50 +053019 const struct i2c_device_id *id)
20{
21 struct da9055 *da9055;
22 int ret;
23
24 da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL);
25 if (!da9055)
26 return -ENOMEM;
27
28 da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
29 if (IS_ERR(da9055->regmap)) {
30 ret = PTR_ERR(da9055->regmap);
31 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
32 ret);
33 return ret;
34 }
35
36 da9055->dev = &i2c->dev;
37 da9055->chip_irq = i2c->irq;
38
39 i2c_set_clientdata(i2c, da9055);
40
41 return da9055_device_init(da9055);
42}
43
Bill Pemberton4740f732012-11-19 13:26:01 -050044static int da9055_i2c_remove(struct i2c_client *i2c)
Ashish Jangam28964342012-09-14 18:54:50 +053045{
46 struct da9055 *da9055 = i2c_get_clientdata(i2c);
47
48 da9055_device_exit(da9055);
49
50 return 0;
51}
52
Adam Thomson07b0e5b2014-02-06 18:03:07 +000053/*
54 * DO NOT change the device Ids. The naming is intentionally specific as both
55 * the PMIC and CODEC parts of this chip are instantiated separately as I2C
56 * devices (both have configurable I2C addresses, and are to all intents and
57 * purposes separate). As a result there are specific DA9055 ids for PMIC
58 * and CODEC, which must be different to operate together.
59 */
Arvind Yadav6af42e52017-08-20 00:59:37 +053060static const struct i2c_device_id da9055_i2c_id[] = {
Adam Thomson07b0e5b2014-02-06 18:03:07 +000061 {"da9055-pmic", 0},
Ashish Jangam28964342012-09-14 18:54:50 +053062 { }
63};
Adam Thomson07b0e5b2014-02-06 18:03:07 +000064MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
Ashish Jangam28964342012-09-14 18:54:50 +053065
Adam Thomsond9a335152014-03-05 14:18:35 +000066static const struct of_device_id da9055_of_match[] = {
67 { .compatible = "dlg,da9055-pmic", },
68 { }
69};
70
Ashish Jangam28964342012-09-14 18:54:50 +053071static struct i2c_driver da9055_i2c_driver = {
72 .probe = da9055_i2c_probe,
Bill Pemberton84449212012-11-19 13:20:24 -050073 .remove = da9055_i2c_remove,
Ashish Jangam28964342012-09-14 18:54:50 +053074 .id_table = da9055_i2c_id,
75 .driver = {
Adam Thomson07b0e5b2014-02-06 18:03:07 +000076 .name = "da9055-pmic",
Krzysztof Kozlowski62e74072020-11-20 17:21:19 +010077 .of_match_table = da9055_of_match,
Ashish Jangam28964342012-09-14 18:54:50 +053078 },
79};
80
81static int __init da9055_i2c_init(void)
82{
83 int ret;
84
85 ret = i2c_add_driver(&da9055_i2c_driver);
86 if (ret != 0) {
87 pr_err("DA9055 I2C registration failed %d\n", ret);
88 return ret;
89 }
90
91 return 0;
92}
93subsys_initcall(da9055_i2c_init);
94
95static void __exit da9055_i2c_exit(void)
96{
97 i2c_del_driver(&da9055_i2c_driver);
98}
99module_exit(da9055_i2c_exit);
100
101MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
102MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC");
103MODULE_LICENSE("GPL");