blob: 4a0afc7f2d4e4b8d6a37927522a2f15952d5ddc6 [file] [log] [blame]
Marc Reillydf3df642012-04-01 16:41:39 +10001/*
2 * Copyright 2009-2010 Creative Product Design
3 * Marc Reilly marc@cpdesign.com.au
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation.
8 */
9
10#include <linux/slab.h>
11#include <linux/module.h>
12#include <linux/platform_device.h>
13#include <linux/mutex.h>
14#include <linux/mfd/core.h>
15#include <linux/mfd/mc13xxx.h>
16#include <linux/of.h>
17#include <linux/of_device.h>
18#include <linux/of_gpio.h>
19#include <linux/i2c.h>
20#include <linux/err.h>
21
22#include "mc13xxx.h"
23
24static const struct i2c_device_id mc13xxx_i2c_device_id[] = {
25 {
26 .name = "mc13892",
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000027 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
Marc Reillydf3df642012-04-01 16:41:39 +100028 }, {
29 /* sentinel */
30 }
31};
32MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
33
34static const struct of_device_id mc13xxx_dt_ids[] = {
35 {
36 .compatible = "fsl,mc13892",
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000037 .data = &mc13xxx_variant_mc13892,
Marc Reillydf3df642012-04-01 16:41:39 +100038 }, {
39 /* sentinel */
40 }
41};
42MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
43
44static struct regmap_config mc13xxx_regmap_i2c_config = {
45 .reg_bits = 8,
46 .val_bits = 24,
47
48 .max_register = MC13XXX_NUMREGS,
49
50 .cache_type = REGCACHE_NONE,
51};
52
53static int mc13xxx_i2c_probe(struct i2c_client *client,
54 const struct i2c_device_id *id)
55{
Marc Reillydf3df642012-04-01 16:41:39 +100056 struct mc13xxx *mc13xxx;
57 struct mc13xxx_platform_data *pdata = dev_get_platdata(&client->dev);
58 int ret;
59
Axel Line7c706b2012-06-29 15:14:36 +020060 mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
Marc Reillydf3df642012-04-01 16:41:39 +100061 if (!mc13xxx)
62 return -ENOMEM;
63
64 dev_set_drvdata(&client->dev, mc13xxx);
65
66 mc13xxx->dev = &client->dev;
67 mutex_init(&mc13xxx->lock);
68
Axel Line7c706b2012-06-29 15:14:36 +020069 mc13xxx->regmap = devm_regmap_init_i2c(client,
70 &mc13xxx_regmap_i2c_config);
Marc Reillydf3df642012-04-01 16:41:39 +100071 if (IS_ERR(mc13xxx->regmap)) {
72 ret = PTR_ERR(mc13xxx->regmap);
73 dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n",
74 ret);
75 dev_set_drvdata(&client->dev, NULL);
Marc Reillydf3df642012-04-01 16:41:39 +100076 return ret;
77 }
78
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000079 if (client->dev.of_node) {
80 const struct of_device_id *of_id =
81 of_match_device(mc13xxx_dt_ids, &client->dev);
82 mc13xxx->variant = of_id->data;
83 } else {
84 mc13xxx->variant = (void *)id->driver_data;
85 }
Marc Reillydf3df642012-04-01 16:41:39 +100086
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000087 ret = mc13xxx_common_init(mc13xxx, pdata, client->irq);
Marc Reillydf3df642012-04-01 16:41:39 +100088
89 return ret;
90}
91
92static int __devexit mc13xxx_i2c_remove(struct i2c_client *client)
93{
94 struct mc13xxx *mc13xxx = dev_get_drvdata(&client->dev);
95
96 mc13xxx_common_cleanup(mc13xxx);
97
98 return 0;
99}
100
101static struct i2c_driver mc13xxx_i2c_driver = {
102 .id_table = mc13xxx_i2c_device_id,
103 .driver = {
104 .owner = THIS_MODULE,
105 .name = "mc13xxx",
106 .of_match_table = mc13xxx_dt_ids,
107 },
108 .probe = mc13xxx_i2c_probe,
109 .remove = __devexit_p(mc13xxx_i2c_remove),
110};
111
112static int __init mc13xxx_i2c_init(void)
113{
114 return i2c_add_driver(&mc13xxx_i2c_driver);
115}
116subsys_initcall(mc13xxx_i2c_init);
117
118static void __exit mc13xxx_i2c_exit(void)
119{
120 i2c_del_driver(&mc13xxx_i2c_driver);
121}
122module_exit(mc13xxx_i2c_exit);
123
124MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
125MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
126MODULE_LICENSE("GPL v2");