static int s35390a_init(void) { unsigned char reg1 = 0; unsigned int ret = 0; /*Check Frist Start Up*/ ret = s35390a_check_started(®1); if( ret != SP_OK ) { DIAG_ERROR("[%s]External RTC init fail!\n", __FUNCTION__); return ret; } /*Set 12/24 format*/ ret = s35390a_set_12or24_format(1); if( ret != SP_OK ) { DIAG_ERROR("[%s]Set External RTC 12/24 format fail!\n", __FUNCTION__); return ret; } /*Reset External RTC EXT_RTC_ADJ_REG*/ ret = s35390a_set_adjust(0x82 ); /* +1 ppm */ ret = s35390a_clear_alarm_int(); DIAG_INFO("External RTC initialize OK!\n"); return SP_OK; }
/** * @brief Gpio pin request function. * @param pin_index[in]: gpio channel + function id + gid + pin number * @param name[in]: caller's name * @return gpio handle/ERROR_ID * @see */ int gp_gpio_request(unsigned int pin_index, char *name) { int ret; unsigned int ch = GPIO_CHANNEL(pin_index); unsigned int pin_number = GPIO_PIN_NUMBER(pin_index); gpio_handle_t *handle; if (gpio == NULL) { DIAG_ERROR("gpio not initialized!"); return -ENODEV; } if(ch >= NUM_GPIO_CHANNEL) { DIAG_ERROR("ch not exit!"); return -EINVAL; } if (down_interruptible(&gpio->sem) != 0) { return -ERESTARTSYS; } /* check pin requested */ if ((ch < NUM_GPIO_CHANNEL) && (pin_number < 32) && (pin_table[ch][pin_number] != NULL)) { name = pin_table[ch][pin_number]->name; DIAG_ERROR("pin already requested by %s!\n", (name != NULL) ? name : "unknown module"); ret = -EBUSY; goto out; } ret = gpHalGpioSetPadGrp(pin_index); if (ret != 0) { ret = -EINVAL; goto out; } handle = (gpio_handle_t *)kzalloc(sizeof(gpio_handle_t), GFP_KERNEL); if (handle == NULL) { ret = -ENOMEM; goto out; } handle->pin_index = pin_index; handle->name = name; ret = (int)handle; /* set pin requested */ if ((ch < NUM_GPIO_CHANNEL) && (pin_number < 32)) { pin_table[ch][pin_number] = handle; } out: up(&gpio->sem); return ret; }
static UINT32 audioInit( void ) { #ifdef SYSCONFIG_SPU if (insmod("gp_audio") != SP_OK) { DIAG_ERROR("insmod gp_audio error!\n"); return SP_FAIL; } if (insmod("gp_mixer") != SP_OK) { DIAG_ERROR("insmod gp_mixer error!\n"); return SP_FAIL; } if (insmod("gp_spu_module") != SP_OK) { DIAG_ERROR("insmod gp_spu_module error!\n"); return SP_FAIL; } #else #ifdef SYSCONFIG_AUDIO if (insmod("gp_audio") != SP_OK) { DIAG_ERROR("insmod gp_audio error!\n"); return SP_FAIL; } if (insmod("gp_mixer") != SP_OK) { DIAG_ERROR("insmod gp_mixer error!\n"); return SP_FAIL; } #endif #endif return SP_OK; }
static UINT32 ppuInit( void ) { #ifdef SYSCONFIG_PPU #if (SYSCONFIG_PPU == 1) if (insmod("gp_ppu_module") != SP_OK) { DIAG_ERROR("insmod gp_ppu_module error!\n"); return SP_FAIL; } #elif (SYSCONFIG_PPU == 2) if (insmod("gp_ppu_simple") != SP_OK) { DIAG_ERROR("insmod gp_ppu_simple error!\n"); return SP_FAIL; } #elif (SYSCONFIG_PPU == 3) if (insmod("gp_ppu_dma_module") != SP_OK) { DIAG_ERROR("insmod gp_ppu_dma_module error!\n"); return SP_FAIL; } #endif #endif return SP_OK; }
static UINT32 scalarInit( void ) { if (insmod("gp_scale_module") != SP_OK) { DIAG_ERROR("insmod gp_scale_module error!\n"); return SP_FAIL; } if( gp_ver.major == MACH_GPL32900 ) { if (insmod("gp_scale2_module") != SP_OK) { DIAG_ERROR("insmod gp_scale_module error!\n"); return SP_FAIL; } } if( gp_ver.major == MACH_GPL32900B ) { if (insmod("gp_scale2_module") != SP_OK) { DIAG_ERROR("insmod gp_scale_module error!\n"); return SP_FAIL; } } return SP_OK; }
/** *@brief Write S35390A register */ static int s35390a_set_reg(unsigned char addr, unsigned char *dataGroup, unsigned char cnt) { unsigned char slaveAddress = DEVICE_ADDR; int ret = SP_OK; unsigned char i = 0; int i2c_handle = 0; addr = (addr<<1)&0x0e; slaveAddress = (slaveAddress|addr); i2c_handle = gp_i2c_bus_request(slaveAddress, 0x0f); if(!i2c_handle){ DIAG_ERROR("[%s] Fail to request I2c bus!\n", __FUNCTION__); return SP_FAIL; } //msb2Lsb(dataGroup, cnt); for(i = 0; i < cnt; i++){ dataGroup[i] = bitrev8(dataGroup[i]); } ret = gp_i2c_bus_write(i2c_handle, dataGroup, cnt); if(ret < 0){ DIAG_ERROR("Fail to write external RTC register!\n"); ret = SP_FAIL; }else{ ret = SP_OK; } if(i2c_handle) gp_i2c_bus_release(i2c_handle); return ret; }
static int __init gp_ext_rtc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; int ret = 0; gp_ext_rtc_info = kzalloc(sizeof(gp_ext_rtc_t), GFP_KERNEL); if (!gp_ext_rtc_info) return -ENOMEM; if(s35390a_init()){ DIAG_ERROR("S35390A Initialize Fail!!!\n"); goto err_init; } #if ENABLE_INT1_OUTPUT_FREQUENCY s35390a_int1_output_freq(16); #endif spin_lock_init(&gp_ext_rtc_info->lock); gp_ext_rtc_info->rtc = rtc_device_register("gp-ext-rtc", &pdev->dev, &gp_ext_rtc_ops, THIS_MODULE); ret = PTR_ERR(gp_ext_rtc_info->rtc); if (IS_ERR(gp_ext_rtc_info->rtc)) { DIAG_ERROR("Failed to register RTC device -> %d\n", ret); goto err_init; } device_init_wakeup(dev, 1); return 0; err_init: kfree(gp_ext_rtc_info); gp_ext_rtc_info = NULL; return ret; }
/** * @brief Scale driver init function */ static int __init scale_init(void) { int ret = -ENXIO; scale = (scale_info_t *)kzalloc(sizeof(scale_info_t), GFP_KERNEL); if (scale == NULL) { ret = -ENOMEM; DIAG_ERROR("scale kmalloc fail\n"); goto fail_kmalloc; } ret = request_irq(IRQ_SCALE_ENGINE, scale_irq_handler, IRQF_SHARED, "SCALE_IRQ", scale); if (ret < 0) { DIAG_ERROR("scale request irq fail\n"); goto fail_request_irq; } /* initialize */ init_MUTEX(&scale->sem); init_waitqueue_head(&scale->done_wait); scale->dev.name = "scalar"; scale->dev.minor = MISC_DYNAMIC_MINOR; scale->dev.fops = &scale_fops; /* register device */ ret = misc_register(&scale->dev); if (ret != 0) { DIAG_ERROR("scalar device register fail\n"); goto fail_device_register; } platform_device_register(&gp_scalar_device); platform_driver_register(&gp_scalar_driver); return 0; /* error rollback */ fail_device_register: free_irq(IRQ_SCALE_ENGINE, scale); fail_request_irq: kfree(scale); scale = NULL; fail_kmalloc: return ret; }
static UINT32 asensorInit( void ) { #ifdef SYSCONFIG_A_SENSOR DIAG_ERROR("load asensor ko\n"); if (insmod("/lib/modules/common/%s.ko",SYSCONFIG_A_SENSOR_DEVICE) != SP_OK) { DIAG_ERROR("insmod gp_gsensor error!\n"); return SP_FAIL; } #endif return SP_OK; }
static int gp_adc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct gp_adc_device_s *adc; int ret; adc = kzalloc(sizeof(struct gp_adc_device_s), GFP_KERNEL); if (adc == NULL) { DIAG_ERROR("failed to allocate adc device\n"); return -ENOMEM; } g_adc_dev = adc; sema_init(&adc->lock,1); sema_init(&g_adc_prepare,1); sema_init(&adc->aux_sem, 0); adc->pdev = pdev; adc->aux_ch = -1; /* not starting aux */ ret = request_irq( IRQ_SAACC, gp_adc_irq, 0, dev_name(dev), adc); if (ret < 0) { DIAG_ERROR( "failed to attach adc irq\n"); goto err_alloc; } /* register misc device */ adc->dev.name = "adc"; adc->dev.minor = MISC_DYNAMIC_MINOR; adc->dev.fops = &gp_adc_fops; adc->open_cnt = 0; ret = misc_register(&adc->dev); if (ret != 0) { DIAG_ERROR("gp_adc device register fail\n"); goto err_irq; } platform_set_drvdata(pdev, adc); if(gAdcRegBackup == NULL) gAdcRegBackup = (int *)kmalloc(sizeof(regADC_t), GFP_KERNEL); return 0; err_irq: free_irq(IRQ_SAACC, adc); err_alloc: kfree(adc); return ret; }
static UINT32 sysMknod( char *name, mode_t mode ) { FILE *file; char line[128]; UINT32 minor; char *pEnd; file = fopen ("/proc/misc", "r"); if (file == NULL) { DIAG_ERROR("[%s:%d], Open Fail!\n", __FUNCTION__, __LINE__); return SP_FAIL; } while (fgets(line, sizeof(line), file) != NULL) { minor = (UINT32)strtol(line, &pEnd, 10); pEnd += 1; if (strncmp(pEnd, name, strlen(name)) == 0) { memset(&line, 0, sizeof(line)); snprintf(line, sizeof(line), "/dev/%s", name); mknod(line, S_IFCHR|0777, makedev(MISC_MAJOR, minor)); break; } } fclose ( file ); return SP_OK; }
enum HunterState hunter_get_state(struct CmpAppr *appr) { if (appr->type == CMP_APPR_STATIC_SPRITE && appr->body.static_sprite.bitmap == sc_hunter_stand_right) { return HUNTER_STATE_STAND_RIGHT; } else if ( appr->type == CMP_APPR_STATIC_SPRITE && appr->body.static_sprite.bitmap == sc_hunter_stand_left) { return HUNTER_STATE_STAND_LEFT; } else if ( appr->type == CMP_APPR_ANIMATED_SPRITE && appr->body.animated_sprite.common == sc_hunter_walk_right_common) { return HUNTER_STATE_WALK_RIGHT; } else if ( appr->type == CMP_APPR_ANIMATED_SPRITE && appr->body.animated_sprite.common == sc_hunter_walk_left_common) { return HUNTER_STATE_WALK_LEFT; } else { DIAG_ERROR("Failed recognizing hunter state based on the appearance component."); exit(1); } }
/** * @brief I2C bus device write function */ static ssize_t i2c_bus_write(struct file *flip, const char __user *buf, size_t count, loff_t *oppos) { int ret = 0; unsigned char *sendBuf = NULL; sendBuf = (unsigned char *)kmalloc(count, GFP_KERNEL); if (!sendBuf) { ret = -ENOMEM; goto __err_kmalloc; } if (copy_from_user(sendBuf, buf, count)) { ret = -EFAULT; goto __err_copy; } ret = gp_i2c_bus_write((int)flip->private_data, sendBuf, count); if (ret < 0) { DIAG_ERROR("ERROR: i2c bus write fail\n"); //return -ENXIO; /*MUST free sendBuf*/ ret = -ENXIO; } __err_copy: kfree(sendBuf); sendBuf = NULL; __err_kmalloc: return ret; }
/** * @brief I2C bus device read function */ static ssize_t i2c_bus_read(struct file *flip, char __user *buf, size_t count, loff_t *oppos) { int ret = 0; unsigned char *recvBuf = NULL; recvBuf = (unsigned char *)kmalloc(count, GFP_KERNEL); if (!(recvBuf)) { ret = -ENOMEM; goto __err_kmalloc; } ret = gp_i2c_bus_read((int)flip->private_data, recvBuf, count); if (ret <= 0) { DIAG_ERROR("ERROR: i2c read fail\n"); /*return -ENXIO;*/ ret = -ENXIO; goto __err_copy; } if (copy_to_user(buf, recvBuf, ret)) { ret = -EFAULT; /*goto __err_copy;*/ } __err_copy: kfree(recvBuf); recvBuf = NULL; __err_kmalloc: return ret; }
static UINT32 uartModeInit(void) {/* #define SYSCONFIG_UART_FUNC #define SYSCONFIG_UART_FUNC_DEVICE "CloudDog" */ #ifdef SYSCONFIG_UART_FUNC DIAG_ERROR("load asensor ko\n"); if (insmod("/lib/modules/common/%s.ko",SYSCONFIG_UART_FUNC_DEVICE) != SP_OK) { DIAG_ERROR("insmod gp_gsensor error!\n"); return SP_FAIL; } #endif return SP_OK; }
/** * @brief spi device probe */ static int gp_spi_probe(struct platform_device *pdev) { int ret = 0; gp_spi_data = kzalloc(sizeof(gp_spi_t), GFP_KERNEL); if(!gp_spi_data){ return -ENOMEM; } memset(gp_spi_data, 0, sizeof(gp_spi_t)); gp_spi_data->pin_handle = gp_board_pin_func_request(GP_PIN_SPI, GP_BOARD_WAIT_FOREVER); if (gp_spi_data->pin_handle < 0) { DIAG_ERROR("[%s:%d] Error!\n", __FUNCTION__, __LINE__); ret = -EINVAL; goto fail_pin; } gp_spi_data->dev.name = SPI_NAME; gp_spi_data->dev.minor = MISC_DYNAMIC_MINOR; gp_spi_data->dev.fops = &spi_fops; gpHalSpiClkEnable(&gp_spi_device.dev, 1); ret = misc_register(&gp_spi_data->dev); if(ret != 0){ DIAG_ERROR("spi probe register fail\n"); goto fail_reg; } platform_set_drvdata(pdev,&gp_spi_data); init_MUTEX(&gp_spi_data->spi_sem); DIAG_INFO("spi probe ok\n"); return 0; fail_reg: gp_board_pin_func_release(gp_spi_data->pin_handle); gpHalSpiClkEnable(&gp_spi_device.dev, 0); fail_pin: kfree(gp_spi_data); return ret; }
static UINT32 rtcInit( void ) { #ifdef SYSCONFIG_INTERNAL_RTC if (insmod("gp_rtc_module") != SP_OK) { DIAG_ERROR("insmod external_rtc error!\n"); return SP_FAIL; } #else if (insmod("/lib/modules/external_rtc.ko") != SP_OK) { DIAG_ERROR("insmod external_rtc error!\n"); return SP_FAIL; } #endif return SP_OK; }
/** * @brief ioctrl to check request buffer * @return success: 0, fail: -EINVAL(<0) * @see */ static int32_t check_rqbuf_type(void) { if(csi_devices->rbuf.count>CSI_MAX_BUF) { DIAG_ERROR("too many buffers\n"); return -EINVAL; } if(csi_devices->rbuf.type!=V4L2_BUF_TYPE_VIDEO_CAPTURE) { DIAG_ERROR("only support video capture mode"); return -EINVAL; } if(csi_devices->rbuf.memory!=V4L2_MEMORY_USERPTR) { DIAG_ERROR("only support userptr I/O strea\n"); return -EINVAL; } return 0; }
static int __init gp_ext_rtc_init(void) { int ret = 0; ret = platform_device_register(&gp_ext_rtc_device); if (ret != 0){ DIAG_ERROR("Unable to register gp ext rtc device: %d\n", ret); return ret; } return platform_driver_register(&gp_ext_rtc_driver); }
static UINT32 pwmInit( void ) { if (insmod("gp_pwm_module") != SP_OK) { DIAG_ERROR("insmod gp_pwm_module error!\n"); return SP_FAIL; } }
static UINT32 ti2cInit( void ) { if(insmod("gp_ti2c_bus_module") != SP_OK){ DIAG_ERROR("insmod TI2C bus error!\n"); return SP_FAIL; } }
static UINT32 timerInit( void ) { if (insmod("gp_timer_module") != SP_OK) { DIAG_ERROR("insmod gp_tc_module error!\n"); return SP_FAIL; } }
static UINT32 aesInit( void ) { if (insmod("gp_aes_module") != SP_OK) { DIAG_ERROR("insmod gp_aes_module error!\n"); return SP_FAIL; } return SP_OK; }
void *cmp_appr_bitmap(struct CmpAppr *appr) { switch (appr->type) { case CMP_APPR_STATIC_SPRITE: return cmp_appr_static_sprite_bitmap((struct CmpApprStaticSprite*)appr); case CMP_APPR_ANIMATED_SPRITE: return cmp_appr_animated_sprite_bitmap((struct CmpApprAnimSprite*)appr); } DIAG_ERROR("Should never get here."); exit(1); }
static int __init gp_adc_module_init(void) { int ret; platform_device_register(&gp_adc_device); ret = platform_driver_register(&gp_adc_driver); if (ret) DIAG_ERROR("%s: failed to add adc driver\n", __func__); return ret; }
static UINT32 gpFastBootInit( void ) { if(insmod("snapshot") != SP_OK) { DIAG_ERROR("insmod snapshot driver error!\n"); return SP_FAIL; } return SP_OK; }
static UINT32 lineBufferInit( void ) { if (insmod("gp_line_buffer_module") != SP_OK) { DIAG_ERROR("insmod gp_line_buffer_module error!\n"); return SP_FAIL; } return SP_OK; }
static UINT32 boardInit( void ) { if (insmod("/lib/modules/board_config.ko") != SP_OK) { DIAG_ERROR("insmod board_config error!\n"); return SP_FAIL; } return SP_OK; }
static UINT32 boardCoreInit( void ) { if (insmod("gp_board") != SP_OK) { DIAG_ERROR("insmod gp_board error!\n"); return SP_FAIL; } return SP_OK; }
static UINT32 inputInit( void ) { #ifdef SYSCONFIG_KEY if (insmod("/lib/modules/key_driver.ko") != SP_OK) { DIAG_ERROR("insmod key_driver error!\n"); return SP_FAIL; } #endif #ifdef SYSCONFIG_TOUCH if (insmod("/lib/modules/touch_driver.ko") != SP_OK) { DIAG_ERROR("insmod touch_driver error!\n"); return SP_FAIL; } #endif return SP_OK; }