Lines Matching defs:twl6040
41 #include <linux/mfd/twl6040.h>
109 int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
114 ret = regmap_read(twl6040->regmap, reg, &val);
122 int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val)
126 ret = regmap_write(twl6040->regmap, reg, val);
132 int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
134 return regmap_update_bits(twl6040->regmap, reg, mask, mask);
138 int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
140 return regmap_update_bits(twl6040->regmap, reg, mask, 0);
144 /* twl6040 codec manual power-up sequence */
145 static int twl6040_power_up_manual(struct twl6040 *twl6040)
152 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
159 ret = twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
166 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
173 ret = twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
180 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
188 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
191 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
194 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
197 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
199 dev_err(twl6040->dev, "manual power-up failed\n");
203 /* twl6040 manual power-down sequence */
204 static void twl6040_power_down_manual(struct twl6040 *twl6040)
208 ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL);
209 ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL);
210 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL);
214 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
219 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
223 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
227 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
231 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
236 struct twl6040 *twl6040 = data;
238 complete(&twl6040->ready);
245 struct twl6040 *twl6040 = data;
248 status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS);
250 dev_warn(twl6040->dev, "Thermal shutdown, powering-off");
251 twl6040_power(twl6040, 0);
253 dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on");
254 twl6040_power(twl6040, 1);
260 static int twl6040_power_up_automatic(struct twl6040 *twl6040)
264 gpio_set_value(twl6040->audpwron, 1);
266 time_left = wait_for_completion_timeout(&twl6040->ready,
271 dev_warn(twl6040->dev, "timeout waiting for READYINT\n");
272 intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
274 dev_err(twl6040->dev, "automatic power-up failed\n");
275 gpio_set_value(twl6040->audpwron, 0);
283 int twl6040_power(struct twl6040 *twl6040, int on)
287 mutex_lock(&twl6040->mutex);
291 if (twl6040->power_count++)
294 clk_prepare_enable(twl6040->clk32k);
297 regcache_cache_only(twl6040->regmap, false);
299 if (gpio_is_valid(twl6040->audpwron)) {
301 ret = twl6040_power_up_automatic(twl6040);
303 twl6040->power_count = 0;
308 ret = twl6040_power_up_manual(twl6040);
310 twl6040->power_count = 0;
316 regcache_sync(twl6040->regmap);
319 twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL;
320 twl6040->sysclk = 19200000;
321 twl6040->mclk = 32768;
324 if (!twl6040->power_count) {
325 dev_err(twl6040->dev,
331 if (--twl6040->power_count)
334 if (gpio_is_valid(twl6040->audpwron)) {
336 gpio_set_value(twl6040->audpwron, 0);
342 twl6040_power_down_manual(twl6040);
346 regcache_cache_only(twl6040->regmap, true);
347 regcache_mark_dirty(twl6040->regmap);
349 twl6040->sysclk = 0;
350 twl6040->mclk = 0;
352 clk_disable_unprepare(twl6040->clk32k);
356 mutex_unlock(&twl6040->mutex);
361 int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
367 mutex_lock(&twl6040->mutex);
369 hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL);
370 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL);
373 if (pll_id != twl6040->pll) {
374 twl6040->sysclk = 0;
375 twl6040->mclk = 0;
382 if (twl6040->sysclk != freq_out) {
391 dev_err(twl6040->dev,
397 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
402 if (twl6040->pll == pll_id)
408 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
412 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
415 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL,
419 dev_err(twl6040->dev,
428 dev_err(twl6040->dev,
434 if (twl6040->mclk != freq_in) {
459 dev_err(twl6040->dev,
471 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL,
475 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
478 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
483 dev_err(twl6040->dev, "unknown pll id %d\n", pll_id);
488 twl6040->sysclk = freq_out;
489 twl6040->mclk = freq_in;
490 twl6040->pll = pll_id;
493 mutex_unlock(&twl6040->mutex);
498 int twl6040_get_pll(struct twl6040 *twl6040)
500 if (twl6040->power_count)
501 return twl6040->pll;
507 unsigned int twl6040_get_sysclk(struct twl6040 *twl6040)
509 return twl6040->sysclk;
514 int twl6040_get_vibralr_status(struct twl6040 *twl6040)
520 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLL, ®);
525 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLR, ®);
609 .name = "twl6040",
622 struct twl6040 *twl6040;
637 twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040),
639 if (!twl6040)
642 twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config);
643 if (IS_ERR(twl6040->regmap))
644 return PTR_ERR(twl6040->regmap);
646 i2c_set_clientdata(client, twl6040);
648 twl6040->clk32k = devm_clk_get(&client->dev, "clk32k");
649 if (IS_ERR(twl6040->clk32k)) {
651 twl6040->clk32k = NULL;
654 twl6040->supplies[0].supply = "vio";
655 twl6040->supplies[1].supply = "v2v1";
657 twl6040->supplies);
663 ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
669 twl6040->dev = &client->dev;
670 twl6040->irq = client->irq;
672 mutex_init(&twl6040->mutex);
673 init_completion(&twl6040->ready);
675 regmap_register_patch(twl6040->regmap, twl6040_patch,
678 twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV);
679 if (twl6040->rev < 0) {
681 twl6040->rev);
682 ret = twl6040->rev;
687 if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0)
688 twl6040->audpwron = of_get_named_gpio(node,
691 twl6040->audpwron = -EINVAL;
693 if (gpio_is_valid(twl6040->audpwron)) {
694 ret = devm_gpio_request_one(&client->dev, twl6040->audpwron,
700 twl6040_reg_read(twl6040, TWL6040_REG_INTID);
703 ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, IRQF_ONESHOT,
704 0, &twl6040_irq_chip, &twl6040->irq_data);
708 twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data,
710 twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data,
713 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_ready, NULL,
715 "twl6040_irq_ready", twl6040);
717 dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret);
721 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_th, NULL,
723 "twl6040_irq_th", twl6040);
725 dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret);
730 * The main functionality of twl6040 to provide audio on OMAP4+ systems.
733 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG);
734 cell = &twl6040->cells[children];
735 cell->name = "twl6040-codec";
744 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB);
746 cell = &twl6040->cells[children];
747 cell->name = "twl6040-vibra";
756 cell = &twl6040->cells[children];
757 cell->name = "twl6040-gpo";
761 regcache_cache_only(twl6040->regmap, true);
762 regcache_mark_dirty(twl6040->regmap);
764 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children,
772 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
774 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
780 struct twl6040 *twl6040 = i2c_get_clientdata(client);
782 if (twl6040->power_count)
783 twl6040_power(twl6040, 0);
785 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
789 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
795 { "twl6040", 0, },
803 .name = "twl6040",
817 MODULE_ALIAS("platform:twl6040");