sfc: Do not retry hardware probe if it schedules a reset
[linux-2.6.git] / drivers / mfd / s5m-core.c
blobe075c113eec6f7d77a67b5ca1eb145abe8eebbdf
1 /*
2 * s5m87xx.c
4 * Copyright (c) 2011 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/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>
29 static struct mfd_cell s5m87xx_devs[] = {
31 .name = "s5m8767-pmic",
32 }, {
33 .name = "s5m-rtc",
37 int s5m_reg_read(struct s5m87xx_dev *s5m87xx, u8 reg, void *dest)
39 return regmap_read(s5m87xx->regmap, reg, dest);
41 EXPORT_SYMBOL_GPL(s5m_reg_read);
43 int s5m_bulk_read(struct s5m87xx_dev *s5m87xx, u8 reg, int count, u8 *buf)
45 return regmap_bulk_read(s5m87xx->regmap, reg, buf, count);;
47 EXPORT_SYMBOL_GPL(s5m_bulk_read);
49 int s5m_reg_write(struct s5m87xx_dev *s5m87xx, u8 reg, u8 value)
51 return regmap_write(s5m87xx->regmap, reg, value);
53 EXPORT_SYMBOL_GPL(s5m_reg_write);
55 int s5m_bulk_write(struct s5m87xx_dev *s5m87xx, u8 reg, int count, u8 *buf)
57 return regmap_raw_write(s5m87xx->regmap, reg, buf, count * sizeof(u16));
59 EXPORT_SYMBOL_GPL(s5m_bulk_write);
61 int s5m_reg_update(struct s5m87xx_dev *s5m87xx, u8 reg, u8 val, u8 mask)
63 return regmap_update_bits(s5m87xx->regmap, reg, mask, val);
65 EXPORT_SYMBOL_GPL(s5m_reg_update);
67 static struct regmap_config s5m_regmap_config = {
68 .reg_bits = 8,
69 .val_bits = 8,
72 static int s5m87xx_i2c_probe(struct i2c_client *i2c,
73 const struct i2c_device_id *id)
75 struct s5m_platform_data *pdata = i2c->dev.platform_data;
76 struct s5m87xx_dev *s5m87xx;
77 int ret = 0;
78 int error;
80 s5m87xx = kzalloc(sizeof(struct s5m87xx_dev), GFP_KERNEL);
81 if (s5m87xx == NULL)
82 return -ENOMEM;
84 i2c_set_clientdata(i2c, s5m87xx);
85 s5m87xx->dev = &i2c->dev;
86 s5m87xx->i2c = i2c;
87 s5m87xx->irq = i2c->irq;
88 s5m87xx->type = id->driver_data;
90 if (pdata) {
91 s5m87xx->device_type = pdata->device_type;
92 s5m87xx->ono = pdata->ono;
93 s5m87xx->irq_base = pdata->irq_base;
94 s5m87xx->wakeup = pdata->wakeup;
97 s5m87xx->regmap = regmap_init_i2c(i2c, &s5m_regmap_config);
98 if (IS_ERR(s5m87xx->regmap)) {
99 error = PTR_ERR(s5m87xx->regmap);
100 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
101 error);
102 goto err;
105 s5m87xx->rtc = i2c_new_dummy(i2c->adapter, RTC_I2C_ADDR);
106 i2c_set_clientdata(s5m87xx->rtc, s5m87xx);
108 if (pdata->cfg_pmic_irq)
109 pdata->cfg_pmic_irq();
111 s5m_irq_init(s5m87xx);
113 pm_runtime_set_active(s5m87xx->dev);
115 ret = mfd_add_devices(s5m87xx->dev, -1,
116 s5m87xx_devs, ARRAY_SIZE(s5m87xx_devs),
117 NULL, 0);
119 if (ret < 0)
120 goto err;
122 return ret;
124 err:
125 mfd_remove_devices(s5m87xx->dev);
126 s5m_irq_exit(s5m87xx);
127 i2c_unregister_device(s5m87xx->rtc);
128 regmap_exit(s5m87xx->regmap);
129 kfree(s5m87xx);
130 return ret;
133 static int s5m87xx_i2c_remove(struct i2c_client *i2c)
135 struct s5m87xx_dev *s5m87xx = i2c_get_clientdata(i2c);
137 mfd_remove_devices(s5m87xx->dev);
138 s5m_irq_exit(s5m87xx);
139 i2c_unregister_device(s5m87xx->rtc);
140 regmap_exit(s5m87xx->regmap);
141 kfree(s5m87xx);
142 return 0;
145 static const struct i2c_device_id s5m87xx_i2c_id[] = {
146 { "s5m87xx", 0 },
149 MODULE_DEVICE_TABLE(i2c, s5m87xx_i2c_id);
151 static struct i2c_driver s5m87xx_i2c_driver = {
152 .driver = {
153 .name = "s5m87xx",
154 .owner = THIS_MODULE,
156 .probe = s5m87xx_i2c_probe,
157 .remove = s5m87xx_i2c_remove,
158 .id_table = s5m87xx_i2c_id,
161 static int __init s5m87xx_i2c_init(void)
163 return i2c_add_driver(&s5m87xx_i2c_driver);
166 subsys_initcall(s5m87xx_i2c_init);
168 static void __exit s5m87xx_i2c_exit(void)
170 i2c_del_driver(&s5m87xx_i2c_driver);
172 module_exit(s5m87xx_i2c_exit);
174 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
175 MODULE_DESCRIPTION("Core support for the S5M MFD");
176 MODULE_LICENSE("GPL");