Lines Matching refs:twl6040

98 int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)  in twl6040_reg_read()  argument
103 ret = regmap_read(twl6040->regmap, reg, &val); in twl6040_reg_read()
111 int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val) in twl6040_reg_write() argument
115 ret = regmap_write(twl6040->regmap, reg, val); in twl6040_reg_write()
121 int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) in twl6040_set_bits() argument
123 return regmap_update_bits(twl6040->regmap, reg, mask, mask); in twl6040_set_bits()
127 int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask) in twl6040_clear_bits() argument
129 return regmap_update_bits(twl6040->regmap, reg, mask, 0); in twl6040_clear_bits()
134 static int twl6040_power_up_manual(struct twl6040 *twl6040) in twl6040_power_up_manual() argument
141 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
148 ret = twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_up_manual()
155 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
162 ret = twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_up_manual()
169 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
177 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_up_manual()
180 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
183 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_up_manual()
186 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_up_manual()
188 dev_err(twl6040->dev, "manual power-up failed\n"); in twl6040_power_up_manual()
193 static void twl6040_power_down_manual(struct twl6040 *twl6040) in twl6040_power_down_manual() argument
197 ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL); in twl6040_power_down_manual()
198 ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL); in twl6040_power_down_manual()
199 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); in twl6040_power_down_manual()
203 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
208 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl); in twl6040_power_down_manual()
212 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
216 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl); in twl6040_power_down_manual()
220 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl); in twl6040_power_down_manual()
225 struct twl6040 *twl6040 = data; in twl6040_readyint_handler() local
227 complete(&twl6040->ready); in twl6040_readyint_handler()
234 struct twl6040 *twl6040 = data; in twl6040_thint_handler() local
237 status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS); in twl6040_thint_handler()
239 dev_warn(twl6040->dev, "Thermal shutdown, powering-off"); in twl6040_thint_handler()
240 twl6040_power(twl6040, 0); in twl6040_thint_handler()
242 dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on"); in twl6040_thint_handler()
243 twl6040_power(twl6040, 1); in twl6040_thint_handler()
249 static int twl6040_power_up_automatic(struct twl6040 *twl6040) in twl6040_power_up_automatic() argument
253 gpiod_set_value_cansleep(twl6040->audpwron, 1); in twl6040_power_up_automatic()
255 time_left = wait_for_completion_timeout(&twl6040->ready, in twl6040_power_up_automatic()
260 dev_warn(twl6040->dev, "timeout waiting for READYINT\n"); in twl6040_power_up_automatic()
261 intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); in twl6040_power_up_automatic()
263 dev_err(twl6040->dev, "automatic power-up failed\n"); in twl6040_power_up_automatic()
264 gpiod_set_value_cansleep(twl6040->audpwron, 0); in twl6040_power_up_automatic()
272 int twl6040_power(struct twl6040 *twl6040, int on) in twl6040_power() argument
276 mutex_lock(&twl6040->mutex); in twl6040_power()
280 if (twl6040->power_count++) in twl6040_power()
283 ret = clk_prepare_enable(twl6040->clk32k); in twl6040_power()
285 twl6040->power_count = 0; in twl6040_power()
290 regcache_cache_only(twl6040->regmap, false); in twl6040_power()
292 if (twl6040->audpwron) { in twl6040_power()
294 ret = twl6040_power_up_automatic(twl6040); in twl6040_power()
296 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
297 twl6040->power_count = 0; in twl6040_power()
302 ret = twl6040_power_up_manual(twl6040); in twl6040_power()
304 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
305 twl6040->power_count = 0; in twl6040_power()
317 ret = regcache_sync(twl6040->regmap); in twl6040_power()
319 dev_err(twl6040->dev, "Failed to sync with the HW: %i\n", in twl6040_power()
325 twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL; in twl6040_power()
326 twl6040->sysclk_rate = 19200000; in twl6040_power()
329 if (!twl6040->power_count) { in twl6040_power()
330 dev_err(twl6040->dev, in twl6040_power()
336 if (--twl6040->power_count) in twl6040_power()
339 if (twl6040->audpwron) { in twl6040_power()
341 gpiod_set_value_cansleep(twl6040->audpwron, 0); in twl6040_power()
347 twl6040_power_down_manual(twl6040); in twl6040_power()
351 regcache_cache_only(twl6040->regmap, true); in twl6040_power()
352 regcache_mark_dirty(twl6040->regmap); in twl6040_power()
354 twl6040->sysclk_rate = 0; in twl6040_power()
356 if (twl6040->pll == TWL6040_SYSCLK_SEL_HPPLL) { in twl6040_power()
357 clk_disable_unprepare(twl6040->mclk); in twl6040_power()
358 twl6040->mclk_rate = 0; in twl6040_power()
361 clk_disable_unprepare(twl6040->clk32k); in twl6040_power()
365 mutex_unlock(&twl6040->mutex); in twl6040_power()
370 int twl6040_set_pll(struct twl6040 *twl6040, int pll_id, in twl6040_set_pll() argument
376 mutex_lock(&twl6040->mutex); in twl6040_set_pll()
378 hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL); in twl6040_set_pll()
379 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL); in twl6040_set_pll()
382 if (pll_id != twl6040->pll) { in twl6040_set_pll()
383 twl6040->sysclk_rate = 0; in twl6040_set_pll()
384 twl6040->mclk_rate = 0; in twl6040_set_pll()
391 if (twl6040->sysclk_rate != freq_out) { in twl6040_set_pll()
400 dev_err(twl6040->dev, in twl6040_set_pll()
406 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
411 if (twl6040->pll == pll_id) in twl6040_set_pll()
417 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
421 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
424 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, in twl6040_set_pll()
428 dev_err(twl6040->dev, in twl6040_set_pll()
434 clk_disable_unprepare(twl6040->mclk); in twl6040_set_pll()
439 dev_err(twl6040->dev, in twl6040_set_pll()
445 if (twl6040->mclk_rate != freq_in) { in twl6040_set_pll()
470 dev_err(twl6040->dev, in twl6040_set_pll()
477 if (pll_id != twl6040->pll) in twl6040_set_pll()
478 clk_prepare_enable(twl6040->mclk); in twl6040_set_pll()
485 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL, in twl6040_set_pll()
489 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
492 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, in twl6040_set_pll()
495 twl6040->mclk_rate = freq_in; in twl6040_set_pll()
499 dev_err(twl6040->dev, "unknown pll id %d\n", pll_id); in twl6040_set_pll()
504 twl6040->sysclk_rate = freq_out; in twl6040_set_pll()
505 twl6040->pll = pll_id; in twl6040_set_pll()
508 mutex_unlock(&twl6040->mutex); in twl6040_set_pll()
513 int twl6040_get_pll(struct twl6040 *twl6040) in twl6040_get_pll() argument
515 if (twl6040->power_count) in twl6040_get_pll()
516 return twl6040->pll; in twl6040_get_pll()
522 unsigned int twl6040_get_sysclk(struct twl6040 *twl6040) in twl6040_get_sysclk() argument
524 return twl6040->sysclk_rate; in twl6040_get_sysclk()
529 int twl6040_get_vibralr_status(struct twl6040 *twl6040) in twl6040_get_vibralr_status() argument
535 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLL, &reg); in twl6040_get_vibralr_status()
540 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLR, &reg); in twl6040_get_vibralr_status()
638 struct twl6040 *twl6040; in twl6040_probe() local
653 twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040), in twl6040_probe()
655 if (!twl6040) in twl6040_probe()
658 twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config); in twl6040_probe()
659 if (IS_ERR(twl6040->regmap)) in twl6040_probe()
660 return PTR_ERR(twl6040->regmap); in twl6040_probe()
662 i2c_set_clientdata(client, twl6040); in twl6040_probe()
664 twl6040->clk32k = devm_clk_get(&client->dev, "clk32k"); in twl6040_probe()
665 if (IS_ERR(twl6040->clk32k)) { in twl6040_probe()
666 if (PTR_ERR(twl6040->clk32k) == -EPROBE_DEFER) in twl6040_probe()
669 twl6040->clk32k = NULL; in twl6040_probe()
672 twl6040->mclk = devm_clk_get(&client->dev, "mclk"); in twl6040_probe()
673 if (IS_ERR(twl6040->mclk)) { in twl6040_probe()
674 if (PTR_ERR(twl6040->mclk) == -EPROBE_DEFER) in twl6040_probe()
677 twl6040->mclk = NULL; in twl6040_probe()
680 twl6040->supplies[0].supply = "vio"; in twl6040_probe()
681 twl6040->supplies[1].supply = "v2v1"; in twl6040_probe()
683 twl6040->supplies); in twl6040_probe()
689 ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_probe()
695 twl6040->dev = &client->dev; in twl6040_probe()
696 twl6040->irq = client->irq; in twl6040_probe()
698 mutex_init(&twl6040->mutex); in twl6040_probe()
699 init_completion(&twl6040->ready); in twl6040_probe()
701 regmap_register_patch(twl6040->regmap, twl6040_patch, in twl6040_probe()
704 twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV); in twl6040_probe()
705 if (twl6040->rev < 0) { in twl6040_probe()
707 twl6040->rev); in twl6040_probe()
708 ret = twl6040->rev; in twl6040_probe()
713 if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0) { in twl6040_probe()
714 twl6040->audpwron = devm_gpiod_get_optional(&client->dev, in twl6040_probe()
717 ret = PTR_ERR_OR_ZERO(twl6040->audpwron); in twl6040_probe()
721 gpiod_set_consumer_name(twl6040->audpwron, "audpwron"); in twl6040_probe()
724 twl6040_reg_read(twl6040, TWL6040_REG_INTID); in twl6040_probe()
727 ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, IRQF_ONESHOT, in twl6040_probe()
728 0, &twl6040_irq_chip, &twl6040->irq_data); in twl6040_probe()
732 twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data, in twl6040_probe()
734 twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data, in twl6040_probe()
737 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_ready, NULL, in twl6040_probe()
739 "twl6040_irq_ready", twl6040); in twl6040_probe()
741 dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret); in twl6040_probe()
745 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_th, NULL, in twl6040_probe()
747 "twl6040_irq_th", twl6040); in twl6040_probe()
749 dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret); in twl6040_probe()
757 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG); in twl6040_probe()
758 cell = &twl6040->cells[children]; in twl6040_probe()
768 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB); in twl6040_probe()
770 cell = &twl6040->cells[children]; in twl6040_probe()
780 cell = &twl6040->cells[children]; in twl6040_probe()
785 cell = &twl6040->cells[children]; in twl6040_probe()
790 regcache_cache_only(twl6040->regmap, true); in twl6040_probe()
791 regcache_mark_dirty(twl6040->regmap); in twl6040_probe()
793 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children, in twl6040_probe()
801 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); in twl6040_probe()
803 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_probe()
809 struct twl6040 *twl6040 = i2c_get_clientdata(client); in twl6040_remove() local
811 if (twl6040->power_count) in twl6040_remove()
812 twl6040_power(twl6040, 0); in twl6040_remove()
814 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data); in twl6040_remove()
818 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies); in twl6040_remove()