Lines Matching refs:twl6040

109 int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)  in twl6040_reg_read()  argument
114 ret = regmap_read(twl6040->regmap, reg, &val); in twl6040_reg_read()
122 int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val) in twl6040_reg_write() argument
126 ret = regmap_write(twl6040->regmap, reg, val); in twl6040_reg_write()
132 int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) in twl6040_set_bits() argument
134 return regmap_update_bits(twl6040->regmap, reg, mask, mask); in twl6040_set_bits()
138 int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) in twl6040_clear_bits() argument
140 return regmap_update_bits(twl6040->regmap, reg, mask, 0); in twl6040_clear_bits()
145 static int twl6040_power_up_manual(struct twl6040 *twl6040) in twl6040_power_up_manual() argument
152 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
159 ret = twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_up_manual()
166 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
173 ret = twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_up_manual()
180 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
188 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_up_manual()
191 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
194 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_up_manual()
197 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
199 dev_err(twl6040->dev, "manual power-up failed\n"); in twl6040_power_up_manual()
204 static void twl6040_power_down_manual(struct twl6040 *twl6040) in twl6040_power_down_manual() argument
208 ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL); in twl6040_power_down_manual()
209 ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL); in twl6040_power_down_manual()
210 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); in twl6040_power_down_manual()
214 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
219 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_down_manual()
223 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
227 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_down_manual()
231 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
236 struct twl6040 *twl6040 = data; in twl6040_readyint_handler() local
238 complete(&twl6040->ready); in twl6040_readyint_handler()
245 struct twl6040 *twl6040 = data; in twl6040_thint_handler() local
248 status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS); in twl6040_thint_handler()
250 dev_warn(twl6040->dev, "Thermal shutdown, powering-off"); in twl6040_thint_handler()
251 twl6040_power(twl6040, 0); in twl6040_thint_handler()
253 dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on"); in twl6040_thint_handler()
254 twl6040_power(twl6040, 1); in twl6040_thint_handler()
260 static int twl6040_power_up_automatic(struct twl6040 *twl6040) in twl6040_power_up_automatic() argument
264 gpio_set_value(twl6040->audpwron, 1); in twl6040_power_up_automatic()
266 time_left = wait_for_completion_timeout(&twl6040->ready, in twl6040_power_up_automatic()
271 dev_warn(twl6040->dev, "timeout waiting for READYINT\n"); in twl6040_power_up_automatic()
272 intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); in twl6040_power_up_automatic()
274 dev_err(twl6040->dev, "automatic power-up failed\n"); in twl6040_power_up_automatic()
275 gpio_set_value(twl6040->audpwron, 0); in twl6040_power_up_automatic()
283 int twl6040_power(struct twl6040 *twl6040, int on) in twl6040_power() argument
287 mutex_lock(&twl6040->mutex); in twl6040_power()
291 if (twl6040->power_count++) in twl6040_power()
294 clk_prepare_enable(twl6040->clk32k); in twl6040_power()
297 regcache_cache_only(twl6040->regmap, false); in twl6040_power()
299 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_power()
301 ret = twl6040_power_up_automatic(twl6040); in twl6040_power()
303 twl6040->power_count = 0; in twl6040_power()
308 ret = twl6040_power_up_manual(twl6040); in twl6040_power()
310 twl6040->power_count = 0; in twl6040_power()
316 regcache_sync(twl6040->regmap); in twl6040_power()
319 twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL; in twl6040_power()
320 twl6040->sysclk = 19200000; in twl6040_power()
321 twl6040->mclk = 32768; in twl6040_power()
324 if (!twl6040->power_count) { in twl6040_power()
325 dev_err(twl6040->dev, in twl6040_power()
331 if (--twl6040->power_count) in twl6040_power()
334 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_power()
336 gpio_set_value(twl6040->audpwron, 0); in twl6040_power()
342 twl6040_power_down_manual(twl6040); in twl6040_power()
346 regcache_cache_only(twl6040->regmap, true); in twl6040_power()
347 regcache_mark_dirty(twl6040->regmap); in twl6040_power()
349 twl6040->sysclk = 0; in twl6040_power()
350 twl6040->mclk = 0; in twl6040_power()
352 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
356 mutex_unlock(&twl6040->mutex); in twl6040_power()
361 int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, in twl6040_set_pll() argument
367 mutex_lock(&twl6040->mutex); in twl6040_set_pll()
369 hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL); in twl6040_set_pll()
370 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); in twl6040_set_pll()
373 if (pll_id != twl6040->pll) { in twl6040_set_pll()
374 twl6040->sysclk = 0; in twl6040_set_pll()
375 twl6040->mclk = 0; in twl6040_set_pll()
382 if (twl6040->sysclk != freq_out) { in twl6040_set_pll()
391 dev_err(twl6040->dev, in twl6040_set_pll()
397 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
402 if (twl6040->pll == pll_id) in twl6040_set_pll()
408 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
412 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
415 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, in twl6040_set_pll()
419 dev_err(twl6040->dev, in twl6040_set_pll()
428 dev_err(twl6040->dev, in twl6040_set_pll()
434 if (twl6040->mclk != freq_in) { in twl6040_set_pll()
459 dev_err(twl6040->dev, in twl6040_set_pll()
471 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, in twl6040_set_pll()
475 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
478 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
483 dev_err(twl6040->dev, "unknown pll id %d\n", pll_id); in twl6040_set_pll()
488 twl6040->sysclk = freq_out; in twl6040_set_pll()
489 twl6040->mclk = freq_in; in twl6040_set_pll()
490 twl6040->pll = pll_id; in twl6040_set_pll()
493 mutex_unlock(&twl6040->mutex); in twl6040_set_pll()
498 int twl6040_get_pll(struct twl6040 *twl6040) in twl6040_get_pll() argument
500 if (twl6040->power_count) in twl6040_get_pll()
501 return twl6040->pll; in twl6040_get_pll()
507 unsigned int twl6040_get_sysclk(struct twl6040 *twl6040) in twl6040_get_sysclk() argument
509 return twl6040->sysclk; in twl6040_get_sysclk()
514 int twl6040_get_vibralr_status(struct twl6040 *twl6040) in twl6040_get_vibralr_status() argument
520 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLL, &reg); in twl6040_get_vibralr_status()
525 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLR, &reg); in twl6040_get_vibralr_status()
622 struct twl6040 *twl6040; in twl6040_probe() local
637 twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040), in twl6040_probe()
639 if (!twl6040) in twl6040_probe()
642 twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config); in twl6040_probe()
643 if (IS_ERR(twl6040->regmap)) in twl6040_probe()
644 return PTR_ERR(twl6040->regmap); in twl6040_probe()
646 i2c_set_clientdata(client, twl6040); in twl6040_probe()
648 twl6040->clk32k = devm_clk_get(&client->dev, "clk32k"); in twl6040_probe()
649 if (IS_ERR(twl6040->clk32k)) { in twl6040_probe()
650 if (PTR_ERR(twl6040->clk32k) == -EPROBE_DEFER) in twl6040_probe()
653 twl6040->clk32k = NULL; in twl6040_probe()
656 twl6040->supplies[0].supply = "vio"; in twl6040_probe()
657 twl6040->supplies[1].supply = "v2v1"; in twl6040_probe()
659 twl6040->supplies); in twl6040_probe()
665 ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_probe()
671 twl6040->dev = &client->dev; in twl6040_probe()
672 twl6040->irq = client->irq; in twl6040_probe()
674 mutex_init(&twl6040->mutex); in twl6040_probe()
675 init_completion(&twl6040->ready); in twl6040_probe()
677 regmap_register_patch(twl6040->regmap, twl6040_patch, in twl6040_probe()
680 twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); in twl6040_probe()
681 if (twl6040->rev < 0) { in twl6040_probe()
683 twl6040->rev); in twl6040_probe()
684 ret = twl6040->rev; in twl6040_probe()
689 if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0) in twl6040_probe()
690 twl6040->audpwron = of_get_named_gpio(node, in twl6040_probe()
693 twl6040->audpwron = -EINVAL; in twl6040_probe()
695 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_probe()
696 ret = devm_gpio_request_one(&client->dev, twl6040->audpwron, in twl6040_probe()
702 twl6040_reg_read(twl6040, TWL6040_REG_INTID); in twl6040_probe()
705 ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, IRQF_ONESHOT, in twl6040_probe()
706 0, &twl6040_irq_chip, &twl6040->irq_data); in twl6040_probe()
710 twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data, in twl6040_probe()
712 twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data, in twl6040_probe()
715 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_ready, NULL, in twl6040_probe()
717 "twl6040_irq_ready", twl6040); in twl6040_probe()
719 dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret); in twl6040_probe()
723 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_th, NULL, in twl6040_probe()
725 "twl6040_irq_th", twl6040); in twl6040_probe()
727 dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret); in twl6040_probe()
735 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG); in twl6040_probe()
736 cell = &twl6040->cells[children]; in twl6040_probe()
746 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB); in twl6040_probe()
748 cell = &twl6040->cells[children]; in twl6040_probe()
758 cell = &twl6040->cells[children]; in twl6040_probe()
763 regcache_cache_only(twl6040->regmap, true); in twl6040_probe()
764 regcache_mark_dirty(twl6040->regmap); in twl6040_probe()
766 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children, in twl6040_probe()
774 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); in twl6040_probe()
776 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_probe()
782 struct twl6040 *twl6040 = i2c_get_clientdata(client); in twl6040_remove() local
784 if (twl6040->power_count) in twl6040_remove()
785 twl6040_power(twl6040, 0); in twl6040_remove()
787 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); in twl6040_remove()
791 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_remove()