]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/mfd/ab8500-i2c.c
mfd: Handle the ab8500 irq for suspend/resume
[mirror_ubuntu-bionic-kernel.git] / drivers / mfd / ab8500-i2c.c
CommitLineData
39368eda
MW
1/*
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>
ee66e653 13#include <linux/mfd/abx500/ab8500.h>
bc628fd1 14#include <linux/mfd/dbx500-prcmu.h>
39368eda
MW
15
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
bc628fd1
MN
26static int ab8500_i2c_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask,
27 u8 data)
28{
29 int ret;
30
31 ret = prcmu_abb_write_masked((u8)(addr >> 8), (u8)(addr & 0xFF), &data,
32 &mask, 1);
33 if (ret < 0)
34 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
35 return ret;
36}
37
39368eda
MW
38static int ab8500_i2c_read(struct ab8500 *ab8500, u16 addr)
39{
40 int ret;
41 u8 data;
42
43 ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
44 if (ret < 0) {
45 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
46 return ret;
47 }
48 return (int)data;
49}
50
51static int __devinit ab8500_i2c_probe(struct platform_device *plf)
52{
0f620837 53 const struct platform_device_id *platid = platform_get_device_id(plf);
39368eda
MW
54 struct ab8500 *ab8500;
55 struct resource *resource;
56 int ret;
57
58 ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL);
59 if (!ab8500)
60 return -ENOMEM;
61
62 ab8500->dev = &plf->dev;
63
64 resource = platform_get_resource(plf, IORESOURCE_IRQ, 0);
65 if (!resource) {
66 kfree(ab8500);
67 return -ENODEV;
68 }
69
70 ab8500->irq = resource->start;
71
72 ab8500->read = ab8500_i2c_read;
73 ab8500->write = ab8500_i2c_write;
bc628fd1 74 ab8500->write_masked = ab8500_i2c_write_masked;
39368eda
MW
75
76 platform_set_drvdata(plf, ab8500);
77
0f620837 78 ret = ab8500_init(ab8500, platid->driver_data);
39368eda
MW
79 if (ret)
80 kfree(ab8500);
81
0f620837 82
39368eda
MW
83 return ret;
84}
85
86static int __devexit ab8500_i2c_remove(struct platform_device *plf)
87{
88 struct ab8500 *ab8500 = platform_get_drvdata(plf);
89
90 ab8500_exit(ab8500);
91 kfree(ab8500);
92
93 return 0;
94}
95
0f620837
LW
96static const struct platform_device_id ab8500_id[] = {
97 { "ab8500-i2c", AB8500_VERSION_AB8500 },
98 { "ab8505-i2c", AB8500_VERSION_AB8505 },
99 { "ab9540-i2c", AB8500_VERSION_AB9540 },
100 { "ab8540-i2c", AB8500_VERSION_AB8540 },
101 { }
102};
103
7e82d6ff
RV
104#ifdef CONFIG_PM
105static int ab8500_i2c_suspend(struct device *dev)
106{
107 struct ab8500 *ab = dev_get_drvdata(dev);
108
109 disable_irq(ab->irq);
110 enable_irq_wake(ab->irq);
111
112 return 0;
113}
114
115static int ab8500_i2c_resume(struct device *dev)
116{
117 struct ab8500 *ab = dev_get_drvdata(dev);
118
119 disable_irq_wake(ab->irq);
120 enable_irq(ab->irq);
121
122 return 0;
123}
124
125static const struct dev_pm_ops ab8500_i2c_pm_ops = {
126 .suspend = ab8500_i2c_suspend,
127 .resume = ab8500_i2c_resume,
128};
129
130#define AB8500_I2C_PM_OPS (&ab8500_i2c_pm_ops)
131#else
132#define AB8500_I2C_PM_OPS NULL
133#endif
134
39368eda
MW
135static struct platform_driver ab8500_i2c_driver = {
136 .driver = {
137 .name = "ab8500-i2c",
138 .owner = THIS_MODULE,
7e82d6ff 139 .pm = AB8500_I2C_PM_OPS,
39368eda
MW
140 },
141 .probe = ab8500_i2c_probe,
0f620837
LW
142 .remove = __devexit_p(ab8500_i2c_remove),
143 .id_table = ab8500_id,
39368eda
MW
144};
145
146static int __init ab8500_i2c_init(void)
147{
148 return platform_driver_register(&ab8500_i2c_driver);
149}
150
151static void __exit ab8500_i2c_exit(void)
152{
153 platform_driver_unregister(&ab8500_i2c_driver);
154}
0cb3fcd7 155arch_initcall(ab8500_i2c_init);
39368eda
MW
156module_exit(ab8500_i2c_exit);
157
158MODULE_AUTHOR("Mattias WALLIN <mattias.wallin@stericsson.com");
159MODULE_DESCRIPTION("AB8500 Core access via PRCMU I2C");
160MODULE_LICENSE("GPL v2");