26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/slab.h>
29 #include <linux/kernel.h>
38 #include <linux/i2c.h>
45 #define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1)
46 #define TWL6040_NUM_SUPPLIES (2)
51 if (pdata && pdata->
vibra)
109 u8 ldoctl, ncpctl, lppllctl;
165 static void twl6040_power_down(
struct twl6040 *twl6040)
167 u8 ncpctl, ldoctl, lppllctl;
197 struct twl6040 *twl6040 =
data;
209 "Thermal shutdown, powering-off");
213 "Leaving thermal shutdown, powering-on");
221 static int twl6040_power_up_completion(
struct twl6040 *twl6040,
231 if (!(intid & TWL6040_READYINT)) {
233 "timeout waiting for READYINT\n");
244 int naudint = twl6040->
irq;
254 if (gpio_is_valid(audpwron)) {
258 ret = twl6040_power_up_completion(twl6040, naudint);
261 "automatic power-down failed\n");
267 ret = twl6040_power_up(twl6040);
270 "manual power-up failed\n");
277 twl6040->
sysclk = 19200000;
278 twl6040->
mclk = 32768;
283 "device is already powered-off\n");
291 if (gpio_is_valid(audpwron)) {
299 twl6040_power_down(twl6040);
312 unsigned int freq_in,
unsigned int freq_out)
314 u8 hppllctl, lppllctl;
323 if (pll_id != twl6040->
pll) {
332 if (twl6040->
sysclk != freq_out) {
342 "freq_out %d not supported\n",
352 if (twl6040->
pll == pll_id)
370 "freq_in %d not supported\n", freq_in);
377 if (freq_out != 19200000) {
379 "freq_out %d not supported\n", freq_out);
384 if (twl6040->
mclk != freq_in) {
413 "freq_in %d not supported\n", freq_in);
436 dev_err(twl6040->
dev,
"unknown pll id %d\n", pll_id);
441 twl6040->
sysclk = freq_out;
442 twl6040->
mclk = freq_in;
443 twl6040->
pll = pll_id;
478 static struct resource twl6040_vibra_rsrc[] = {
484 static struct resource twl6040_codec_rsrc[] = {
490 static bool twl6040_readable_reg(
struct device *
dev,
unsigned int reg)
498 static struct regmap_config twl6040_regmap_config = {
503 .readable_reg = twl6040_readable_reg,
511 struct twl6040 *twl6040;
513 int irq,
ret, children = 0;
515 if (!pdata && !node) {
516 dev_err(&client->
dev,
"Platform data is missing\n");
522 dev_err(&client->
dev,
"Invalid IRQ configuration\n");
534 if (IS_ERR(twl6040->
regmap)) {
535 ret = PTR_ERR(twl6040->
regmap);
539 i2c_set_clientdata(client, twl6040);
541 twl6040->
supplies[0].supply =
"vio";
542 twl6040->
supplies[1].supply =
"v2v1";
546 dev_err(&client->
dev,
"Failed to get supplies: %d\n", ret);
547 goto regulator_get_err;
552 dev_err(&client->
dev,
"Failed to enable supplies: %d\n", ret);
556 twl6040->
dev = &client->
dev;
557 twl6040->
irq = client->
irq;
560 init_completion(&twl6040->
ready);
569 twl6040->
audpwron = of_get_named_gpio(node,
570 "ti,audpwron-gpio", 0);
574 if (gpio_is_valid(twl6040->
audpwron)) {
588 "twl6040_irq_ready", twl6040);
590 dev_err(twl6040->
dev,
"READY IRQ request failed: %d\n",
605 cell = &twl6040->
cells[children];
606 cell->
name =
"twl6040-codec";
607 twl6040_codec_rsrc[0].
start = irq;
608 twl6040_codec_rsrc[0].
end = irq;
611 if (pdata && pdata->
codec) {
617 if (twl6040_has_vibra(pdata, node)) {
620 cell = &twl6040->
cells[children];
621 cell->
name =
"twl6040-vibra";
622 twl6040_vibra_rsrc[0].
start = irq;
623 twl6040_vibra_rsrc[0].
end = irq;
627 if (pdata && pdata->
vibra) {
638 if (!pdata || (pdata && pdata->
gpo)) {
639 cell = &twl6040->
cells[children];
640 cell->
name =
"twl6040-gpo";
661 if (gpio_is_valid(twl6040->
audpwron))
668 i2c_set_clientdata(client,
NULL);
675 struct twl6040 *twl6040 = i2c_get_clientdata(client);
680 if (gpio_is_valid(twl6040->
audpwron))
687 i2c_set_clientdata(client,
NULL);
707 .probe = twl6040_probe,
709 .id_table = twl6040_i2c_id,