Lines Matching refs:twl6040

99 int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)  in twl6040_reg_read()  argument
104 ret = regmap_read(twl6040->regmap, reg, &val); in twl6040_reg_read()
112 int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val) in twl6040_reg_write() argument
116 ret = regmap_write(twl6040->regmap, reg, val); in twl6040_reg_write()
122 int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) in twl6040_set_bits() argument
124 return regmap_update_bits(twl6040->regmap, reg, mask, mask); in twl6040_set_bits()
128 int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) in twl6040_clear_bits() argument
130 return regmap_update_bits(twl6040->regmap, reg, mask, 0); in twl6040_clear_bits()
135 static int twl6040_power_up_manual(struct twl6040 *twl6040) in twl6040_power_up_manual() argument
142 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
149 ret = twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_up_manual()
156 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
163 ret = twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_up_manual()
170 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
178 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_up_manual()
181 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
184 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_up_manual()
187 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
189 dev_err(twl6040->dev, "manual power-up failed\n"); in twl6040_power_up_manual()
194 static void twl6040_power_down_manual(struct twl6040 *twl6040) in twl6040_power_down_manual() argument
198 ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL); in twl6040_power_down_manual()
199 ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL); in twl6040_power_down_manual()
200 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); in twl6040_power_down_manual()
204 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
209 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_down_manual()
213 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
217 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_down_manual()
221 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
226 struct twl6040 *twl6040 = data; in twl6040_readyint_handler() local
228 complete(&twl6040->ready); in twl6040_readyint_handler()
235 struct twl6040 *twl6040 = data; in twl6040_thint_handler() local
238 status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS); in twl6040_thint_handler()
240 dev_warn(twl6040->dev, "Thermal shutdown, powering-off"); in twl6040_thint_handler()
241 twl6040_power(twl6040, 0); in twl6040_thint_handler()
243 dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on"); in twl6040_thint_handler()
244 twl6040_power(twl6040, 1); in twl6040_thint_handler()
250 static int twl6040_power_up_automatic(struct twl6040 *twl6040) in twl6040_power_up_automatic() argument
254 gpio_set_value(twl6040->audpwron, 1); in twl6040_power_up_automatic()
256 time_left = wait_for_completion_timeout(&twl6040->ready, in twl6040_power_up_automatic()
261 dev_warn(twl6040->dev, "timeout waiting for READYINT\n"); in twl6040_power_up_automatic()
262 intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); in twl6040_power_up_automatic()
264 dev_err(twl6040->dev, "automatic power-up failed\n"); in twl6040_power_up_automatic()
265 gpio_set_value(twl6040->audpwron, 0); in twl6040_power_up_automatic()
273 int twl6040_power(struct twl6040 *twl6040, int on) in twl6040_power() argument
277 mutex_lock(&twl6040->mutex); in twl6040_power()
281 if (twl6040->power_count++) in twl6040_power()
284 ret = clk_prepare_enable(twl6040->clk32k); in twl6040_power()
286 twl6040->power_count = 0; in twl6040_power()
291 regcache_cache_only(twl6040->regmap, false); in twl6040_power()
293 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_power()
295 ret = twl6040_power_up_automatic(twl6040); in twl6040_power()
297 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
298 twl6040->power_count = 0; in twl6040_power()
303 ret = twl6040_power_up_manual(twl6040); in twl6040_power()
305 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
306 twl6040->power_count = 0; in twl6040_power()
318 ret = regcache_sync(twl6040->regmap); in twl6040_power()
320 dev_err(twl6040->dev, "Failed to sync with the HW: %i\n", in twl6040_power()
326 twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL; in twl6040_power()
327 twl6040->sysclk_rate = 19200000; in twl6040_power()
330 if (!twl6040->power_count) { in twl6040_power()
331 dev_err(twl6040->dev, in twl6040_power()
337 if (--twl6040->power_count) in twl6040_power()
340 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_power()
342 gpio_set_value(twl6040->audpwron, 0); in twl6040_power()
348 twl6040_power_down_manual(twl6040); in twl6040_power()
352 regcache_cache_only(twl6040->regmap, true); in twl6040_power()
353 regcache_mark_dirty(twl6040->regmap); in twl6040_power()
355 twl6040->sysclk_rate = 0; in twl6040_power()
357 if (twl6040->pll == TWL6040_SYSCLK_SEL_HPPLL) { in twl6040_power()
358 clk_disable_unprepare(twl6040->mclk); in twl6040_power()
359 twl6040->mclk_rate = 0; in twl6040_power()
362 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
366 mutex_unlock(&twl6040->mutex); in twl6040_power()
371 int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, in twl6040_set_pll() argument
377 mutex_lock(&twl6040->mutex); in twl6040_set_pll()
379 hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL); in twl6040_set_pll()
380 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); in twl6040_set_pll()
383 if (pll_id != twl6040->pll) { in twl6040_set_pll()
384 twl6040->sysclk_rate = 0; in twl6040_set_pll()
385 twl6040->mclk_rate = 0; in twl6040_set_pll()
392 if (twl6040->sysclk_rate != freq_out) { in twl6040_set_pll()
401 dev_err(twl6040->dev, in twl6040_set_pll()
407 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
412 if (twl6040->pll == pll_id) in twl6040_set_pll()
418 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
422 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
425 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, in twl6040_set_pll()
429 dev_err(twl6040->dev, in twl6040_set_pll()
435 clk_disable_unprepare(twl6040->mclk); in twl6040_set_pll()
440 dev_err(twl6040->dev, in twl6040_set_pll()
446 if (twl6040->mclk_rate != freq_in) { in twl6040_set_pll()
471 dev_err(twl6040->dev, in twl6040_set_pll()
478 if (pll_id != twl6040->pll) in twl6040_set_pll()
479 clk_prepare_enable(twl6040->mclk); in twl6040_set_pll()
486 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, in twl6040_set_pll()
490 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
493 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
496 twl6040->mclk_rate = freq_in; in twl6040_set_pll()
500 dev_err(twl6040->dev, "unknown pll id %d\n", pll_id); in twl6040_set_pll()
505 twl6040->sysclk_rate = freq_out; in twl6040_set_pll()
506 twl6040->pll = pll_id; in twl6040_set_pll()
509 mutex_unlock(&twl6040->mutex); in twl6040_set_pll()
514 int twl6040_get_pll(struct twl6040 *twl6040) in twl6040_get_pll() argument
516 if (twl6040->power_count) in twl6040_get_pll()
517 return twl6040->pll; in twl6040_get_pll()
523 unsigned int twl6040_get_sysclk(struct twl6040 *twl6040) in twl6040_get_sysclk() argument
525 return twl6040->sysclk_rate; in twl6040_get_sysclk()
530 int twl6040_get_vibralr_status(struct twl6040 *twl6040) in twl6040_get_vibralr_status() argument
536 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLL, &reg); in twl6040_get_vibralr_status()
541 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLR, &reg); in twl6040_get_vibralr_status()
640 struct twl6040 *twl6040; in twl6040_probe() local
655 twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040), in twl6040_probe()
657 if (!twl6040) in twl6040_probe()
660 twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config); in twl6040_probe()
661 if (IS_ERR(twl6040->regmap)) in twl6040_probe()
662 return PTR_ERR(twl6040->regmap); in twl6040_probe()
664 i2c_set_clientdata(client, twl6040); in twl6040_probe()
666 twl6040->clk32k = devm_clk_get(&client->dev, "clk32k"); in twl6040_probe()
667 if (IS_ERR(twl6040->clk32k)) { in twl6040_probe()
668 if (PTR_ERR(twl6040->clk32k) == -EPROBE_DEFER) in twl6040_probe()
671 twl6040->clk32k = NULL; in twl6040_probe()
674 twl6040->mclk = devm_clk_get(&client->dev, "mclk"); in twl6040_probe()
675 if (IS_ERR(twl6040->mclk)) { in twl6040_probe()
676 if (PTR_ERR(twl6040->mclk) == -EPROBE_DEFER) in twl6040_probe()
679 twl6040->mclk = NULL; in twl6040_probe()
682 twl6040->supplies[0].supply = "vio"; in twl6040_probe()
683 twl6040->supplies[1].supply = "v2v1"; in twl6040_probe()
685 twl6040->supplies); in twl6040_probe()
691 ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_probe()
697 twl6040->dev = &client->dev; in twl6040_probe()
698 twl6040->irq = client->irq; in twl6040_probe()
700 mutex_init(&twl6040->mutex); in twl6040_probe()
701 init_completion(&twl6040->ready); in twl6040_probe()
703 regmap_register_patch(twl6040->regmap, twl6040_patch, in twl6040_probe()
706 twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); in twl6040_probe()
707 if (twl6040->rev < 0) { in twl6040_probe()
709 twl6040->rev); in twl6040_probe()
710 ret = twl6040->rev; in twl6040_probe()
715 if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0) in twl6040_probe()
716 twl6040->audpwron = of_get_named_gpio(node, in twl6040_probe()
719 twl6040->audpwron = -EINVAL; in twl6040_probe()
721 if (gpio_is_valid(twl6040->audpwron)) { in twl6040_probe()
722 ret = devm_gpio_request_one(&client->dev, twl6040->audpwron, in twl6040_probe()
728 twl6040_reg_read(twl6040, TWL6040_REG_INTID); in twl6040_probe()
731 ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, IRQF_ONESHOT, in twl6040_probe()
732 0, &twl6040_irq_chip, &twl6040->irq_data); in twl6040_probe()
736 twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data, in twl6040_probe()
738 twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data, in twl6040_probe()
741 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_ready, NULL, in twl6040_probe()
743 "twl6040_irq_ready", twl6040); in twl6040_probe()
745 dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret); in twl6040_probe()
749 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_th, NULL, in twl6040_probe()
751 "twl6040_irq_th", twl6040); in twl6040_probe()
753 dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret); in twl6040_probe()
761 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG); in twl6040_probe()
762 cell = &twl6040->cells[children]; in twl6040_probe()
772 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB); in twl6040_probe()
774 cell = &twl6040->cells[children]; in twl6040_probe()
784 cell = &twl6040->cells[children]; in twl6040_probe()
789 cell = &twl6040->cells[children]; in twl6040_probe()
794 regcache_cache_only(twl6040->regmap, true); in twl6040_probe()
795 regcache_mark_dirty(twl6040->regmap); in twl6040_probe()
797 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children, in twl6040_probe()
805 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); in twl6040_probe()
807 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_probe()
813 struct twl6040 *twl6040 = i2c_get_clientdata(client); in twl6040_remove() local
815 if (twl6040->power_count) in twl6040_remove()
816 twl6040_power(twl6040, 0); in twl6040_remove()
818 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); in twl6040_remove()
822 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_remove()