]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/mfd/s5m-core.c
led: Modified power control of pm860x led
[mirror_ubuntu-hirsute-kernel.git] / drivers / mfd / s5m-core.c
CommitLineData
0f5f7078
SK
1/*
2 * s5m87xx.c
3 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/init.h>
17#include <linux/err.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
20#include <linux/interrupt.h>
21#include <linux/pm_runtime.h>
22#include <linux/mutex.h>
23#include <linux/mfd/core.h>
24#include <linux/mfd/s5m87xx/s5m-core.h>
25#include <linux/mfd/s5m87xx/s5m-pmic.h>
26#include <linux/mfd/s5m87xx/s5m-rtc.h>
27#include <linux/regmap.h>
28
88a1cfd6
SK
29static struct mfd_cell s5m8751_devs[] = {
30 {
31 .name = "s5m8751-pmic",
32 }, {
33 .name = "s5m-charger",
34 }, {
35 .name = "s5m8751-codec",
36 },
37};
38
39static struct mfd_cell s5m8763_devs[] = {
40 {
41 .name = "s5m8763-pmic",
42 }, {
43 .name = "s5m-rtc",
44 }, {
45 .name = "s5m-charger",
46 },
47};
48
49static struct mfd_cell s5m8767_devs[] = {
0f5f7078
SK
50 {
51 .name = "s5m8767-pmic",
52 }, {
53 .name = "s5m-rtc",
54 },
55};
56
57int s5m_reg_read(struct s5m87xx_dev *s5m87xx, u8 reg, void *dest)
58{
59 return regmap_read(s5m87xx->regmap, reg, dest);
60}
61EXPORT_SYMBOL_GPL(s5m_reg_read);
62
63int s5m_bulk_read(struct s5m87xx_dev *s5m87xx, u8 reg, int count, u8 *buf)
64{
65 return regmap_bulk_read(s5m87xx->regmap, reg, buf, count);;
66}
67EXPORT_SYMBOL_GPL(s5m_bulk_read);
68
69int s5m_reg_write(struct s5m87xx_dev *s5m87xx, u8 reg, u8 value)
70{
71 return regmap_write(s5m87xx->regmap, reg, value);
72}
73EXPORT_SYMBOL_GPL(s5m_reg_write);
74
75int s5m_bulk_write(struct s5m87xx_dev *s5m87xx, u8 reg, int count, u8 *buf)
76{
113351b5 77 return regmap_raw_write(s5m87xx->regmap, reg, buf, count);
0f5f7078
SK
78}
79EXPORT_SYMBOL_GPL(s5m_bulk_write);
80
81int s5m_reg_update(struct s5m87xx_dev *s5m87xx, u8 reg, u8 val, u8 mask)
82{
83 return regmap_update_bits(s5m87xx->regmap, reg, mask, val);
84}
85EXPORT_SYMBOL_GPL(s5m_reg_update);
86
87static struct regmap_config s5m_regmap_config = {
88 .reg_bits = 8,
89 .val_bits = 8,
90};
91
92static int s5m87xx_i2c_probe(struct i2c_client *i2c,
93 const struct i2c_device_id *id)
94{
95 struct s5m_platform_data *pdata = i2c->dev.platform_data;
96 struct s5m87xx_dev *s5m87xx;
97 int ret = 0;
98 int error;
99
621210e2
SK
100 s5m87xx = devm_kzalloc(&i2c->dev, sizeof(struct s5m87xx_dev),
101 GFP_KERNEL);
0f5f7078
SK
102 if (s5m87xx == NULL)
103 return -ENOMEM;
104
105 i2c_set_clientdata(i2c, s5m87xx);
106 s5m87xx->dev = &i2c->dev;
107 s5m87xx->i2c = i2c;
108 s5m87xx->irq = i2c->irq;
109 s5m87xx->type = id->driver_data;
110
111 if (pdata) {
112 s5m87xx->device_type = pdata->device_type;
113 s5m87xx->ono = pdata->ono;
114 s5m87xx->irq_base = pdata->irq_base;
115 s5m87xx->wakeup = pdata->wakeup;
116 }
117
118 s5m87xx->regmap = regmap_init_i2c(i2c, &s5m_regmap_config);
119 if (IS_ERR(s5m87xx->regmap)) {
120 error = PTR_ERR(s5m87xx->regmap);
121 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
122 error);
123 goto err;
124 }
125
126 s5m87xx->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR);
127 i2c_set_clientdata(s5m87xx->rtc, s5m87xx);
128
c3ebb30a 129 if (pdata && pdata->cfg_pmic_irq)
0f5f7078
SK
130 pdata->cfg_pmic_irq();
131
132 s5m_irq_init(s5m87xx);
133
134 pm_runtime_set_active(s5m87xx->dev);
135
88a1cfd6
SK
136 switch (s5m87xx->device_type) {
137 case S5M8751X:
138 ret = mfd_add_devices(s5m87xx->dev, -1, s5m8751_devs,
139 ARRAY_SIZE(s5m8751_devs), NULL, 0);
140 break;
141 case S5M8763X:
142 ret = mfd_add_devices(s5m87xx->dev, -1, s5m8763_devs,
143 ARRAY_SIZE(s5m8763_devs), NULL, 0);
144 break;
145 case S5M8767X:
146 ret = mfd_add_devices(s5m87xx->dev, -1, s5m8767_devs,
147 ARRAY_SIZE(s5m8767_devs), NULL, 0);
148 break;
149 default:
150 /* If this happens the probe function is problem */
151 BUG();
152 }
0f5f7078
SK
153
154 if (ret < 0)
155 goto err;
156
157 return ret;
158
159err:
160 mfd_remove_devices(s5m87xx->dev);
161 s5m_irq_exit(s5m87xx);
162 i2c_unregister_device(s5m87xx->rtc);
163 regmap_exit(s5m87xx->regmap);
0f5f7078
SK
164 return ret;
165}
166
167static int s5m87xx_i2c_remove(struct i2c_client *i2c)
168{
169 struct s5m87xx_dev *s5m87xx = i2c_get_clientdata(i2c);
170
171 mfd_remove_devices(s5m87xx->dev);
172 s5m_irq_exit(s5m87xx);
173 i2c_unregister_device(s5m87xx->rtc);
174 regmap_exit(s5m87xx->regmap);
0f5f7078
SK
175 return 0;
176}
177
178static const struct i2c_device_id s5m87xx_i2c_id[] = {
179 { "s5m87xx", 0 },
180 { }
181};
182MODULE_DEVICE_TABLE(i2c, s5m87xx_i2c_id);
183
184static struct i2c_driver s5m87xx_i2c_driver = {
185 .driver = {
186 .name = "s5m87xx",
187 .owner = THIS_MODULE,
188 },
189 .probe = s5m87xx_i2c_probe,
190 .remove = s5m87xx_i2c_remove,
191 .id_table = s5m87xx_i2c_id,
192};
193
194static int __init s5m87xx_i2c_init(void)
195{
196 return i2c_add_driver(&s5m87xx_i2c_driver);
197}
198
199subsys_initcall(s5m87xx_i2c_init);
200
201static void __exit s5m87xx_i2c_exit(void)
202{
203 i2c_del_driver(&s5m87xx_i2c_driver);
204}
205module_exit(s5m87xx_i2c_exit);
206
207MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
208MODULE_DESCRIPTION("Core support for the S5M MFD");
209MODULE_LICENSE("GPL");