Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Stuff
Monday, April 21st, 2008 at 5:13:30pm UTC 

  1. #ifdef USE_IMX31_I2C_DRIVER
  2.         #define LOGF_ENABLE
  3.         #define IADR            (I2C_BASE_ADDR | 0x00)
  4.         #define IFDR            (I2C_BASE_ADDR | 0x04)
  5.         #define I2CR            (I2C_BASE_ADDR | 0x08)
  6.         #define I2SR            (I2C_BASE_ADDR | 0x0c)
  7.         #define I2DR            (I2C_BASE_ADDR | 0x10)
  8.  
  9.         #define I2CR_IEN        (1 << 7)
  10.         #define I2CR_IIEN       (1 << 6)
  11.         #define I2CR_MSTA       (1 << 5)
  12.         #define I2CR_MTX        (1 << 4)
  13.         #define I2CR_TX_NO_AK   (1 << 3)
  14.         #define I2CR_RSTA       (1 << 2)
  15.  
  16.         #define I2SR_ICF        (1 << 7)
  17.         #define I2SR_IBB        (1 << 5)
  18.         #define I2SR_IIF        (1 << 1)
  19.         #define I2SR_RX_NO_AK   (1 << 0)
  20.  
  21.         static unsigned short div[] = { 30, 32, 36, 42, 48, 52, 60, 72, 80, 88, 104, 128, 144,
  22.                                         160, 192, 240, 288, 320, 384, 480, 576, 640, 768, 960,
  23.                                         1152, 1280, 1536, 1920, 2304, 2560, 3072, 3840};
  24.  
  25.         static unsigned long mx31_decode_pll(int unsigned long reg, int unsigned long infreq)
  26.         {
  27.                 int unsigned long mfi = (reg >> 10) & 0xf;
  28.                 int unsigned long mfn =  reg & 0x3f;
  29.                 int unsigned long mfd = (reg >> 16) & 0x3f;
  30.                 int unsigned long pd =  (reg >> 26) & 0xf;
  31.  
  32.                 mfi = mfi <= 5 ? 5 : mfi;
  33.                 mfd += 1;
  34.                 pd += 1;
  35.  
  36.                 return ((2 * (infreq >> 10) * (mfi * mfd + mfn)) /
  37.                         (mfd * pd)) << 10;
  38.         }
  39.  
  40.         static int mx31_get_mpl_dpdgck_clk(void)
  41.         {
  42.                 int unsigned long infreq;
  43.  
  44.                 /*if ((__REG(CLKCTL_CCMR) & CCMR_PRCS_MASK) == CCMR_FPM)
  45.                         infreq = CONFIG_MX31_CLK32 * 1024;
  46.                 else*/
  47.                         infreq = CONFIG_MX31_HCLK_FREQ;
  48.  
  49.                 return mx31_decode_pll(__REG32(CCM_MPCTL), infreq);
  50.         }
  51.  
  52.         static int mx31_get_mcu_main_clk(void)
  53.         {
  54.                 /* For now we assume mpl_dpdgck_clk == mcu_main_clk
  55.                 * which should be correct for most boards
  56.                 */
  57.                 return mx31_get_mpl_dpdgck_clk();
  58.         }
  59.  
  60.         static int mx31_get_ipg_clk(void)
  61.         {
  62.                 int unsigned long freq = mx31_get_mcu_main_clk();
  63.                 int unsigned long pdr0 = __REG32(CCM_PDR0);
  64.  
  65.                 freq /= ((pdr0 >> 3) & 0x7) + 1;
  66.                 freq /= ((pdr0 >> 6) & 0x3) + 1;
  67.  
  68.                 return freq;
  69.         }
  70.         void i2c_init(int speed)
  71.         {
  72.                  int freq = mx31_get_ipg_clk();
  73.                  int i;
  74.  
  75.                  for (i = 0; i < 0x1f; i++)
  76.                         if (freq / div[i] <= speed)
  77.                                 break;
  78.  
  79.                 __REG16(I2CR) = 0; /* Reset module */
  80.                 __REG16(IFDR) = i;
  81.                 __REG16(I2CR) = I2CR_IEN;
  82.                 __REG16(I2SR) = 0;
  83.         }
  84.  
  85. #else
  86.  
  87.         #if 0
  88.         static int i2c_getack(void)
  89.         {
  90.             return 0;
  91.         }
  92.  
  93.         static int i2c_start(void)
  94.         {
  95.             return 0;
  96.         }
  97.  
  98.         static void i2c_stop(void)
  99.         {
  100.         }
  101.  
  102.         static int i2c_outb(unsigned char byte)
  103.         {
  104.             (void)byte;
  105.             return 0;
  106.         }
  107.         #endif
  108.  
  109.         void i2c_write(int addr, const unsigned char *buf, int count)
  110.         {
  111.             (void)addr;
  112.             (void)buf;
  113.             (void)count;
  114.         }
  115.  
  116.         void i2c_init(void)
  117.         {
  118.         }
  119. #endif

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right
worth-right