4 * Copyright (c) 2012 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
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.
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/samsung/s5m-core.h>
25 #include <linux/mfd/samsung/s5m-pmic.h>
26 #include <linux/mfd/samsung/s5m-rtc.h>
27 #include <linux/regmap.h>
29 static struct mfd_cell s5m8751_devs
[] = {
31 .name
= "s5m8751-pmic",
33 .name
= "s5m-charger",
35 .name
= "s5m8751-codec",
39 static struct mfd_cell s5m8763_devs
[] = {
41 .name
= "s5m8763-pmic",
45 .name
= "s5m-charger",
49 static struct mfd_cell s5m8767_devs
[] = {
51 .name
= "s5m8767-pmic",
57 int sec_reg_read(struct sec_pmic_dev
*sec_pmic
, u8 reg
, void *dest
)
59 return regmap_read(sec_pmic
->regmap
, reg
, dest
);
61 EXPORT_SYMBOL_GPL(sec_reg_read
);
63 int sec_bulk_read(struct sec_pmic_dev
*sec_pmic
, u8 reg
, int count
, u8
*buf
)
65 return regmap_bulk_read(sec_pmic
->regmap
, reg
, buf
, count
);
67 EXPORT_SYMBOL_GPL(sec_bulk_read
);
69 int sec_reg_write(struct sec_pmic_dev
*sec_pmic
, u8 reg
, u8 value
)
71 return regmap_write(sec_pmic
->regmap
, reg
, value
);
73 EXPORT_SYMBOL_GPL(sec_reg_write
);
75 int sec_bulk_write(struct sec_pmic_dev
*sec_pmic
, u8 reg
, int count
, u8
*buf
)
77 return regmap_raw_write(sec_pmic
->regmap
, reg
, buf
, count
);
79 EXPORT_SYMBOL_GPL(sec_bulk_write
);
81 int sec_reg_update(struct sec_pmic_dev
*sec_pmic
, u8 reg
, u8 val
, u8 mask
)
83 return regmap_update_bits(sec_pmic
->regmap
, reg
, mask
, val
);
85 EXPORT_SYMBOL_GPL(sec_reg_update
);
87 static struct regmap_config sec_regmap_config
= {
92 static int sec_pmic_probe(struct i2c_client
*i2c
,
93 const struct i2c_device_id
*id
)
95 struct sec_platform_data
*pdata
= i2c
->dev
.platform_data
;
96 struct sec_pmic_dev
*sec_pmic
;
99 sec_pmic
= devm_kzalloc(&i2c
->dev
, sizeof(struct sec_pmic_dev
),
101 if (sec_pmic
== NULL
)
104 i2c_set_clientdata(i2c
, sec_pmic
);
105 sec_pmic
->dev
= &i2c
->dev
;
107 sec_pmic
->irq
= i2c
->irq
;
108 sec_pmic
->type
= id
->driver_data
;
111 sec_pmic
->device_type
= pdata
->device_type
;
112 sec_pmic
->ono
= pdata
->ono
;
113 sec_pmic
->irq_base
= pdata
->irq_base
;
114 sec_pmic
->wakeup
= pdata
->wakeup
;
117 sec_pmic
->regmap
= devm_regmap_init_i2c(i2c
, &sec_regmap_config
);
118 if (IS_ERR(sec_pmic
->regmap
)) {
119 ret
= PTR_ERR(sec_pmic
->regmap
);
120 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
125 sec_pmic
->rtc
= i2c_new_dummy(i2c
->adapter
, RTC_I2C_ADDR
);
126 i2c_set_clientdata(sec_pmic
->rtc
, sec_pmic
);
128 if (pdata
&& pdata
->cfg_pmic_irq
)
129 pdata
->cfg_pmic_irq();
131 sec_irq_init(sec_pmic
);
133 pm_runtime_set_active(sec_pmic
->dev
);
135 switch (sec_pmic
->device_type
) {
137 ret
= mfd_add_devices(sec_pmic
->dev
, -1, s5m8751_devs
,
138 ARRAY_SIZE(s5m8751_devs
), NULL
, 0);
141 ret
= mfd_add_devices(sec_pmic
->dev
, -1, s5m8763_devs
,
142 ARRAY_SIZE(s5m8763_devs
), NULL
, 0);
145 ret
= mfd_add_devices(sec_pmic
->dev
, -1, s5m8767_devs
,
146 ARRAY_SIZE(s5m8767_devs
), NULL
, 0);
149 /* If this happens the probe function is problem */
159 mfd_remove_devices(sec_pmic
->dev
);
160 sec_irq_exit(sec_pmic
);
161 i2c_unregister_device(sec_pmic
->rtc
);
165 static int sec_pmic_remove(struct i2c_client
*i2c
)
167 struct sec_pmic_dev
*sec_pmic
= i2c_get_clientdata(i2c
);
169 mfd_remove_devices(sec_pmic
->dev
);
170 sec_irq_exit(sec_pmic
);
171 i2c_unregister_device(sec_pmic
->rtc
);
175 static const struct i2c_device_id sec_pmic_id
[] = {
179 MODULE_DEVICE_TABLE(i2c
, sec_pmic_id
);
181 static struct i2c_driver sec_pmic_driver
= {
184 .owner
= THIS_MODULE
,
186 .probe
= sec_pmic_probe
,
187 .remove
= sec_pmic_remove
,
188 .id_table
= sec_pmic_id
,
191 static int __init
sec_pmic_init(void)
193 return i2c_add_driver(&sec_pmic_driver
);
196 subsys_initcall(sec_pmic_init
);
198 static void __exit
sec_pmic_exit(void)
200 i2c_del_driver(&sec_pmic_driver
);
202 module_exit(sec_pmic_exit
);
204 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
205 MODULE_DESCRIPTION("Core support for the S5M MFD");
206 MODULE_LICENSE("GPL");