2 * Copyright 2009-2010 Creative Product Design
3 * Marc Reilly marc@cpdesign.com.au
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.
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>
17 #include <linux/of_device.h>
18 #include <linux/of_gpio.h>
19 #include <linux/i2c.h>
20 #include <linux/err.h>
24 static const struct i2c_device_id mc13xxx_i2c_device_id
[] = {
27 .driver_data
= (kernel_ulong_t
)&mc13xxx_variant_mc13892
,
30 .driver_data
= (kernel_ulong_t
)&mc13xxx_variant_mc34708
,
35 MODULE_DEVICE_TABLE(i2c
, mc13xxx_i2c_device_id
);
37 static const struct of_device_id mc13xxx_dt_ids
[] = {
39 .compatible
= "fsl,mc13892",
40 .data
= &mc13xxx_variant_mc13892
,
42 .compatible
= "fsl,mc34708",
43 .data
= &mc13xxx_variant_mc34708
,
48 MODULE_DEVICE_TABLE(of
, mc13xxx_dt_ids
);
50 static struct regmap_config mc13xxx_regmap_i2c_config
= {
54 .max_register
= MC13XXX_NUMREGS
,
56 .cache_type
= REGCACHE_NONE
,
59 static int mc13xxx_i2c_probe(struct i2c_client
*client
,
60 const struct i2c_device_id
*id
)
62 struct mc13xxx
*mc13xxx
;
63 struct mc13xxx_platform_data
*pdata
= dev_get_platdata(&client
->dev
);
66 mc13xxx
= devm_kzalloc(&client
->dev
, sizeof(*mc13xxx
), GFP_KERNEL
);
70 dev_set_drvdata(&client
->dev
, mc13xxx
);
72 mc13xxx
->dev
= &client
->dev
;
73 mutex_init(&mc13xxx
->lock
);
75 mc13xxx
->regmap
= devm_regmap_init_i2c(client
,
76 &mc13xxx_regmap_i2c_config
);
77 if (IS_ERR(mc13xxx
->regmap
)) {
78 ret
= PTR_ERR(mc13xxx
->regmap
);
79 dev_err(mc13xxx
->dev
, "Failed to initialize register map: %d\n",
81 dev_set_drvdata(&client
->dev
, NULL
);
85 if (client
->dev
.of_node
) {
86 const struct of_device_id
*of_id
=
87 of_match_device(mc13xxx_dt_ids
, &client
->dev
);
88 mc13xxx
->variant
= of_id
->data
;
90 mc13xxx
->variant
= (void *)id
->driver_data
;
93 ret
= mc13xxx_common_init(mc13xxx
, pdata
, client
->irq
);
98 static int mc13xxx_i2c_remove(struct i2c_client
*client
)
100 struct mc13xxx
*mc13xxx
= dev_get_drvdata(&client
->dev
);
102 mc13xxx_common_cleanup(mc13xxx
);
107 static struct i2c_driver mc13xxx_i2c_driver
= {
108 .id_table
= mc13xxx_i2c_device_id
,
110 .owner
= THIS_MODULE
,
112 .of_match_table
= mc13xxx_dt_ids
,
114 .probe
= mc13xxx_i2c_probe
,
115 .remove
= mc13xxx_i2c_remove
,
118 static int __init
mc13xxx_i2c_init(void)
120 return i2c_add_driver(&mc13xxx_i2c_driver
);
122 subsys_initcall(mc13xxx_i2c_init
);
124 static void __exit
mc13xxx_i2c_exit(void)
126 i2c_del_driver(&mc13xxx_i2c_driver
);
128 module_exit(mc13xxx_i2c_exit
);
130 MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
131 MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
132 MODULE_LICENSE("GPL v2");