static void adau1781_spi_switch_mode(struct device *dev) { struct spi_device *spi = to_spi_device(dev); /* * To get the device into SPI mode CLATCH has to be pulled low three * times. Do this by issuing three dummy reads. */ spi_w8r8(spi, 0x00); spi_w8r8(spi, 0x00); spi_w8r8(spi, 0x00); }
static unsigned char rtc_read (unsigned char reg) { int ret; ret = spi_w8r8(slave, reg); return ret < 0 ? 0 : ret; }
/* * Return the status of the DataFlash device. */ static inline int dataflash_status(struct spi_device *spi) { /* NOTE: at45db321c over 25 MHz wants to write * a dummy byte after the opcode... */ return spi_w8r8(spi, OP_READ_STATUS); }
static int sx151x_spi_read(int chip, unsigned char reg) { struct spi_slave *slave; int ret; slave = spi_setup_slave(CONFIG_SX151X_SPI_BUS, chip, 1000000, SPI_MODE_0); if (!slave) return 0; spi_claim_bus(slave); ret = spi_w8r8(slave, reg | 0x80); if (ret < 0) printf("spi%d.%d read fail: can't read %02x: %d\n", CONFIG_SX151X_SPI_BUS, chip, reg, ret); else printf("spi%d.%d read register 0x%02x: 0x%02x\n", CONFIG_SX151X_SPI_BUS, chip, reg, ret); spi_release_bus(slave); spi_free_slave(slave); return ret; }
static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro) { int ret, i; struct kxsd9_state *st = iio_priv(indio_dev); bool foundit = false; for (i = 0; i < 4; i++) if (micro == kxsd9_micro_scales[i]) { foundit = true; break; } if (!foundit) return -EINVAL; mutex_lock(&st->buf_lock); ret = spi_w8r8(st->us, KXSD9_READ(KXSD9_REG_CTRL_C)); if (ret) goto error_ret; st->tx[0] = KXSD9_WRITE(KXSD9_REG_CTRL_C); st->tx[1] = (ret & ~KXSD9_FS_MASK) | i; ret = spi_write(st->us, st->tx, 2); error_ret: mutex_unlock(&st->buf_lock); return ret; }
static int adxl34x_spi_read(struct spi_device *spi, unsigned char reg) { unsigned char cmd; cmd = ADXL34X_READCMD(reg); return spi_w8r8(spi, cmd); }
static int lis3_spi_read(struct lis3lv02d *lis3, int reg, u8 *v) { struct spi_device *spi = lis3->bus_priv; int ret = spi_w8r8(spi, reg | LIS3_SPI_READ); if (ret < 0) return -EINVAL; *v = (u8) ret; return 0; }
static int m41t94_read_time(struct device *dev, struct rtc_time *tm) { struct spi_device *spi = to_spi_device(dev); u8 buf[2]; int ret, hour; /* clear halt update bit */ ret = spi_w8r8(spi, M41T94_REG_HT); if (ret < 0) return ret; if (ret & M41T94_BIT_HALT) { buf[0] = 0x80 | M41T94_REG_HT; buf[1] = ret & ~M41T94_BIT_HALT; spi_write(spi, buf, 2); } /* clear stop bit */ ret = spi_w8r8(spi, M41T94_REG_SECONDS); if (ret < 0) return ret; if (ret & M41T94_BIT_STOP) { buf[0] = 0x80 | M41T94_REG_SECONDS; buf[1] = ret & ~M41T94_BIT_STOP; spi_write(spi, buf, 2); } tm->tm_sec = bcd2bin(spi_w8r8(spi, M41T94_REG_SECONDS)); tm->tm_min = bcd2bin(spi_w8r8(spi, M41T94_REG_MINUTES)); hour = spi_w8r8(spi, M41T94_REG_HOURS); tm->tm_hour = bcd2bin(hour & 0x3f); tm->tm_wday = bcd2bin(spi_w8r8(spi, M41T94_REG_WDAY)) - 1; tm->tm_mday = bcd2bin(spi_w8r8(spi, M41T94_REG_DAY)); tm->tm_mon = bcd2bin(spi_w8r8(spi, M41T94_REG_MONTH)) - 1; tm->tm_year = bcd2bin(spi_w8r8(spi, M41T94_REG_YEAR)); if ((hour & M41T94_BIT_CB) || !(hour & M41T94_BIT_CEB)) tm->tm_year += 100; dev_dbg(dev, "%s secs=%d, mins=%d, " "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", "read", tm->tm_sec, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); /* initial clock setting can be undefined */ return rtc_valid_tm(tm); }
static int as3935_read(struct as3935_state *st, unsigned int reg, int *val) { u8 cmd; int ret; cmd = (AS3935_READ_DATA | AS3935_ADDRESS(reg)) >> 8; ret = spi_w8r8(st->spi, cmd); if (ret < 0) return ret; *val = ret; return 0; }
static int ak4104_fill_cache(struct snd_soc_codec *codec) { int i; u8 *reg_cache = codec->reg_cache; struct spi_device *spi = codec->control_data; for (i = 0; i < codec->driver->reg_cache_size; i++) { int ret = spi_w8r8(spi, i | AK4104_READ); if (ret < 0) { dev_err(&spi->dev, "SPI write failure\n"); return ret; } reg_cache[i] = ret; } return 0; }
static int ade7754_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7754_state *st = iio_priv(indio_dev); int ret; ret = spi_w8r8(st->us, ADE7754_READ_REG(reg_address)); if (ret < 0) { dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X", reg_address); return ret; } *val = ret; return 0; }
u8 rf69_read_reg(struct spi_device *spi, u8 addr) { int retval; retval = spi_w8r8(spi, addr); #ifdef DEBUG_VALUES if (retval < 0) /* should never happen, since we already checked, * that module is connected. Therefore no error * handling, just an optional error message... */ dev_dbg(&spi->dev, "read 0x%x FAILED\n", addr); else dev_dbg(&spi->dev, "read 0x%x from reg 0x%x\n", retval, addr); #endif return retval; }
static int __devinit m41t94_probe(struct spi_device *spi) { struct rtc_device *rtc; int res; spi->bits_per_word = 8; spi_setup(spi); res = spi_w8r8(spi, M41T94_REG_SECONDS); if (res < 0) { dev_err(&spi->dev, "not found.\n"); return res; } rtc = rtc_device_register(m41t94_driver.driver.name, &spi->dev, &m41t94_rtc_ops, THIS_MODULE); if (IS_ERR(rtc)) return PTR_ERR(rtc); dev_set_drvdata(&spi->dev, rtc); return 0; }
/* When we cat /sys/bus/spi/devices/spi0.0/looptest this will be triggered */ static ssize_t dummy_looptest(struct device *dev, struct device_attribute *attr, char *buf) { struct spi_device *spi = to_spi_device(dev); struct dummy *p_dummy = dev_get_drvdata(&spi->dev); /* * WARNING! Do not dereference the chip-specific data in any normal * driver for a chip. It is usually STATIC and shall not be read * or written to. Your chip driver should NOT depend on fields in this * struct, this is just used here to alter the behaviour of the chip * in order to perform tests. */ struct pl022_config_chip *chip_info = spi->controller_data; int status; u8 txbuf[14] = {0xDE, 0xAD, 0xBE, 0xEF, 0x2B, 0xAD, 0xCA, 0xFE, 0xBA, 0xBE, 0xB1, 0x05, 0xF0, 0x0D}; u8 rxbuf[14]; u8 *bigtxbuf_virtual; u8 *bigrxbuf_virtual; if (mutex_lock_interruptible(&p_dummy->lock)) return -ERESTARTSYS; bigtxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL); if (bigtxbuf_virtual == NULL) { status = -ENOMEM; goto out; } bigrxbuf_virtual = kmalloc(DMA_TEST_SIZE, GFP_KERNEL); /* Fill TXBUF with some happy pattern */ memset(bigtxbuf_virtual, 0xAA, DMA_TEST_SIZE); /* * Force chip to 8 bit mode * WARNING: NEVER DO THIS IN REAL DRIVER CODE, THIS SHOULD BE STATIC! */ chip_info->data_size = SSP_DATA_BITS_8; /* You should NOT DO THIS EITHER */ spi->master->setup(spi); /* Now run the tests for 8bit mode */ pr_info("Simple test 1: write 0xAA byte, read back garbage byte " "in 8bit mode\n"); status = spi_w8r8(spi, 0xAA); if (status < 0) pr_warning("Siple test 1: FAILURE: spi_write_then_read " "failed with status %d\n", status); else pr_info("Simple test 1: SUCCESS!\n"); pr_info("Simple test 2: write 8 bytes, read back 8 bytes garbage " "in 8bit mode (full FIFO)\n"); status = spi_write_then_read(spi, &txbuf[0], 8, &rxbuf[0], 8); if (status < 0) pr_warning("Simple test 2: FAILURE: spi_write_then_read() " "failed with status %d\n", status); else pr_info("Simple test 2: SUCCESS!\n"); pr_info("Simple test 3: write 14 bytes, read back 14 bytes garbage " "in 8bit mode (see if we overflow FIFO)\n"); status = spi_write_then_read(spi, &txbuf[0], 14, &rxbuf[0], 14); if (status < 0) pr_warning("Simple test 3: FAILURE: failed with status %d " "(probably FIFO overrun)\n", status); else pr_info("Simple test 3: SUCCESS!\n"); pr_info("Simple test 4: write 8 bytes with spi_write(), read 8 " "bytes garbage with spi_read() in 8bit mode\n"); status = spi_write(spi, &txbuf[0], 8); if (status < 0) pr_warning("Simple test 4 step 1: FAILURE: spi_write() " "failed with status %d\n", status); else pr_info("Simple test 4 step 1: SUCCESS!\n"); status = spi_read(spi, &rxbuf[0], 8); if (status < 0) pr_warning("Simple test 4 step 2: FAILURE: spi_read() " "failed with status %d\n", status); else pr_info("Simple test 4 step 2: SUCCESS!\n"); pr_info("Simple test 5: write 14 bytes with spi_write(), read " "14 bytes garbage with spi_read() in 8bit mode\n"); status = spi_write(spi, &txbuf[0], 14); if (status < 0) pr_warning("Simple test 5 step 1: FAILURE: spi_write() " "failed with status %d (probably FIFO overrun)\n", status); else pr_info("Simple test 5 step 1: SUCCESS!\n"); status = spi_read(spi, &rxbuf[0], 14); if (status < 0) pr_warning("Simple test 5 step 2: FAILURE: spi_read() " "failed with status %d (probably FIFO overrun)\n", status); else pr_info("Simple test 5: SUCCESS!\n"); pr_info("Simple test 6: write %d bytes with spi_write(), " "read %d bytes garbage with spi_read() in 8bit mode\n", DMA_TEST_SIZE, DMA_TEST_SIZE); status = spi_write(spi, &bigtxbuf_virtual[0], DMA_TEST_SIZE); if (status < 0) pr_warning("Simple test 6 step 1: FAILURE: spi_write() " "failed with status %d (probably FIFO overrun)\n", status); else pr_info("Simple test 6 step 1: SUCCESS!\n"); status = spi_read(spi, &bigrxbuf_virtual[0], DMA_TEST_SIZE); if (status < 0) pr_warning("Simple test 6 step 2: FAILURE: spi_read() " "failed with status %d (probably FIFO overrun)\n", status); else pr_info("Simple test 6: SUCCESS!\n"); /* * Force chip to 16 bit mode * WARNING: NEVER DO THIS IN REAL DRIVER CODE, THIS SHOULD BE STATIC! */ chip_info->data_size = SSP_DATA_BITS_16; /* You should NOT DO THIS EITHER */ spi->master->setup(spi); pr_info("Simple test 7: write 0xAA byte, read back garbage byte " "in 16bit bus mode\n"); status = spi_w8r8(spi, 0xAA); if (status == -EIO) pr_info("Simple test 7: SUCCESS! (expected failure with " "status EIO)\n"); else if (status < 0) pr_warning("Siple test 7: FAILURE: spi_write_then_read " "failed with status %d\n", status); else pr_warning("Siple test 7: FAILURE: spi_write_then_read " "succeeded but it was expected to fail!\n"); pr_info("Simple test 8: write 8 bytes, read back 8 bytes garbage " "in 16bit mode (full FIFO)\n"); status = spi_write_then_read(spi, &txbuf[0], 8, &rxbuf[0], 8); if (status < 0) pr_warning("Simple test 8: FAILURE: spi_write_then_read() " "failed with status %d\n", status); else pr_info("Simple test 8: SUCCESS!\n"); pr_info("Simple test 9: write 14 bytes, read back 14 bytes garbage " "in 16bit mode (see if we overflow FIFO)\n"); status = spi_write_then_read(spi, &txbuf[0], 14, &rxbuf[0], 14); if (status < 0) pr_warning("Simple test 9: FAILURE: failed with status %d " "(probably FIFO overrun)\n", status); else pr_info("Simple test 9: SUCCESS!\n"); pr_info("Simple test 10: write %d bytes with spi_write(), " "read %d bytes garbage with spi_read() in 16bit mode\n", DMA_TEST_SIZE, DMA_TEST_SIZE); status = spi_write(spi, &bigtxbuf_virtual[0], DMA_TEST_SIZE); if (status < 0) pr_warning("Simple test 10 step 1: FAILURE: spi_write() " "failed with status %d (probably FIFO overrun)\n", status); else pr_info("Simple test 10 step 1: SUCCESS!\n"); status = spi_read(spi, &bigrxbuf_virtual[0], DMA_TEST_SIZE); if (status < 0) pr_warning("Simple test 10 step 2: FAILURE: spi_read() " "failed with status %d (probably FIFO overrun)\n", status); else pr_info("Simple test 10: SUCCESS!\n"); status = sprintf(buf, "loop test complete\n"); kfree(bigrxbuf_virtual); kfree(bigtxbuf_virtual); out: mutex_unlock(&p_dummy->lock); return status; }
/** * sc16is7x2_read - Read back register content * @reg: Register offset * @ch: Channel (0 or 1) * * Returns positive 8 bit value from the device if successful or a * negative value on error */ static int sc16is7x2_read(struct sc16is7x2_chip *ts, unsigned reg, unsigned ch) { return spi_w8r8(ts->spi, read_cmd(reg, ch)); }
static int __devinit rs5c348_probe(struct spi_device *spi) { int ret; struct rtc_device *rtc; struct rs5c348_plat_data *pdata; pdata = kzalloc(sizeof(struct rs5c348_plat_data), GFP_KERNEL); if (!pdata) return -ENOMEM; spi->dev.platform_data = pdata; /* Check D7 of SECOND register */ ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_SECS)); if (ret < 0 || (ret & 0x80)) { dev_err(&spi->dev, "not found.\n"); goto kfree_exit; } dev_info(&spi->dev, "chip found, driver version " DRV_VERSION "\n"); dev_info(&spi->dev, "spiclk %u KHz.\n", (spi->max_speed_hz + 500) / 1000); /* turn RTC on if it was not on */ ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL2)); if (ret < 0) goto kfree_exit; if (ret & (RS5C348_BIT_XSTP | RS5C348_BIT_VDET)) { u8 buf[2]; struct rtc_time tm; if (ret & RS5C348_BIT_VDET) dev_warn(&spi->dev, "voltage-low detected.\n"); if (ret & RS5C348_BIT_XSTP) dev_warn(&spi->dev, "oscillator-stop detected.\n"); rtc_time_to_tm(0, &tm); /* 1970/1/1 */ ret = rs5c348_rtc_set_time(&spi->dev, &tm); if (ret < 0) goto kfree_exit; buf[0] = RS5C348_CMD_W(RS5C348_REG_CTL2); buf[1] = 0; ret = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0); if (ret < 0) goto kfree_exit; } ret = spi_w8r8(spi, RS5C348_CMD_R(RS5C348_REG_CTL1)); if (ret < 0) goto kfree_exit; if (ret & RS5C348_BIT_24H) pdata->rtc_24h = 1; rtc = rtc_device_register(rs5c348_driver.driver.name, &spi->dev, &rs5c348_rtc_ops, THIS_MODULE); if (IS_ERR(rtc)) { ret = PTR_ERR(rtc); goto kfree_exit; } pdata->rtc = rtc; return 0; kfree_exit: kfree(pdata); return ret; }
static uint8_t lis_reg_read(struct lis302dl_info *lis, uint8_t reg) { return spi_w8r8(lis->spi, 0xc0 | reg); }
static inline int bma220_read_reg(struct spi_device *spi, u8 reg) { return spi_w8r8(spi, reg | BMA220_READ_MASK); }
static int pi433_probe(struct spi_device *spi) { struct pi433_device *device; int retval; /* setup spi parameters */ spi->mode = 0x00; spi->bits_per_word = 8; /* * spi->max_speed_hz = 10000000; * 1MHz already set by device tree overlay */ retval = spi_setup(spi); if (retval) { dev_dbg(&spi->dev, "configuration of SPI interface failed!\n"); return retval; } dev_dbg(&spi->dev, "spi interface setup: mode 0x%2x, %d bits per word, %dhz max speed", spi->mode, spi->bits_per_word, spi->max_speed_hz); /* Ping the chip by reading the version register */ retval = spi_w8r8(spi, 0x10); if (retval < 0) return retval; switch (retval) { case 0x24: dev_dbg(&spi->dev, "found pi433 (ver. 0x%x)", retval); break; default: dev_dbg(&spi->dev, "unknown chip version: 0x%x", retval); return -ENODEV; } /* Allocate driver data */ device = kzalloc(sizeof(*device), GFP_KERNEL); if (!device) return -ENOMEM; /* Initialize the driver data */ device->spi = spi; device->rx_active = false; device->tx_active = false; device->interrupt_rx_allowed = false; /* init rx buffer */ device->rx_buffer = kmalloc(MAX_MSG_SIZE, GFP_KERNEL); if (!device->rx_buffer) { retval = -ENOMEM; goto RX_failed; } /* init wait queues */ init_waitqueue_head(&device->tx_wait_queue); init_waitqueue_head(&device->rx_wait_queue); init_waitqueue_head(&device->fifo_wait_queue); /* init fifo */ INIT_KFIFO(device->tx_fifo); /* init mutexes and locks */ mutex_init(&device->tx_fifo_lock); mutex_init(&device->rx_lock); /* setup GPIO (including irq_handler) for the different DIOs */ retval = setup_gpio(device); if (retval) { dev_dbg(&spi->dev, "setup of GPIOs failed"); goto GPIO_failed; } /* setup the radio module */ retval = rf69_set_mode(spi, standby); if (retval < 0) goto minor_failed; retval = rf69_set_data_mode(spi, DATAMODUL_MODE_PACKET); if (retval < 0) goto minor_failed; retval = rf69_enable_amplifier(spi, MASK_PALEVEL_PA0); if (retval < 0) goto minor_failed; retval = rf69_disable_amplifier(spi, MASK_PALEVEL_PA1); if (retval < 0) goto minor_failed; retval = rf69_disable_amplifier(spi, MASK_PALEVEL_PA2); if (retval < 0) goto minor_failed; retval = rf69_set_output_power_level(spi, 13); if (retval < 0) goto minor_failed; retval = rf69_set_antenna_impedance(spi, fifty_ohm); if (retval < 0) goto minor_failed; /* determ minor number */ retval = pi433_get_minor(device); if (retval) { dev_dbg(&spi->dev, "get of minor number failed"); goto minor_failed; } /* create device */ device->devt = MKDEV(MAJOR(pi433_dev), device->minor); device->dev = device_create(pi433_class, &spi->dev, device->devt, device, "pi433.%d", device->minor); if (IS_ERR(device->dev)) { pr_err("pi433: device register failed\n"); retval = PTR_ERR(device->dev); goto device_create_failed; } else { dev_dbg(device->dev, "created device for major %d, minor %d\n", MAJOR(pi433_dev), device->minor); } /* start tx thread */ device->tx_task_struct = kthread_run(pi433_tx_thread, device, "pi433.%d_tx_task", device->minor); if (IS_ERR(device->tx_task_struct)) { dev_dbg(device->dev, "start of send thread failed"); retval = PTR_ERR(device->tx_task_struct); goto send_thread_failed; } /* create cdev */ device->cdev = cdev_alloc(); if (!device->cdev) { dev_dbg(device->dev, "allocation of cdev failed"); goto cdev_failed; } device->cdev->owner = THIS_MODULE; cdev_init(device->cdev, &pi433_fops); retval = cdev_add(device->cdev, device->devt, 1); if (retval) { dev_dbg(device->dev, "register of cdev failed"); goto del_cdev; } /* spi setup */ spi_set_drvdata(spi, device); return 0; del_cdev: cdev_del(device->cdev); cdev_failed: kthread_stop(device->tx_task_struct); send_thread_failed: device_destroy(pi433_class, device->devt); device_create_failed: pi433_free_minor(device); minor_failed: free_gpio(device); GPIO_failed: kfree(device->rx_buffer); RX_failed: kfree(device); return retval; }
static int __devinit r2113s_probe(struct spi_device *spi) { int ret=0; struct rtc_device *rtc; struct r2113s_plat_data *pdata=NULL; /* check spi device mode */ if((spi->mode & (SPI_CPHA|SPI_CPOL)) != (SPI_CPHA|SPI_CPOL)){ dev_err(&spi->dev, "mode setting error: NOT mode-2.\n"); ret = -EINVAL; goto kfree_exit; } if(!(spi->mode & SPI_CS_HIGH)){ dev_err(&spi->dev, "mode setting error: chipselect is NOT active high.\n"); ret = -EINVAL; goto kfree_exit; } if(!(spi->mode & SPI_3WIRE)){ dev_err(&spi->dev, "mode setting error: SI/SO signals is NOT shared.\n"); ret = -EINVAL; goto kfree_exit; } if(spi->mode & SPI_LSB_FIRST){ dev_err(&spi->dev, "mode setting error: not MSB first send/recieve.\n"); ret = -EINVAL; goto kfree_exit; } pdata = kzalloc(sizeof(struct r2113s_plat_data), GFP_KERNEL); if (!pdata){ dev_err(&spi->dev, "not enough memory.\n"); ret = -ENOMEM; goto kfree_exit; } spi->dev.platform_data = pdata; /* Check D7 of SECOND register */ ret = spi_w8r8(spi, R2113S_CMD_R(R2113S_REG_SECS)); if (ret < 0 || (ret & 0x80)) { dev_err(&spi->dev, "not found.(%d)\n",ret); goto kfree_exit; } dev_info(&spi->dev, "chip found, driver version " DRV_VERSION "\n"); dev_info(&spi->dev, "spiclk %u KHz.\n", (spi->max_speed_hz + 500) / 1000); /* turn RTC on if it was not on */ ret = spi_w8r8(spi, R2113S_CMD_R(R2113S_REG_CTL2)); if (ret < 0) goto kfree_exit; pdata->pon_stat = ret & (R2113S_BIT_XSTP | R2113S_BIT_VDET | R2113S_BIT_PON); if (pdata->pon_stat) { // u8 buf[2]; // struct rtc_time tm; if (pdata->pon_stat & R2113S_BIT_PON) dev_err(&spi->dev, "voltage-zero detected.\n"); else { if (pdata->pon_stat & R2113S_BIT_VDET) dev_err(&spi->dev, "voltage-low detected.\n"); if (pdata->pon_stat & R2113S_BIT_XSTP) dev_err(&spi->dev, "oscillator-stop detected.\n"); } /* rtc_time_to_tm(0, &tm); /\* 1970/1/1 *\/ */ /* ret = r2113s_rtc_set_time(&spi->dev, &tm); */ /* if (ret < 0) */ /* goto kfree_exit; */ /* buf[0] = R2113S_CMD_W(R2113S_REG_CTL2); */ /* buf[1] = 0; */ /* ret = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0); */ /* if (ret < 0) */ /* goto kfree_exit; */ } ret = spi_w8r8(spi, R2113S_CMD_R(R2113S_REG_CTL1)); if (ret < 0) goto kfree_exit; if (ret & R2113S_BIT_24H) pdata->rtc_24h = 1; rtc = rtc_device_register(r2113s_driver.driver.name, &spi->dev, &r2113s_rtc_ops, THIS_MODULE); if (IS_ERR(rtc)) { ret = PTR_ERR(rtc); goto kfree_exit; } pdata->rtc = rtc; return 0; kfree_exit: if(NULL!=pdata) kfree(pdata); return ret; }