blob: 4a174cdb50b623e97d9360291b4ab2a4798c92a6 [file] [log] [blame]
Linus Walleij798a8ee2011-03-09 13:02:38 +01001/*
2 * Core driver for TPS61050/61052 boost converters, used for while LED
3 * driving, audio power amplification, white LED flash, and generic
4 * boost conversion. Additionally it provides a 1-bit GPIO pin (out or in)
5 * and a flash synchronization pin to synchronize flash events when used as
6 * flashgun.
7 *
8 * Copyright (C) 2011 ST-Ericsson SA
9 * Written on behalf of Linaro for ST-Ericsson
10 *
11 * Author: Linus Walleij <linus.walleij@linaro.org>
12 *
13 * License terms: GNU General Public License (GPL) version 2
14 */
15
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/i2c.h>
Grigoryev Denis7e507112015-10-02 16:14:41 +000019#include <linux/regmap.h>
Linus Walleij798a8ee2011-03-09 13:02:38 +010020#include <linux/gpio.h>
21#include <linux/spinlock.h>
22#include <linux/slab.h>
23#include <linux/err.h>
24#include <linux/regulator/driver.h>
25#include <linux/mfd/core.h>
26#include <linux/mfd/tps6105x.h>
27
Grigoryev Denis7e507112015-10-02 16:14:41 +000028static struct regmap_config tps6105x_regmap_config = {
29 .reg_bits = 8,
30 .val_bits = 8,
31 .max_register = TPS6105X_REG_3,
32};
Linus Walleij798a8ee2011-03-09 13:02:38 +010033
Bill Pembertonf791be42012-11-19 13:23:04 -050034static int tps6105x_startup(struct tps6105x *tps6105x)
Linus Walleij798a8ee2011-03-09 13:02:38 +010035{
36 int ret;
Grigoryev Denis7e507112015-10-02 16:14:41 +000037 unsigned int regval;
Linus Walleij798a8ee2011-03-09 13:02:38 +010038
Grigoryev Denis7e507112015-10-02 16:14:41 +000039 ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, &regval);
Linus Walleij798a8ee2011-03-09 13:02:38 +010040 if (ret)
41 return ret;
42 switch (regval >> TPS6105X_REG0_MODE_SHIFT) {
43 case TPS6105X_REG0_MODE_SHUTDOWN:
44 dev_info(&tps6105x->client->dev,
45 "TPS6105x found in SHUTDOWN mode\n");
46 break;
47 case TPS6105X_REG0_MODE_TORCH:
48 dev_info(&tps6105x->client->dev,
49 "TPS6105x found in TORCH mode\n");
50 break;
51 case TPS6105X_REG0_MODE_TORCH_FLASH:
52 dev_info(&tps6105x->client->dev,
53 "TPS6105x found in FLASH mode\n");
54 break;
55 case TPS6105X_REG0_MODE_VOLTAGE:
56 dev_info(&tps6105x->client->dev,
57 "TPS6105x found in VOLTAGE mode\n");
58 break;
59 default:
60 break;
61 }
62
63 return ret;
64}
65
66/*
67 * MFD cells - we have one cell which is selected operation
68 * mode, and we always have a GPIO cell.
69 */
70static struct mfd_cell tps6105x_cells[] = {
71 {
72 /* name will be runtime assigned */
73 .id = -1,
74 },
75 {
76 .name = "tps6105x-gpio",
77 .id = -1,
78 },
79};
80
Bill Pembertonf791be42012-11-19 13:23:04 -050081static int tps6105x_probe(struct i2c_client *client,
Linus Walleij798a8ee2011-03-09 13:02:38 +010082 const struct i2c_device_id *id)
83{
84 struct tps6105x *tps6105x;
85 struct tps6105x_platform_data *pdata;
86 int ret;
87 int i;
88
Himangi Saraogiad835332014-07-19 14:00:10 +053089 tps6105x = devm_kmalloc(&client->dev, sizeof(*tps6105x), GFP_KERNEL);
Linus Walleij798a8ee2011-03-09 13:02:38 +010090 if (!tps6105x)
91 return -ENOMEM;
92
Grigoryev Denis7e507112015-10-02 16:14:41 +000093 tps6105x->regmap = devm_regmap_init_i2c(client, &tps6105x_regmap_config);
94 if (IS_ERR(tps6105x->regmap))
95 return PTR_ERR(tps6105x->regmap);
96
Linus Walleij798a8ee2011-03-09 13:02:38 +010097 i2c_set_clientdata(client, tps6105x);
98 tps6105x->client = client;
Jingoo Han334a41ce2013-07-30 17:10:05 +090099 pdata = dev_get_platdata(&client->dev);
Linus Walleij798a8ee2011-03-09 13:02:38 +0100100 tps6105x->pdata = pdata;
Linus Walleij798a8ee2011-03-09 13:02:38 +0100101
102 ret = tps6105x_startup(tps6105x);
103 if (ret) {
104 dev_err(&client->dev, "chip initialization failed\n");
Himangi Saraogiad835332014-07-19 14:00:10 +0530105 return ret;
Linus Walleij798a8ee2011-03-09 13:02:38 +0100106 }
107
108 /* Remove warning texts when you implement new cell drivers */
109 switch (pdata->mode) {
110 case TPS6105X_MODE_SHUTDOWN:
111 dev_info(&client->dev,
112 "present, not used for anything, only GPIO\n");
113 break;
114 case TPS6105X_MODE_TORCH:
115 tps6105x_cells[0].name = "tps6105x-leds";
116 dev_warn(&client->dev,
117 "torch mode is unsupported\n");
118 break;
119 case TPS6105X_MODE_TORCH_FLASH:
120 tps6105x_cells[0].name = "tps6105x-flash";
121 dev_warn(&client->dev,
122 "flash mode is unsupported\n");
123 break;
124 case TPS6105X_MODE_VOLTAGE:
125 tps6105x_cells[0].name ="tps6105x-regulator";
126 break;
127 default:
128 break;
129 }
130
131 /* Set up and register the platform devices. */
132 for (i = 0; i < ARRAY_SIZE(tps6105x_cells); i++) {
133 /* One state holder for all drivers, this is simple */
Samuel Ortiza7c98ce2011-05-11 10:33:25 +0200134 tps6105x_cells[i].platform_data = tps6105x;
135 tps6105x_cells[i].pdata_size = sizeof(*tps6105x);
Linus Walleij798a8ee2011-03-09 13:02:38 +0100136 }
137
Himangi Saraogiad835332014-07-19 14:00:10 +0530138 return mfd_add_devices(&client->dev, 0, tps6105x_cells,
139 ARRAY_SIZE(tps6105x_cells), NULL, 0, NULL);
Linus Walleij798a8ee2011-03-09 13:02:38 +0100140}
141
Bill Pemberton4740f732012-11-19 13:26:01 -0500142static int tps6105x_remove(struct i2c_client *client)
Linus Walleij798a8ee2011-03-09 13:02:38 +0100143{
144 struct tps6105x *tps6105x = i2c_get_clientdata(client);
145
146 mfd_remove_devices(&client->dev);
147
148 /* Put chip in shutdown mode */
Grigoryev Denis7e507112015-10-02 16:14:41 +0000149 regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
Linus Walleij798a8ee2011-03-09 13:02:38 +0100150 TPS6105X_REG0_MODE_MASK,
151 TPS6105X_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT);
152
Linus Walleij798a8ee2011-03-09 13:02:38 +0100153 return 0;
154}
155
156static const struct i2c_device_id tps6105x_id[] = {
157 { "tps61050", 0 },
158 { "tps61052", 0 },
159 { }
160};
161MODULE_DEVICE_TABLE(i2c, tps6105x_id);
162
163static struct i2c_driver tps6105x_driver = {
164 .driver = {
165 .name = "tps6105x",
166 },
167 .probe = tps6105x_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500168 .remove = tps6105x_remove,
Linus Walleij798a8ee2011-03-09 13:02:38 +0100169 .id_table = tps6105x_id,
170};
171
172static int __init tps6105x_init(void)
173{
174 return i2c_add_driver(&tps6105x_driver);
175}
176subsys_initcall(tps6105x_init);
177
178static void __exit tps6105x_exit(void)
179{
180 i2c_del_driver(&tps6105x_driver);
181}
182module_exit(tps6105x_exit);
183
184MODULE_AUTHOR("Linus Walleij");
185MODULE_DESCRIPTION("TPS6105x White LED Boost Converter Driver");
186MODULE_LICENSE("GPL v2");