RTC 芯片 ISL12020M 驱动编程

ISL1208-后备电池供电的低功率RTC SRAM ISL1208-后备电池供电的低功率RTC SRAMISL1208 介绍引脚图特征方框图可选封装行业应用 ISL1208 介绍 ISL1208是低功耗实时时钟,带定时与晶体补偿、时钟/日历、电源失效指示器、周期或轮询报警、智能后备电池切换和后备电池供电的用户SRAM。振荡器采用外部、低成本、32.768kHz的晶体。实时时钟用独立的时、分、秒寄存器跟踪时间,并且还带有日历寄存器用于存储日、月、年和星期。日历精确到2099年,具有闰年自动修正功能。 引脚图 特征 实时时钟/日历-以小时、分钟和秒为单位跟踪 阅读详情
  1. 这段时间编了个RTC芯片ISL12020M的驱动程序,程序大部分是从ISL1208上移植过来的。寄存器地址进行了重新设置。现在已经编译通过了,还是有点成就感。嘿嘿。代码如下:
  2.     /*
         * Intersil ISL12020M rtc class driver
         *
         *
         *
         * This program is free software; you can redistribute it and/or modify it
         * under the terms of the GNU General Public License as published by the
         * Free Software Foundation; either version 2 of the License, or (at your
         * option) any later version.
         *
         */
        #include <linux/module.h>
        #include <linux/i2c.h>
        #include <linux/bcd.h>
        #include <linux/rtc.h>
        #define DRV_NAME "isl12020m"
        #define DRV_VERSION "0.2"
        /* Register map */
        /* rtc section */
        #define ISL12020M_REG_SC 0x00
        #define ISL12020M_REG_MN 0x01
        #define ISL12020M_REG_HR 0x02
        #define ISL12020M_REG_HR_MIL (1<<7) /* 24h/12h mode */
        #define ISL12020M_REG_HR_PM (1<<5) /* PM/AM bit in 12h mode */
        #define ISL12020M_REG_DT 0x03
        #define ISL12020M_REG_MO 0x04
        #define ISL12020M_REG_YR 0x05
        #define ISL12020M_REG_DW 0x06
        #define ISL12020M_RTC_SECTION_LEN 7
        /* control/status section */
        #define ISL12020M_REG_SR 0x07 /* status reg */
        #define ISL12020M_REG_SR_DSTADJ (1<<5) /* daylight saving time change */
        #define ISL12020M_REG_SR_ALM (1<<4) /* alarm bit ,can only set 0 */
        #define ISL12020M_REG_SR_LBAT85 (1<<2) /* low battery indicator 85% */
        #define ISL12020M_REG_SR_LBAT75 (1<<1) /* low battery indicator 75% */
        #define ISL12020M_REG_SR_RTCF (1<<0) /* real time clock fail */
        #define ISL12020M_REG_INT 0x08 /* interrupt control reg */
        #define ISL12020M_REG_INT_ARST (1<<7) /* automatic reset */
        #define ISL12020M_REG_INT_WRTC (1<<6) /* write rtc enable */
        #define ISL12020M_REG_INT_IM (1<<5) /* interrupt/alarm mode */
        #define ISL12020M_REG_INT_FOBATB (1<<4) /* frequency output and interrupt */
        #define ISL12020M_REG_PWR_VDD 0x09 /* power supply control reg */
        #define ISL12020M_REG_PWR_VDD_CLRTS (1<<7) /* clear time stamp VDD to battery and time stamp battery to VDD regs */
        #define ISL12020M_REG_PWR_VBAT 0x0A /* battery voltage trip voltage reg */
        #define ISL12020M_REG_ITR0 0x0B /* initial AT and DT setting reg */
        #define ISL12020M_REG_ALPHA 0x0C /* ALPHA reg ,temperature coefficient */
        #define ISL12020M_REG_BETA 0x0D /* BETA reg, */
        #define ISL12020M_REG_BETA_TSE (1<<7) /* temperature sensor enable */
        #define ISL12020M_REG_FATR 0x0E /* final analog trimming reg */
        #define ISL12020M_REG_FDTR 0x0F /* final digital trimming reg */
        /* alarm section */
        #define ISL12020M_REG_SCA0 0x10 /* second */
        #define ISL12020M_REG_MNA0 0x11 /* minute */
        #define ISL12020M_REG_HRA0 0x12 /* hour */
        #define ISL12020M_REG_DTA0 0x13 /* date */
        #define ISL12020M_REG_MOA0 0x14 /* month */
        #define ISL12020M_REG_DWA0 0x15 /* day of week */
        #define ISL12020M_ALARM_SECTION_LEN 6
        /* TSV2B section, time stamp VDD to battery*/
        #define ISL12020M_REG_VSC 0x16
        #define ISL12020M_REG_VMN 0x17
        #define ISL12020M_REG_VHR 0x18
        #define ISL12020M_REG_VDT 0x19
        #define ISL12020M_REG_VMO 0x1A
        /* TSB2V, time stamp battery to VDD */
        #define ISL12020M_REG_BSC 0x1B
        #define ISL12020M_REG_BMN 0x1C
        #define ISL12020M_REG_BHR 0x1D
        #define ISL12020M_REG_BDT 0x1E
        #define ISL12020M_REG_BMO 0x1F
        /* DSTCR, DST control regs */
        /* DST begginning time, set forward */
        #define ISL12020M_REG_DSTMOFD 0x20
        #define ISL12020M_REG_DSTMOFD_DSTE (1<<7) /* dst enable bit */
        #define ISL12020M_REG_DSTDWFD 0x21
        #define ISL12020M_REG_DSTDWFD_DSTDWFDE (1<<6 ) /* set the priority of the day/week over the date */
        #define ISL12020M_REG_DSTDTFD 0x22
        #define ISL12020M_REG_DSTHRFD 0x23
        /* DST ending time, set backward or reverse */
        #define ISL12020M_REG_DSTMORV 0x24
        #define ISL12020M_REG_DSTDWRV 0x25
        #define ISL12020M_REG_DSTDWRV_DSTDWRVE (1<<6) /* set the priority of the day/week over the date */
        #define ISL12020M_REG_DSTDTRV 0x26
        #define ISL12020M_REG_DSTHRRV 0x27
        /* temperature regs*/
        #define ISL12020M_REG_TK0L 0x28 /*LSB 8 bit*/
        #define ISL12020M_REG_TK0M 0x29 /* MSB 2 bit */
        /* NPPM */
        #define ISL12020M_REG_NPPML 0x2A
        #define ISL12020M_REG_NPPMH 0x2B
        /* XT0 regs */
        #define ISL12020M_REG_XT0 0x2C
        /* ALPHA hot reg */
        #define ISL12020M_REG_ALPHAH 0x2D
        /* GPM section ,general purpose user sram */
        #define ISL12020M_REG_GPM1 0x2E
        #define ISL12020M_REG_GPM2 0x2F
        #define ISL12020M_GPM_SECTION_LEN 2
        /* i2c configuration */
        #define ISL12020M_I2C_ADDR 0xde /* 1101 1110*/
        static unsigned short normal_i2c[] = {
         ISL12020M_I2C_ADDR>>1, I2C_CLIENT_END
        };
        I2C_CLIENT_INSMOD; /* defines addr_data */
        static int isl12020m_attach_adapter(struct i2c_adapter *adapter);
        static int isl12020m_detach_client(struct i2c_client *client);
        static struct i2c_driver isl12020m_driver = {
         .driver = {
          .name = DRV_NAME,
         },
         .id = I2C_DRIVERID_ISL12020M,
         .attach_adapter = &isl12020m_attach_adapter,
         .detach_client = &isl12020m_detach_client,
        };
        /* block read */
        static int
        isl12020m_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
                 unsigned len)
        {
         u8 reg_addr[1] = { reg };
         struct i2c_msg msgs[2] = {
          { client->addr, client->flags, sizeof(reg_addr), reg_addr },
          { client->addr, client->flags | I2C_M_RD, len, buf }
         };
         int ret;
         BUG_ON(len == 0);
         BUG_ON(reg > ISL12020M_REG_GPM2);
         BUG_ON(reg + len > ISL12020M_REG_GPM2 + 1);
         ret = i2c_transfer(client->adapter, msgs, 2);
         if (ret > 0)
          ret = 0;
         return ret;
        }
        /* block write */
        static int
        isl12020m_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
                 unsigned len)
        {
         u8 i2c_buf[ISL12020M_REG_GPM2 + 2];
         struct i2c_msg msgs[1] = {
          { client->addr, client->flags, len + 1, i2c_buf }
         };
         int ret;
         BUG_ON(len == 0);
         BUG_ON(reg > ISL12020M_REG_GPM2);
         BUG_ON(reg + len > ISL12020M_REG_GPM2 + 1);
         i2c_buf[0] = reg;
         memcpy(&i2c_buf[1], &buf[0], len);
         ret = i2c_transfer(client->adapter, msgs, 1);
         if (ret > 0)
          ret = 0;
         return ret;
        }
        /* simple check to see wether we have a isl12020m */
        static int isl12020m_i2c_validate_client(struct i2c_client *client)
        {
         u8 regs[ISL12020M_RTC_SECTION_LEN] = { 0, };
         u8 zero_mask[ISL12020M_RTC_SECTION_LEN] = {
          0x80, 0x80, 0x40, 0xc0, 0xe0, 0x00, 0xf8 //1000 = 8
         };
         int i;
         int ret;
         ret = isl12020m_i2c_read_regs(client, 0, regs, ISL12020M_RTC_SECTION_LEN);
         if (ret < 0)
          return ret;
         for (i = 0; i < ISL12020M_RTC_SECTION_LEN; ++i) {
          if (regs[i] & zero_mask[i]) /* check if bits are cleared */
           return -ENODEV;
         }
         return 0;
        }
        static int isl12020m_i2c_get_sr(struct i2c_client *client)
        {
         return i2c_smbus_read_byte_data(client, ISL12020M_REG_SR) == -1 ? -EIO:0;
        }
        static int isl12020m_i2c_get_fatr(struct i2c_client *client)
        {
         int fatr = i2c_smbus_read_byte_data(client, ISL12020M_REG_FATR);
         if (fatr < 0)
          return -EIO;
         /* The 6bit value in the ATR register controls the load
          * capacitance C_load * in steps of 0.25pF
          *
          * bit (1<<5) of the ATR register is inverted
          *
          * C_load(ATR=0x20) = 4.50pF
          * C_load(ATR=0x00) = 12.50pF
          * C_load(ATR=0x1f) = 20.25pF
          *
          */
         fatr &= 0x3f; /* mask out lsb */
         fatr ^= 1<<5; /* invert 6th bit */
         fatr += 2*9; /* add offset of 4.5pF; unit[atr] = 0.25pF */
         return fatr;
        }
        static int isl12020m_i2c_get_fdtr(struct i2c_client *client)
        {
         int fdtr = i2c_smbus_read_byte_data(client, ISL12020M_REG_FDTR);
         if (fdtr < 0)
          return -EIO;
         /* dtr encodes adjustments of {-60,-40,-20,0,20,40,60} ppm */
         fdtr = ((fdtr & 0x3) * 20) * (fdtr & (1<<2) ? -1 : 1);
         return fdtr;
        }
        static int isl12020m_i2c_get_gpm(struct i2c_client *client)
        {
         u8 buf[ISL12020M_GPM_SECTION_LEN] = { 0, };
         int ret;
         ret = isl12020m_i2c_read_regs (client, ISL12020M_REG_GPM1, buf,
               ISL12020M_GPM_SECTION_LEN);
         if (ret < 0)
          return ret;
         return (buf[1] << 8) | buf[0];
        }
        static int isl12020m_i2c_set_gpm(struct i2c_client *client, u16 usr)
        {
         u8 buf[ISL12020M_GPM_SECTION_LEN];
         buf[0] = usr & 0xff;
         buf[1] = (usr >> 8) & 0xff;
         return isl12020m_i2c_set_regs (client, ISL12020M_REG_GPM1, buf,
                 ISL12020M_GPM_SECTION_LEN);
        }
        static int isl12020m_rtc_proc(struct device *dev, struct seq_file *seq)
        {
         struct i2c_client *const client = to_i2c_client(dev);
         int sr, fdtr, fatr, usr;
         sr = isl12020m_i2c_get_sr(client);
         if (sr < 0) {
          dev_err(&client->dev, "%s: reading SR failed\n", __func__);
          return sr;
         }
         seq_printf(seq, "status_reg\t:%s%s (0x%.2x)\n", //%s%s%s%s get out
             (sr & ISL12020M_REG_SR_RTCF) ? " RTCF" : "",
        // (sr & ISL12020M_REG_SR_BAT) ? " BAT" : "",
             (sr & ISL12020M_REG_SR_ALM) ? " ALM" : "",
        // (sr & ISL12020M_REG_SR_WRTC) ? " WRTC" : "",
        // (sr & ISL12020M_REG_SR_XTOSCB) ? " XTOSCB" : "",
        // (sr & ISL12020M_REG_SR_ARST) ? " ARST" : "",
             sr);
         seq_printf(seq, "batt_status\t: %s\n",
             (sr & ISL12020M_REG_SR_RTCF) ? "bad" : "okay");
         fdtr = isl12020m_i2c_get_fdtr(client);
         if (fdtr >= 0 -1)
          seq_printf(seq, "digital_trim\t: %d ppm\n", fdtr);
         fatr = isl12020m_i2c_get_fatr(client);
         if (fatr >= 0)
          seq_printf(seq, "analog_trim\t: %d.%.2d pF\n",
              fatr>>2, (fatr&0x3)*25);
         usr = isl12020m_i2c_get_gpm(client);
         if (usr >= 0)
          seq_printf(seq, "user_data\t: 0x%.4x\n", usr);
         return 0;
        }
        static int isl12020m_i2c_read_time(struct i2c_client *client,
             struct rtc_time *tm)
        {
         int sr;
         u8 regs[ISL12020M_RTC_SECTION_LEN] = { 0, };
         sr = isl12020m_i2c_get_sr(client);
         if (sr < 0) {
          dev_err(&client->dev, "%s: reading SR failed\n", __func__);
          return -EIO;
         }
         sr = isl12020m_i2c_read_regs(client, 0, regs, ISL12020M_RTC_SECTION_LEN);
         if (sr < 0) {
          dev_err(&client->dev, "%s: reading RTC section failed\n",
           __func__);
          return sr;
         }
         tm->tm_sec = BCD2BIN(regs[ISL12020M_REG_SC]);
         tm->tm_min = BCD2BIN(regs[ISL12020M_REG_MN]);
         { /* HR field has a more complex interpretation */
          const u8 _hr = regs[ISL12020M_REG_HR];
          if (_hr & ISL12020M_REG_HR_MIL) /* 24h format */
           tm->tm_hour = BCD2BIN(_hr & 0x3f);
          else { // 12h format
           tm->tm_hour = BCD2BIN(_hr & 0x1f);
           if (_hr & ISL12020M_REG_HR_PM) /* PM flag set */
            tm->tm_hour += 12;
          }
         }
         tm->tm_mday = BCD2BIN(regs[ISL12020M_REG_DT]);
         tm->tm_mon = BCD2BIN(regs[ISL12020M_REG_MO]) - 1; /* rtc starts at 1 */
         tm->tm_year = BCD2BIN(regs[ISL12020M_REG_YR]) + 100;
         tm->tm_wday = BCD2BIN(regs[ISL12020M_REG_DW]);
         return 0;
        }
        static int isl12020m_i2c_read_alarm(struct i2c_client *client,
              struct rtc_wkalrm *alarm)
        {
         struct rtc_time *const tm = &alarm->time;
         u8 regs[ISL12020M_ALARM_SECTION_LEN] = { 0, };
         int sr;
         sr = isl12020m_i2c_get_sr(client);
         if (sr < 0) {
          dev_err(&client->dev, "%s: reading SR failed\n", __func__);
          return sr;
         }
         sr = isl12020m_i2c_read_regs(client, ISL12020M_REG_SCA0, regs,
              ISL12020M_ALARM_SECTION_LEN);
         if (sr < 0) {
          dev_err(&client->dev, "%s: reading alarm section failed\n",
           __func__);
          return sr;
         }
         /* MSB of each alarm register is an enable bit */
         tm->tm_sec = BCD2BIN(regs[ISL12020M_REG_SCA0-ISL12020M_REG_SCA0] & 0x7f);
         tm->tm_min = BCD2BIN(regs[ISL12020M_REG_MNA0-ISL12020M_REG_SCA0] & 0x7f);
         tm->tm_hour = BCD2BIN(regs[ISL12020M_REG_HRA0-ISL12020M_REG_SCA0] & 0x3f);
         tm->tm_mday = BCD2BIN(regs[ISL12020M_REG_DTA0-ISL12020M_REG_SCA0] & 0x3f);
         tm->tm_mon = BCD2BIN(regs[ISL12020M_REG_MOA0-ISL12020M_REG_SCA0] & 0x1f)-1;
         tm->tm_wday = BCD2BIN(regs[ISL12020M_REG_DWA0-ISL12020M_REG_SCA0] & 0x03);
         return 0;
        }
        static int isl12020m_rtc_read_time(struct device *dev, struct rtc_time *tm)
        {
         return isl12020m_i2c_read_time(to_i2c_client(dev), tm);
        }
        static int isl12020m_i2c_set_time(struct i2c_client *client,
            struct rtc_time const *tm)
        {
         int sr;
         u8 regs[ISL12020M_RTC_SECTION_LEN] = { 0, };
         regs[ISL12020M_REG_SC] = BIN2BCD(tm->tm_sec);
         regs[ISL12020M_REG_MN] = BIN2BCD(tm->tm_min);
         regs[ISL12020M_REG_HR] = BIN2BCD(tm->tm_hour) | ISL12020M_REG_HR_MIL;
         regs[ISL12020M_REG_DT] = BIN2BCD(tm->tm_mday);
         regs[ISL12020M_REG_MO] = BIN2BCD(tm->tm_mon + 1);
         regs[ISL12020M_REG_YR] = BIN2BCD(tm->tm_year - 100);
         regs[ISL12020M_REG_DW] = BIN2BCD(tm->tm_wday & 7);
         sr = isl12020m_i2c_get_sr(client);
         if (sr < 0) {
          dev_err(&client->dev, "%s: reading SR failed\n", __func__);
          return sr;
         }
         /* set WRTC */
         sr = i2c_smbus_write_byte_data (client, ISL12020M_REG_SR,
                   sr | ISL12020M_REG_INT_WRTC);
         if (sr < 0) {
          dev_err(&client->dev, "%s: writing SR failed\n", __func__);
          return sr;
         }
         /* write RTC registers */
         sr = isl12020m_i2c_set_regs(client, 0, regs, ISL12020M_RTC_SECTION_LEN);
         if (sr < 0) {
          dev_err(&client->dev, "%s: writing RTC section failed\n",
           __func__);
          return sr;
         }
         /* clear WRTC again */
         sr = i2c_smbus_write_byte_data (client, ISL12020M_REG_SR,
                   sr & ~ISL12020M_REG_INT_WRTC);
         if (sr < 0) {
          dev_err(&client->dev, "%s: writing SR failed\n", __func__);
          return sr;
         }
         return 0;
        }
        static int isl12020m_rtc_set_time(struct device *dev, struct rtc_time *tm)
        {
         return isl12020m_i2c_set_time(to_i2c_client(dev), tm);
        }
        static int isl12020m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
        {
         return isl12020m_i2c_read_alarm(to_i2c_client(dev), alarm);
        }
        static const struct rtc_class_ops isl12020m_rtc_ops = {
         .proc = isl12020m_rtc_proc,
         .read_time = isl12020m_rtc_read_time,
         .set_time = isl12020m_rtc_set_time,
         .read_alarm = isl12020m_rtc_read_alarm,
         //.set_alarm = isl1208_rtc_set_alarm,
        };
        /* sysfs interface */
        static ssize_t isl12020m_sysfs_show_atrim(struct device *dev,
             struct device_attribute *attr,
             char *buf)
        {
         int fatr;
         fatr = isl12020m_i2c_get_fatr(to_i2c_client(dev));
         if (fatr < 0)
          return fatr;
         return sprintf(buf, "%d.%.2d pF\n", fatr>>2, (fatr&0x3)*25);
        }
        static DEVICE_ATTR(atrim, S_IRUGO, isl12020m_sysfs_show_atrim, NULL);
        static ssize_t isl12020m_sysfs_show_dtrim(struct device *dev,
             struct device_attribute *attr,
             char *buf)
        {
         int fdtr;
         fdtr = isl12020m_i2c_get_fdtr(to_i2c_client(dev));
         if (fdtr < 0)
          return fdtr;
         return sprintf(buf, "%d ppm\n", fdtr);
        }
        static DEVICE_ATTR(dtrim, S_IRUGO, isl12020m_sysfs_show_dtrim, NULL);
        static ssize_t isl12020m_sysfs_show_usr(struct device *dev,
                   struct device_attribute *attr,
                   char *buf)
        {
         int usr;
         usr = isl12020m_i2c_get_gpm(to_i2c_client(dev));
         if (usr < 0)
          return usr;
         return sprintf(buf, "0x%.4x\n", usr);
        }
        static ssize_t isl12020m_sysfs_store_usr(struct device *dev,
                   struct device_attribute *attr,
                   const char *buf, size_t count)
        {
         int usr = -1;
         if (buf[0] == '0' && (buf[1] == 'x' || buf[1] == 'X')) {
          if (sscanf(buf, "%x", &usr) != 1)
           return -EINVAL;
         } else {
          if (sscanf(buf, "%d", &usr) != 1)
           return -EINVAL;
         }
         if (usr < 0 || usr > 0xffff)
          return -EINVAL;
         return isl12020m_i2c_set_gpm(to_i2c_client(dev), usr) ? -EIO : count;
        }
        static DEVICE_ATTR(usr, S_IRUGO | S_IWUSR, isl12020m_sysfs_show_usr,
             isl12020m_sysfs_store_usr);
        static int
        isl12020m_probe(struct i2c_adapter *adapter, int addr, int kind)
        {
         int rc = 0;
         struct i2c_client *new_client = NULL;
         struct rtc_device *rtc = NULL;
         if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
          rc = -ENODEV;
          goto failout;
         }
         new_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
         if (new_client == NULL) {
          rc = -ENOMEM;
          goto failout;
         }
         new_client->addr = addr;
         new_client->adapter = adapter;
         new_client->driver = &isl12020m_driver;
         new_client->flags = 0;
         strcpy(new_client->name, DRV_NAME);
         if (kind < 0) {
          rc = isl12020m_i2c_validate_client(new_client);
          if (rc < 0)
           goto failout;
         }
         rc = i2c_attach_client(new_client);
         if (rc < 0)
          goto failout;
         dev_info(&new_client->dev,
           "chip found, driver version " DRV_VERSION "\n");
         rtc = rtc_device_register(isl12020m_driver.driver.name,
              &new_client->dev,
              &isl12020m_rtc_ops, THIS_MODULE);
         if (IS_ERR(rtc)) {
          rc = PTR_ERR(rtc);
          goto failout_detach;
         }
         i2c_set_clientdata(new_client, rtc);
         rc = isl12020m_i2c_get_sr(new_client);
         if (rc < 0) {
          dev_err(&new_client->dev, "reading status failed\n");
          goto failout_unregister;
         }
         if (rc & ISL12020M_REG_SR_RTCF)
          dev_warn(&new_client->dev, "rtc power failure detected, "
            "please set clock.\n");
         rc = device_create_file(&new_client->dev, &dev_attr_atrim);
         if (rc < 0)
          goto failout_unregister;
         rc = device_create_file(&new_client->dev, &dev_attr_dtrim);
         if (rc < 0)
          goto failout_atrim;
         rc = device_create_file(&new_client->dev, &dev_attr_usr);
         if (rc < 0)
          goto failout_dtrim;
         return 0;
         failout_dtrim:
         device_remove_file(&new_client->dev, &dev_attr_dtrim);
         failout_atrim:
         device_remove_file(&new_client->dev, &dev_attr_atrim);
         failout_unregister:
         rtc_device_unregister(rtc);
         failout_detach:
         i2c_detach_client(new_client);
         failout:
         kfree(new_client);
         return rc;
        }
        static int
        isl12020m_attach_adapter (struct i2c_adapter *adapter)
        {
         return i2c_probe(adapter, &addr_data, isl12020m_probe);
        }
        static int
        isl12020m_detach_client(struct i2c_client *client)
        {
         int rc;
         struct rtc_device *const rtc = i2c_get_clientdata(client);
         if (rtc)
          rtc_device_unregister(rtc); /* do we need to kfree? */
         rc = i2c_detach_client(client);
         if (rc)
          return rc;
         kfree(client);
         return 0;
        }
        /* module management */
        static int __init isl12020m_init(void)
        {
         return i2c_add_driver(&isl12020m_driver);
        }
        static void __exit isl12020m_exit(void)
        {
         i2c_del_driver(&isl12020m_driver);
        }
        MODULE_AUTHOR("Herbert Valerio Riedel <hvr@gnu.org>");
        MODULE_DESCRIPTION("Intersil ISL12020M RTC driver");
        MODULE_LICENSE("GPL");
        MODULE_VERSION(DRV_VERSION);
        module_init(isl12020m_init);
        module_exit(isl12020m_exit);



ISL1208时钟芯片初始化 1. 寄存器描述 Status Register (SR) The Status Register is located in the memory map at address 07h. This is a volatile register that provides either control or status of RTC failure, battery mode, alarm trigger, write protection of clock counter, crystal oscil 阅读详情

相关推荐

tsc2007驱动

tsc2007是个多功能电阻触摸屏, 具有12bit精度的电阻屏A/D装换器, 压力传感器, 温度传感器等功能. 根据不同的触摸屏尺寸,可以支持8bit和12bit精度的转换. 支持I2C接口, 一个中断输出引脚, 中断输出低电平. 内部结构框图如下: 1.  tsc2007 结构体定义: struct tsc2007 { struct input_de

2219

应用层, i2c-dev.c,和i2c-core.c的交互

i2c 应用层与驱动层沟通的结构体就是下面这个, 定义在i2c-dev.c中: static const struct file_operations i2cdev_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .read = i2c

1064

用示波器量I2C 信号

I2C client 挂到 adapter之后,就可以通过I2C 读写命令开始 读写设备寄存器了。   读写的时候,都可以用示波器量出来I2C CLK 和I2C data信号的,甚至可以读出 data信号上的,传输的设备地址和数据。   有趣的是,开始的时候,把示波器信号周期调的比较大,比如500ms,这时候,测量音频Codec I2C总线上信号,居然量不到信号,而点触摸屏的时候就可以测到

1953

i2c-core.c

/drivers/i2c/i2c-core.c I2C核心提供了一组不依赖于硬件平台的接口函数,这个文件一般不需要工程师修改。 I2C总线驱动和设备驱动之间,依赖I2C核心作为纽带。 I2C核心主要函数如下: 1. 增加删除i2c_adapter: /** * i2c_add_adapter - declare i2c adapter, use dynamic bus

875

AIC3104_音频驱动

这两周一直在调AIC3104的驱动,这是个音频codec芯片,可以实现语音对讲功能。 AIC3104是通过I2C方式与CPU通信,来设置寄存器,另外是IIS接口进行语音的Mic_in和Line_out功能。   下面是aic3104的驱动源代码: /* extdrv/peripheral/vda/adv7179.c * * * Copyright (c) 2006 Hisilic

1891

通过 bitbang GPIO来实现i2c总线协议

i2c总线可以通过bitbang两个gpio口来实现, bitbang就是位拉高拉低的意思,英文手册中经常出现的一个词。 drivers/i2c/algos/i2c-algo-bit.c, 就是这个i2c的algos程序,通过bitbang SCL 和SDA两个引脚,来实现I2C总线协议。 1. 实现bitbang,  有两个最基本的操作,一个是设置GPIO的输出(高或者低),另一个就是读取G

1349

pmic芯片lp3925驱动_i2c接口

1. init/exit static int __init lp3925_init(void) { int ret = 0; ret = i2c_add_driver(&lp3925_driver); //添加lp3925 i2c驱动. if (ret) { printk(KERN_WARNING "l

802

i2c_add_adapter

drivers/i2c/algos/i2c-algo-bit.c 中有两个函数都是用来添加adapter的, 一个是动态添加i2c_add_adapter(), 一个是静态添加i2c_add_numbered_adapter(),   numbered就是已经定好了adapter id号了的意思。 int i2c_bit_add_bus(struct i2c_adapter *ad

1120

medfield 平台 lvds bridge 驱动

lvds bridge, 应该是一个I2C接口控制的,采用lvds数据接口,液晶屏驱动器桥。 这也是个I2C 驱动,挂接在 I2C_2 总线上。 1. 初始化如下: /* ************************************************************************* *\ * FUNCTION: dsi_lvd

792

eeprom_AT24C256_I2C驱动

AT24C256 是256Kbit大小的eeprom,掉电仍可保留数据。本驱动实现了通过I2C总线对AT24C256的读写操作。 #include #include #include #include MODULE_LICENSE("Dual BSD/GPL"); #include "sti7105.h" #include "stsys.h" #include "stddefs.h"

755

国央企创新负责人如何通过平台实现科研成果的快速识别与转化?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

linux中I2C体系结构及4个核心数据结构

一、linux的I2C驱动体系结构分为4部分 1. i2c-core: I2C核心,即i2c_core.c 。提供了I2C总线驱动和设备驱动的注册和注销方法,I2C通信algorithm上层的、与具体适配器无关的代码,以及探测设备、检测设备地址的上层代码等。 2. i2c-algorythm: 里面有I2C的通信方法(即algotithm),位于linux内核源代码driver

760

PotPlayer自用皮肤

自用 PotPlayer 皮肤,仅微调了字体大小与颜色,是按个人习惯调整,未做适配性调整。

Medfield 平台 I2C 驱动配置

medfield 平台中,i2c总线,通过pci总线来配置。 代码位于: /drivers/i2c/busses/i2c-designware-pcidrv.c 中 1. 首先是pci 设备表: static struct dw_pci_controller dw_pci_controllers[] = { [moorestown_0] = {

749

2-shell及常用命令-续.pdf

2-shell及常用命令-续.pdf

前端埋点的实践

1、前言 开始正文前先介绍一下埋点的概念~,(熟悉的朋友可以略过) 前端埋点: 是一种手段,它的目的是上报相关行为数据,相关人员以数据为依据来分析产品在用户端的使用情况,根据分析出来的结果辅助产品优化、迭代。 BI:商业智能,公司内部做数据分析相关的部门。 2、背景 在流量红利逐渐消失的现在,数据的采集、分析和精细化的运营显得更加重要,所以埋点的需求在互联网产品中是很常见的,目的上面也提到了。我们的追求就是又快又好的做好埋点工作,但是现实却不那么美好;目前我们团队在前端埋点方面存在一些痛点: 在构造埋点字段

Arui_0的博客 1772

I2C驱动程序设计

linux中,I2C软件体系结构分为3个部分:   1.I2C核心。   即i2c_core.c 。 里面有I2C的通信方法(即algotithm),位于linux内核源代码/drivers/i2c/目录中。   2.I2C总线驱动。   各主芯片,具有I2C通信功能的CPU,都会有相应的一套I2C总线驱动程序。 如i2c_s3c2410.c,i2c_ambarella.c等

525

贝塞尔曲线原理--曲线生成--路径规划--matlab代码

贝塞尔曲线有着很多特殊的性质, 在图形设计和路径规划中应用都非常广泛, 在路径规划中贝塞尔曲线完全由其控制点决定其形状, n个控制点对应着n-1阶的贝塞尔曲线,并且可以通过递归的方式来绘制.

bob595078694的博客 1万+

i2c协议

The I2C protocol. A device that sends data onto the bus is defined as a transmitter and a device receiving data is a receiver. The device that controls the message is called a master. The devices

502

Nangate 45nm FreePDK开源工艺库:从RTL到GDSII全流程实战

在数字IC设计中,标准单元库是连接逻辑综合与物理实现的基石,它定义了每个单元的逻辑功能、时序延迟与物理尺寸。开源EDA工具链的成熟,使得个人也能借助免费工艺套件完整跑通芯片设计流程。Nangate 45nm FreePDK作为一套经典的开源工艺库,凭借结构清晰、配套完善的特性,成为学习数字后端和时序收敛的理想训练场。从综合工具Yosys读取Liberty文件进行逻辑映射,到OpenROAD执行布局布线与时钟树综合,再到使用OpenSTA分析关键路径延迟,这套流程涵盖了数字设计最核心的环节。通过亲手操作,开发

weixin_29168393的博客 271

华三模拟器实战:3分钟搞定路由器DHCP地址池配置(附常见错误排查)

本文提供华三模拟器中路由器DHCP地址池的实战配置指南。通过分步详解,帮助用户在3分钟内完成基础设置,并深入讲解多地址池、中继配置等进阶应用。文章重点剖析了DHCP服务无法工作的常见原因,提供从客户端到服务器的系统性排错方法,助力快速定位并解决地址分配失败、获取参数错误等典型问题。

w1x2y3的博客 360
上一篇: I2C驱动程序设计
下一篇: wl12xx spi 接口
lamdoc
博客等级 码龄18年 155粉丝 655原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值