Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 1 | /* I2C access for DA9055 PMICs. |
| 2 | * |
| 3 | * Copyright(c) 2012 Dialog Semiconductor Ltd. |
| 4 | * |
| 5 | * Author: David Dajun Chen <dchen@diasemi.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/i2c.h> |
| 17 | #include <linux/err.h> |
Adam Thomson | d9a33515 | 2014-03-05 14:18:35 +0000 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_device.h> |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 20 | |
| 21 | #include <linux/mfd/da9055/core.h> |
| 22 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 23 | static int da9055_i2c_probe(struct i2c_client *i2c, |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 24 | const struct i2c_device_id *id) |
| 25 | { |
| 26 | struct da9055 *da9055; |
| 27 | int ret; |
| 28 | |
| 29 | da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL); |
| 30 | if (!da9055) |
| 31 | return -ENOMEM; |
| 32 | |
| 33 | da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config); |
| 34 | if (IS_ERR(da9055->regmap)) { |
| 35 | ret = PTR_ERR(da9055->regmap); |
| 36 | dev_err(&i2c->dev, "Failed to allocate register map: %d\n", |
| 37 | ret); |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | da9055->dev = &i2c->dev; |
| 42 | da9055->chip_irq = i2c->irq; |
| 43 | |
| 44 | i2c_set_clientdata(i2c, da9055); |
| 45 | |
| 46 | return da9055_device_init(da9055); |
| 47 | } |
| 48 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 49 | static int da9055_i2c_remove(struct i2c_client *i2c) |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 50 | { |
| 51 | struct da9055 *da9055 = i2c_get_clientdata(i2c); |
| 52 | |
| 53 | da9055_device_exit(da9055); |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Adam Thomson | 07b0e5b | 2014-02-06 18:03:07 +0000 | [diff] [blame] | 58 | /* |
| 59 | * DO NOT change the device Ids. The naming is intentionally specific as both |
| 60 | * the PMIC and CODEC parts of this chip are instantiated separately as I2C |
| 61 | * devices (both have configurable I2C addresses, and are to all intents and |
| 62 | * purposes separate). As a result there are specific DA9055 ids for PMIC |
| 63 | * and CODEC, which must be different to operate together. |
| 64 | */ |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 65 | static struct i2c_device_id da9055_i2c_id[] = { |
Adam Thomson | 07b0e5b | 2014-02-06 18:03:07 +0000 | [diff] [blame] | 66 | {"da9055-pmic", 0}, |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 67 | { } |
| 68 | }; |
Adam Thomson | 07b0e5b | 2014-02-06 18:03:07 +0000 | [diff] [blame] | 69 | MODULE_DEVICE_TABLE(i2c, da9055_i2c_id); |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 70 | |
Adam Thomson | d9a33515 | 2014-03-05 14:18:35 +0000 | [diff] [blame] | 71 | static const struct of_device_id da9055_of_match[] = { |
| 72 | { .compatible = "dlg,da9055-pmic", }, |
| 73 | { } |
| 74 | }; |
| 75 | |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 76 | static struct i2c_driver da9055_i2c_driver = { |
| 77 | .probe = da9055_i2c_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 78 | .remove = da9055_i2c_remove, |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 79 | .id_table = da9055_i2c_id, |
| 80 | .driver = { |
Adam Thomson | 07b0e5b | 2014-02-06 18:03:07 +0000 | [diff] [blame] | 81 | .name = "da9055-pmic", |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 82 | .owner = THIS_MODULE, |
Adam Thomson | d9a33515 | 2014-03-05 14:18:35 +0000 | [diff] [blame] | 83 | .of_match_table = of_match_ptr(da9055_of_match), |
Ashish Jangam | 2896434 | 2012-09-14 18:54:50 +0530 | [diff] [blame] | 84 | }, |
| 85 | }; |
| 86 | |
| 87 | static int __init da9055_i2c_init(void) |
| 88 | { |
| 89 | int ret; |
| 90 | |
| 91 | ret = i2c_add_driver(&da9055_i2c_driver); |
| 92 | if (ret != 0) { |
| 93 | pr_err("DA9055 I2C registration failed %d\n", ret); |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | subsys_initcall(da9055_i2c_init); |
| 100 | |
| 101 | static void __exit da9055_i2c_exit(void) |
| 102 | { |
| 103 | i2c_del_driver(&da9055_i2c_driver); |
| 104 | } |
| 105 | module_exit(da9055_i2c_exit); |
| 106 | |
| 107 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); |
| 108 | MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC"); |
| 109 | MODULE_LICENSE("GPL"); |