blob: ae3addb153a2e825f260959e1a52c93cc42051ef [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>
Marc Reillydf3df642012-04-01 16:41:39 +100013#include <linux/mfd/core.h>
14#include <linux/mfd/mc13xxx.h>
15#include <linux/of.h>
16#include <linux/of_device.h>
17#include <linux/of_gpio.h>
18#include <linux/i2c.h>
19#include <linux/err.h>
20
21#include "mc13xxx.h"
22
23static const struct i2c_device_id mc13xxx_i2c_device_id[] = {
24 {
25 .name = "mc13892",
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000026 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
Marc Reillydf3df642012-04-01 16:41:39 +100027 }, {
Uwe Kleine-König0312e022012-07-12 09:57:53 +000028 .name = "mc34708",
29 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc34708,
Marc Reillydf3df642012-04-01 16:41:39 +100030 }, {
31 /* sentinel */
32 }
33};
34MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
35
36static const struct of_device_id mc13xxx_dt_ids[] = {
37 {
38 .compatible = "fsl,mc13892",
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000039 .data = &mc13xxx_variant_mc13892,
Marc Reillydf3df642012-04-01 16:41:39 +100040 }, {
Uwe Kleine-König0312e022012-07-12 09:57:53 +000041 .compatible = "fsl,mc34708",
42 .data = &mc13xxx_variant_mc34708,
Marc Reillydf3df642012-04-01 16:41:39 +100043 }, {
44 /* sentinel */
45 }
46};
47MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
48
49static struct regmap_config mc13xxx_regmap_i2c_config = {
50 .reg_bits = 8,
51 .val_bits = 24,
52
53 .max_register = MC13XXX_NUMREGS,
54
55 .cache_type = REGCACHE_NONE,
56};
57
58static int mc13xxx_i2c_probe(struct i2c_client *client,
59 const struct i2c_device_id *id)
60{
Marc Reillydf3df642012-04-01 16:41:39 +100061 struct mc13xxx *mc13xxx;
Marc Reillydf3df642012-04-01 16:41:39 +100062 int ret;
63
Axel Line7c706b2012-06-29 15:14:36 +020064 mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
Marc Reillydf3df642012-04-01 16:41:39 +100065 if (!mc13xxx)
66 return -ENOMEM;
67
68 dev_set_drvdata(&client->dev, mc13xxx);
69
Alexander Shiyandb9ef442013-12-14 17:03:12 +040070 mc13xxx->irq = client->irq;
Marc Reillydf3df642012-04-01 16:41:39 +100071
Axel Line7c706b2012-06-29 15:14:36 +020072 mc13xxx->regmap = devm_regmap_init_i2c(client,
73 &mc13xxx_regmap_i2c_config);
Marc Reillydf3df642012-04-01 16:41:39 +100074 if (IS_ERR(mc13xxx->regmap)) {
75 ret = PTR_ERR(mc13xxx->regmap);
Alexander Shiyandb9ef442013-12-14 17:03:12 +040076 dev_err(&client->dev, "Failed to initialize regmap: %d\n", ret);
Marc Reillydf3df642012-04-01 16:41:39 +100077 return ret;
78 }
79
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000080 if (client->dev.of_node) {
81 const struct of_device_id *of_id =
82 of_match_device(mc13xxx_dt_ids, &client->dev);
83 mc13xxx->variant = of_id->data;
84 } else {
85 mc13xxx->variant = (void *)id->driver_data;
86 }
Marc Reillydf3df642012-04-01 16:41:39 +100087
Alexander Shiyandb9ef442013-12-14 17:03:12 +040088 return mc13xxx_common_init(&client->dev);
Marc Reillydf3df642012-04-01 16:41:39 +100089}
90
Bill Pemberton4740f732012-11-19 13:26:01 -050091static int mc13xxx_i2c_remove(struct i2c_client *client)
Marc Reillydf3df642012-04-01 16:41:39 +100092{
Alexander Shiyandb9ef442013-12-14 17:03:12 +040093 return mc13xxx_common_exit(&client->dev);
Marc Reillydf3df642012-04-01 16:41:39 +100094}
95
96static struct i2c_driver mc13xxx_i2c_driver = {
97 .id_table = mc13xxx_i2c_device_id,
98 .driver = {
99 .owner = THIS_MODULE,
100 .name = "mc13xxx",
101 .of_match_table = mc13xxx_dt_ids,
102 },
103 .probe = mc13xxx_i2c_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500104 .remove = mc13xxx_i2c_remove,
Marc Reillydf3df642012-04-01 16:41:39 +1000105};
106
107static int __init mc13xxx_i2c_init(void)
108{
109 return i2c_add_driver(&mc13xxx_i2c_driver);
110}
111subsys_initcall(mc13xxx_i2c_init);
112
113static void __exit mc13xxx_i2c_exit(void)
114{
115 i2c_del_driver(&mc13xxx_i2c_driver);
116}
117module_exit(mc13xxx_i2c_exit);
118
119MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
120MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
121MODULE_LICENSE("GPL v2");