Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002  /* I2C access for DA9055 PMICs.
0003  *
0004  * Copyright(c) 2012 Dialog Semiconductor Ltd.
0005  *
0006  * Author: David Dajun Chen <dchen@diasemi.com>
0007  */
0008 
0009 #include <linux/module.h>
0010 #include <linux/device.h>
0011 #include <linux/i2c.h>
0012 #include <linux/err.h>
0013 #include <linux/of.h>
0014 #include <linux/of_device.h>
0015 
0016 #include <linux/mfd/da9055/core.h>
0017 
0018 static int da9055_i2c_probe(struct i2c_client *i2c,
0019                       const struct i2c_device_id *id)
0020 {
0021     struct da9055 *da9055;
0022     int ret;
0023 
0024     da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL);
0025     if (!da9055)
0026         return -ENOMEM;
0027 
0028     da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
0029     if (IS_ERR(da9055->regmap)) {
0030         ret = PTR_ERR(da9055->regmap);
0031         dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
0032             ret);
0033         return ret;
0034     }
0035 
0036     da9055->dev = &i2c->dev;
0037     da9055->chip_irq = i2c->irq;
0038 
0039     i2c_set_clientdata(i2c, da9055);
0040 
0041     return da9055_device_init(da9055);
0042 }
0043 
0044 static int da9055_i2c_remove(struct i2c_client *i2c)
0045 {
0046     struct da9055 *da9055 = i2c_get_clientdata(i2c);
0047 
0048     da9055_device_exit(da9055);
0049 
0050     return 0;
0051 }
0052 
0053 /*
0054  * DO NOT change the device Ids. The naming is intentionally specific as both
0055  * the PMIC and CODEC parts of this chip are instantiated separately as I2C
0056  * devices (both have configurable I2C addresses, and are to all intents and
0057  * purposes separate). As a result there are specific DA9055 ids for PMIC
0058  * and CODEC, which must be different to operate together.
0059  */
0060 static const struct i2c_device_id da9055_i2c_id[] = {
0061     {"da9055-pmic", 0},
0062     { }
0063 };
0064 MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
0065 
0066 static const struct of_device_id da9055_of_match[] = {
0067     { .compatible = "dlg,da9055-pmic", },
0068     { }
0069 };
0070 
0071 static struct i2c_driver da9055_i2c_driver = {
0072     .probe = da9055_i2c_probe,
0073     .remove = da9055_i2c_remove,
0074     .id_table = da9055_i2c_id,
0075     .driver = {
0076         .name = "da9055-pmic",
0077         .of_match_table = da9055_of_match,
0078     },
0079 };
0080 
0081 static int __init da9055_i2c_init(void)
0082 {
0083     int ret;
0084 
0085     ret = i2c_add_driver(&da9055_i2c_driver);
0086     if (ret != 0) {
0087         pr_err("DA9055 I2C registration failed %d\n", ret);
0088         return ret;
0089     }
0090 
0091     return 0;
0092 }
0093 subsys_initcall(da9055_i2c_init);
0094 
0095 static void __exit da9055_i2c_exit(void)
0096 {
0097     i2c_del_driver(&da9055_i2c_driver);
0098 }
0099 module_exit(da9055_i2c_exit);
0100 
0101 MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
0102 MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC");
0103 MODULE_LICENSE("GPL");