blob: 70a16ae856a250c08a45e848f6bd986403775bda [file] [log] [blame]
Mattias Wallin39368ed2010-09-15 13:12:03 +02001/*
2 * Copyright (C) ST-Ericsson SA 2010
3 * Author: Mattias Wallin <mattias.wallin@stericsson.com> for ST-Ericsson.
4 * License Terms: GNU General Public License v2
5 * This file was based on drivers/mfd/ab8500-spi.c
6 */
7
8#include <linux/kernel.h>
9#include <linux/slab.h>
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/platform_device.h>
Linus Walleijee66e652011-12-02 14:16:33 +010013#include <linux/mfd/abx500/ab8500.h>
Linus Walleij650c2a22011-05-15 22:53:56 +020014#include <linux/mfd/db8500-prcmu.h>
Mattias Wallin39368ed2010-09-15 13:12:03 +020015
16static int ab8500_i2c_write(struct ab8500 *ab8500, u16 addr, u8 data)
17{
18 int ret;
19
20 ret = prcmu_abb_write((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
21 if (ret < 0)
22 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
23 return ret;
24}
25
26static int ab8500_i2c_read(struct ab8500 *ab8500, u16 addr)
27{
28 int ret;
29 u8 data;
30
31 ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
32 if (ret < 0) {
33 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
34 return ret;
35 }
36 return (int)data;
37}
38
39static int __devinit ab8500_i2c_probe(struct platform_device *plf)
40{
Linus Walleij0f6208372012-02-20 21:42:10 +010041 const struct platform_device_id *platid = platform_get_device_id(plf);
Mattias Wallin39368ed2010-09-15 13:12:03 +020042 struct ab8500 *ab8500;
43 struct resource *resource;
44 int ret;
45
46 ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL);
47 if (!ab8500)
48 return -ENOMEM;
49
50 ab8500->dev = &plf->dev;
51
52 resource = platform_get_resource(plf, IORESOURCE_IRQ, 0);
53 if (!resource) {
54 kfree(ab8500);
55 return -ENODEV;
56 }
57
58 ab8500->irq = resource->start;
59
60 ab8500->read = ab8500_i2c_read;
61 ab8500->write = ab8500_i2c_write;
62
63 platform_set_drvdata(plf, ab8500);
64
Linus Walleij0f6208372012-02-20 21:42:10 +010065 ret = ab8500_init(ab8500, platid->driver_data);
Mattias Wallin39368ed2010-09-15 13:12:03 +020066 if (ret)
67 kfree(ab8500);
68
Linus Walleij0f6208372012-02-20 21:42:10 +010069
Mattias Wallin39368ed2010-09-15 13:12:03 +020070 return ret;
71}
72
73static int __devexit ab8500_i2c_remove(struct platform_device *plf)
74{
75 struct ab8500 *ab8500 = platform_get_drvdata(plf);
76
77 ab8500_exit(ab8500);
78 kfree(ab8500);
79
80 return 0;
81}
82
Linus Walleij0f6208372012-02-20 21:42:10 +010083static const struct platform_device_id ab8500_id[] = {
84 { "ab8500-i2c", AB8500_VERSION_AB8500 },
85 { "ab8505-i2c", AB8500_VERSION_AB8505 },
86 { "ab9540-i2c", AB8500_VERSION_AB9540 },
87 { "ab8540-i2c", AB8500_VERSION_AB8540 },
88 { }
89};
90
Mattias Wallin39368ed2010-09-15 13:12:03 +020091static struct platform_driver ab8500_i2c_driver = {
92 .driver = {
93 .name = "ab8500-i2c",
94 .owner = THIS_MODULE,
95 },
96 .probe = ab8500_i2c_probe,
Linus Walleij0f6208372012-02-20 21:42:10 +010097 .remove = __devexit_p(ab8500_i2c_remove),
98 .id_table = ab8500_id,
Mattias Wallin39368ed2010-09-15 13:12:03 +020099};
100
101static int __init ab8500_i2c_init(void)
102{
103 return platform_driver_register(&ab8500_i2c_driver);
104}
105
106static void __exit ab8500_i2c_exit(void)
107{
108 platform_driver_unregister(&ab8500_i2c_driver);
109}
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530110arch_initcall(ab8500_i2c_init);
Mattias Wallin39368ed2010-09-15 13:12:03 +0200111module_exit(ab8500_i2c_exit);
112
113MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
114MODULE_DESCRIPTION("AB8500 Core access via PRCMU I2C");
115MODULE_LICENSE("GPL v2");