spl_lradc_init.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Freescale i.MX28 Battery measurement init
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. * on behalf of DENX Software Engineering GmbH
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <config.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/imx-regs.h>
  29. #include "mx28_init.h"
  30. void mx28_lradc_init(void)
  31. {
  32. struct mx28_lradc_regs *regs = (struct mx28_lradc_regs *)MXS_LRADC_BASE;
  33. writel(LRADC_CTRL0_SFTRST, &regs->hw_lradc_ctrl0_clr);
  34. writel(LRADC_CTRL0_CLKGATE, &regs->hw_lradc_ctrl0_clr);
  35. writel(LRADC_CTRL0_ONCHIP_GROUNDREF, &regs->hw_lradc_ctrl0_clr);
  36. clrsetbits_le32(&regs->hw_lradc_ctrl3,
  37. LRADC_CTRL3_CYCLE_TIME_MASK,
  38. LRADC_CTRL3_CYCLE_TIME_6MHZ);
  39. clrsetbits_le32(&regs->hw_lradc_ctrl4,
  40. LRADC_CTRL4_LRADC7SELECT_MASK |
  41. LRADC_CTRL4_LRADC6SELECT_MASK,
  42. LRADC_CTRL4_LRADC7SELECT_CHANNEL7 |
  43. LRADC_CTRL4_LRADC6SELECT_CHANNEL10);
  44. }
  45. void mx28_lradc_enable_batt_measurement(void)
  46. {
  47. struct mx28_lradc_regs *regs = (struct mx28_lradc_regs *)MXS_LRADC_BASE;
  48. /* Check if the channel is present at all. */
  49. if (!(readl(&regs->hw_lradc_status) & LRADC_STATUS_CHANNEL7_PRESENT))
  50. return;
  51. writel(LRADC_CTRL1_LRADC7_IRQ_EN, &regs->hw_lradc_ctrl1_clr);
  52. writel(LRADC_CTRL1_LRADC7_IRQ, &regs->hw_lradc_ctrl1_clr);
  53. clrsetbits_le32(&regs->hw_lradc_conversion,
  54. LRADC_CONVERSION_SCALE_FACTOR_MASK,
  55. LRADC_CONVERSION_SCALE_FACTOR_LI_ION);
  56. writel(LRADC_CONVERSION_AUTOMATIC, &regs->hw_lradc_conversion_set);
  57. /* Configure the channel. */
  58. writel((1 << 7) << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
  59. &regs->hw_lradc_ctrl2_clr);
  60. writel(0xffffffff, &regs->hw_lradc_ch7_clr);
  61. clrbits_le32(&regs->hw_lradc_ch7, LRADC_CH_NUM_SAMPLES_MASK);
  62. writel(LRADC_CH_ACCUMULATE, &regs->hw_lradc_ch7_clr);
  63. /* Schedule the channel. */
  64. writel(1 << 7, &regs->hw_lradc_ctrl0_set);
  65. /* Start the channel sampling. */
  66. writel(((1 << 7) << LRADC_DELAY_TRIGGER_LRADCS_OFFSET) |
  67. ((1 << 3) << LRADC_DELAY_TRIGGER_DELAYS_OFFSET) |
  68. 100, &regs->hw_lradc_delay3);
  69. writel(0xffffffff, &regs->hw_lradc_ch7_clr);
  70. writel(LRADC_DELAY_KICK, &regs->hw_lradc_delay3_set);
  71. }