blob: 898bd335cd8ee99d7d8a2c233ef455801941ff30 [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 }, {
Uwe Kleine-König0312e022012-07-12 09:57:53 +000029 .name = "mc34708",
30 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc34708,
Marc Reillydf3df642012-04-01 16:41:39 +100031 }, {
32 /* sentinel */
33 }
34};
35MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
36
37static const struct of_device_id mc13xxx_dt_ids[] = {
38 {
39 .compatible = "fsl,mc13892",
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000040 .data = &mc13xxx_variant_mc13892,
Marc Reillydf3df642012-04-01 16:41:39 +100041 }, {
Uwe Kleine-König0312e022012-07-12 09:57:53 +000042 .compatible = "fsl,mc34708",
43 .data = &mc13xxx_variant_mc34708,
Marc Reillydf3df642012-04-01 16:41:39 +100044 }, {
45 /* sentinel */
46 }
47};
48MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
49
50static struct regmap_config mc13xxx_regmap_i2c_config = {
51 .reg_bits = 8,
52 .val_bits = 24,
53
54 .max_register = MC13XXX_NUMREGS,
55
56 .cache_type = REGCACHE_NONE,
57};
58
59static int mc13xxx_i2c_probe(struct i2c_client *client,
60 const struct i2c_device_id *id)
61{
Marc Reillydf3df642012-04-01 16:41:39 +100062 struct mc13xxx *mc13xxx;
63 struct mc13xxx_platform_data *pdata = dev_get_platdata(&client->dev);
64 int ret;
65
Axel Line7c706b2012-06-29 15:14:36 +020066 mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
Marc Reillydf3df642012-04-01 16:41:39 +100067 if (!mc13xxx)
68 return -ENOMEM;
69
70 dev_set_drvdata(&client->dev, mc13xxx);
71
72 mc13xxx->dev = &client->dev;
73 mutex_init(&mc13xxx->lock);
74
Axel Line7c706b2012-06-29 15:14:36 +020075 mc13xxx->regmap = devm_regmap_init_i2c(client,
76 &mc13xxx_regmap_i2c_config);
Marc Reillydf3df642012-04-01 16:41:39 +100077 if (IS_ERR(mc13xxx->regmap)) {
78 ret = PTR_ERR(mc13xxx->regmap);
79 dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n",
80 ret);
Marc Reillydf3df642012-04-01 16:41:39 +100081 return ret;
82 }
83
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000084 if (client->dev.of_node) {
85 const struct of_device_id *of_id =
86 of_match_device(mc13xxx_dt_ids, &client->dev);
87 mc13xxx->variant = of_id->data;
88 } else {
89 mc13xxx->variant = (void *)id->driver_data;
90 }
Marc Reillydf3df642012-04-01 16:41:39 +100091
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000092 ret = mc13xxx_common_init(mc13xxx, pdata, client->irq);
Marc Reillydf3df642012-04-01 16:41:39 +100093
94 return ret;
95}
96
Bill Pemberton4740f732012-11-19 13:26:01 -050097static int mc13xxx_i2c_remove(struct i2c_client *client)
Marc Reillydf3df642012-04-01 16:41:39 +100098{
99 struct mc13xxx *mc13xxx = dev_get_drvdata(&client->dev);
100
101 mc13xxx_common_cleanup(mc13xxx);
102
103 return 0;
104}
105
106static struct i2c_driver mc13xxx_i2c_driver = {
107 .id_table = mc13xxx_i2c_device_id,
108 .driver = {
109 .owner = THIS_MODULE,
110 .name = "mc13xxx",
111 .of_match_table = mc13xxx_dt_ids,
112 },
113 .probe = mc13xxx_i2c_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500114 .remove = mc13xxx_i2c_remove,
Marc Reillydf3df642012-04-01 16:41:39 +1000115};
116
117static int __init mc13xxx_i2c_init(void)
118{
119 return i2c_add_driver(&mc13xxx_i2c_driver);
120}
121subsys_initcall(mc13xxx_i2c_init);
122
123static void __exit mc13xxx_i2c_exit(void)
124{
125 i2c_del_driver(&mc13xxx_i2c_driver);
126}
127module_exit(mc13xxx_i2c_exit);
128
129MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
130MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
131MODULE_LICENSE("GPL v2");