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
8 * Copyright (C) 2011 ST-Ericsson SA
9 * Written on behalf of Linaro for ST-Ericsson
11 * Author: Linus Walleij <linus.walleij@linaro.org>
13 * License terms: GNU General Public License (GPL) version 2
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/i2c.h>
19 #include <linux/regmap.h>
20 #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>
28 static struct regmap_config tps6105x_regmap_config
= {
31 .max_register
= TPS6105X_REG_3
,
34 static int tps6105x_startup(struct tps6105x
*tps6105x
)
39 ret
= regmap_read(tps6105x
->regmap
, TPS6105X_REG_0
, ®val
);
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");
47 case TPS6105X_REG0_MODE_TORCH
:
48 dev_info(&tps6105x
->client
->dev
,
49 "TPS6105x found in TORCH mode\n");
51 case TPS6105X_REG0_MODE_TORCH_FLASH
:
52 dev_info(&tps6105x
->client
->dev
,
53 "TPS6105x found in FLASH mode\n");
55 case TPS6105X_REG0_MODE_VOLTAGE
:
56 dev_info(&tps6105x
->client
->dev
,
57 "TPS6105x found in VOLTAGE mode\n");
67 * MFD cells - we have one cell which is selected operation
68 * mode, and we always have a GPIO cell.
70 static struct mfd_cell tps6105x_cells
[] = {
72 /* name will be runtime assigned */
76 .name
= "tps6105x-gpio",
81 static int tps6105x_probe(struct i2c_client
*client
,
82 const struct i2c_device_id
*id
)
84 struct tps6105x
*tps6105x
;
85 struct tps6105x_platform_data
*pdata
;
89 tps6105x
= devm_kmalloc(&client
->dev
, sizeof(*tps6105x
), GFP_KERNEL
);
93 tps6105x
->regmap
= devm_regmap_init_i2c(client
, &tps6105x_regmap_config
);
94 if (IS_ERR(tps6105x
->regmap
))
95 return PTR_ERR(tps6105x
->regmap
);
97 i2c_set_clientdata(client
, tps6105x
);
98 tps6105x
->client
= client
;
99 pdata
= dev_get_platdata(&client
->dev
);
100 tps6105x
->pdata
= pdata
;
102 ret
= tps6105x_startup(tps6105x
);
104 dev_err(&client
->dev
, "chip initialization failed\n");
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");
114 case TPS6105X_MODE_TORCH
:
115 tps6105x_cells
[0].name
= "tps6105x-leds";
116 dev_warn(&client
->dev
,
117 "torch mode is unsupported\n");
119 case TPS6105X_MODE_TORCH_FLASH
:
120 tps6105x_cells
[0].name
= "tps6105x-flash";
121 dev_warn(&client
->dev
,
122 "flash mode is unsupported\n");
124 case TPS6105X_MODE_VOLTAGE
:
125 tps6105x_cells
[0].name
="tps6105x-regulator";
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 */
134 tps6105x_cells
[i
].platform_data
= tps6105x
;
135 tps6105x_cells
[i
].pdata_size
= sizeof(*tps6105x
);
138 return mfd_add_devices(&client
->dev
, 0, tps6105x_cells
,
139 ARRAY_SIZE(tps6105x_cells
), NULL
, 0, NULL
);
142 static int tps6105x_remove(struct i2c_client
*client
)
144 struct tps6105x
*tps6105x
= i2c_get_clientdata(client
);
146 mfd_remove_devices(&client
->dev
);
148 /* Put chip in shutdown mode */
149 regmap_update_bits(tps6105x
->regmap
, TPS6105X_REG_0
,
150 TPS6105X_REG0_MODE_MASK
,
151 TPS6105X_MODE_SHUTDOWN
<< TPS6105X_REG0_MODE_SHIFT
);
156 static const struct i2c_device_id tps6105x_id
[] = {
161 MODULE_DEVICE_TABLE(i2c
, tps6105x_id
);
163 static struct i2c_driver tps6105x_driver
= {
167 .probe
= tps6105x_probe
,
168 .remove
= tps6105x_remove
,
169 .id_table
= tps6105x_id
,
172 static int __init
tps6105x_init(void)
174 return i2c_add_driver(&tps6105x_driver
);
176 subsys_initcall(tps6105x_init
);
178 static void __exit
tps6105x_exit(void)
180 i2c_del_driver(&tps6105x_driver
);
182 module_exit(tps6105x_exit
);
184 MODULE_AUTHOR("Linus Walleij");
185 MODULE_DESCRIPTION("TPS6105x White LED Boost Converter Driver");
186 MODULE_LICENSE("GPL v2");