static int pmic_get(void *data, u64 *val) { const NvOdmPeripheralConnectivity *con = NULL; int ldo_number; NvU32 millivolts; struct pmic_struct *pmic_info = data; ldo_number = pmic_info->ldo_number; con = NvOdmPeripheralGetGuid(NV_ODM_GUID('a','l','l','p','o','w','e','r')); if (con == NULL){ *val = 9999; printk("PMIC(debugfs) : query ERROR\n"); return 0; } NvRmPmuGetVoltage(s_hRmGlobal, con->AddressList[ldo_number].Address, &millivolts); if(millivolts){ *val = 1; printk("PMIC(debugfs) : LDO%d (on)\n", ldo_number+1); }else{ *val = 0; printk("PMIC(debugfs) : LDO%d (off)\n", ldo_number+1); } return 0; }
static void __init register_spi_ipc_devices(void) { unsigned long instance = 0xFFFF; unsigned long cs = 0xFFFF; const NvOdmPeripheralConnectivity *pConnectivity = NULL; int i; pConnectivity = NvOdmPeripheralGetGuid(NV_ODM_GUID('s','p','i',' ','_','i','p','c')); if (!pConnectivity) return; for (i = 0; i < pConnectivity->NumAddress; i++) { switch (pConnectivity->AddressList[i].Interface) { case NvOdmIoModule_Spi: instance = pConnectivity->AddressList[i].Instance; cs = pConnectivity->AddressList[i].Address; break; default: break; } } if (instance == 0xffff || cs == 0xffff) { pr_err("%s: SPI IPC Protocol driver: Instance and CS are Invalid\n", __func__); return; } tegra_spi_ipc_devices[0].bus_num = instance; tegra_spi_ipc_devices[0].chip_select = cs; if (spi_register_board_info(tegra_spi_ipc_devices, ARRAY_SIZE(tegra_spi_ipc_devices)) != 0) { pr_err("%s: spi_register_board_info returned error\n", __func__); } }
static int __init touchLED_probe(struct platform_device *pdev) { s_touchLED.conn = NvOdmPeripheralGetGuid( NV_ODM_GUID('t','o','u','c','h','L','E','D') ); /* enable the power rail */ s_touchLED.hPmu = NvOdmServicesPmuOpen(); if( s_touchLED.conn->AddressList[0].Interface == NvOdmIoModule_Vdd ) { NvOdmServicesPmuVddRailCapabilities cap; NvU32 settle_us; /* address is the vdd rail id */ NvOdmServicesPmuGetCapabilities( s_touchLED.hPmu, s_touchLED.conn->AddressList[0].Address, &cap ); s_touchLED.setVal = cap.requestMilliVolts; s_touchLED.maxVal = 100; /*10.0mA*/ /* set the rail volatage to the recommended */ NvOdmServicesPmuSetVoltage( s_touchLED.hPmu, s_touchLED.conn->AddressList[0].Address, cap.requestMilliVolts, &settle_us ); /* wait for rail to settle */ NvOdmOsWaitUS( settle_us ); } INIT_WORK(&s_touchLED.work, touchLED_timeout); #ifdef TOUCH_LED_TIMER hrtimer_init(&s_touchLED.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); s_touchLED.timer.function = touchLED_timer_func; s_touchLED.delay = TOUCH_DELAY_SEC; hrtimer_start(&s_touchLED.timer, ktime_set(BOOT_DELAY_SEC, 0), HRTIMER_MODE_REL); #endif #ifdef CONFIG_HAS_EARLYSUSPEND s_touchLED.early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; s_touchLED.early_suspend.suspend = touchLED_early_suspend; s_touchLED.early_suspend.resume = touchLED_late_resume; register_early_suspend(&s_touchLED.early_suspend); #endif //20101104, [email protected], WLED set [START] if (sysfs_create_group(&pdev->dev.kobj, &star_wled_group)) { printk(KERN_ERR "[star touch led] sysfs_create_group ERROR\n"); } //20101104, [email protected], WLED set [END] return 0; }
static ssize_t star_pmic_store(struct device *dev, struct device_attribute *attr, char *buf, size_t count) { u32 val = 0; val = simple_strtoul(buf, NULL, 10); if(val){ NvOdmPeripheralConnectivity const *conn = NULL; NvOdmServicesPmuHandle hPmu; conn = NvOdmPeripheralGetGuid( NV_ODM_GUID('p','m','_','r','e','s','e','t') ); hPmu = NvOdmServicesPmuOpen(); if(!conn){ printk("ERROR : invalid GUID\n"); sprintf(buf, "PMIC reset fail\n"); return (ssize_t)(strlen(buf) + 1); } if( conn->AddressList[0].Interface == NvOdmIoModule_Vdd ) { NvU32 settle_us; /* set the rail volatage to the recommended */ NvOdmServicesPmuSetVoltage( hPmu, conn->AddressList[0].Address, NVODM_VOLTAGE_OFF, &settle_us ); /* wait for rail to settle */ NvOdmOsWaitUS( settle_us ); } NvOdmServicesPmuClose(hPmu); } sprintf(buf, "PMIC reset\n"); printk("PMIC reset\n"); return (ssize_t)(strlen(buf) + 1); }
static int __init powerkey_probe(struct platform_device *pdev) { int ret; NvU32 pin, port; const NvOdmPeripheralConnectivity *con = NULL; //20101129, [email protected], idle current issue [START] //GPIO configuration s_touchMaker.gpioHandle = NvOdmGpioOpen(); port = 'x'-'a'; pin = 5; s_touchMaker.pinHandle = NvOdmGpioAcquirePinHandle(s_touchMaker.gpioHandle, port, pin); NvOdmGpioConfig(s_touchMaker.gpioHandle, s_touchMaker.pinHandle, NvOdmGpioPinMode_InputData); //20101129, [email protected], idle current issue [END] //20100610, [email protected], sleep status gpio for modem [START] #ifdef AP_SUSPEND_STATUS //GPIO configuration s_modemCheck.gpioHandle = NvOdmGpioOpen(); if (!s_modemCheck.gpioHandle) { printk(KERN_ERR "[star modem_chk] NvOdmGpioOpen Error \n"); goto err_open_modem_chk_gpio_fail; } port = 'r'-'a'; pin = 0; s_modemCheck.pinHandle = NvOdmGpioAcquirePinHandle(s_modemCheck.gpioHandle, port, pin); if (!s_modemCheck.pinHandle) { printk(KERN_ERR "[star modem_chk] NvOdmGpioAcquirePinHandle Error\n"); goto err_modem_chk_gpio_pin_acquire_fail; } NvOdmGpioSetState(s_modemCheck.gpioHandle, s_modemCheck.pinHandle, 1); NvOdmGpioConfig(s_modemCheck.gpioHandle, s_modemCheck.pinHandle, NvOdmGpioPinMode_Output); #endif //20100610, [email protected], sleep status gpio for modem [END] memset(&s_powerkey, 0x00, sizeof(s_powerkey)); //get query con = NvOdmPeripheralGetGuid(NV_ODM_GUID('p','o','w','e','r','k','e','y')); if(!con){ printk(KERN_ERR "[star powerkey] ODM GUID Error \n"); goto err_probe_fail; } if ( con->AddressList[0].Interface == NvOdmIoModule_Gpio){ port = con->AddressList[0].Instance; pin = con->AddressList[0].Address; }else{ printk(KERN_ERR "[star powerkey] cannot find ODM GUID \n"); goto err_probe_fail; } #ifdef POWERKEY_DELAYED_WORKQUEUE INIT_DELAYED_WORK(&s_powerkey.work, powerkey_handle); wake_lock_init(&s_powerkey.wlock, WAKE_LOCK_SUSPEND, "powerkey_delay"); #else INIT_WORK(&s_powerkey.work, powerkey_handle); #endif //GPIO configuration s_powerkey.gpioHandle = NvOdmGpioOpen(); if (!s_powerkey.gpioHandle) { printk(KERN_ERR "[star powerkey] NvOdmGpioOpen Error \n"); goto err_open_gpio_fail; } s_powerkey.pinHandle = NvOdmGpioAcquirePinHandle(s_powerkey.gpioHandle, port, pin); if (!s_powerkey.pinHandle) { printk(KERN_ERR "[star powerkey] NvOdmGpioAcquirePinHandle Error\n"); goto err_gpio_pin_acquire_fail; } //NvOdmGpioSetState(s_powerkey.gpioHandle, s_powerkey.pinHandle, 0); NvOdmGpioConfig(s_powerkey.gpioHandle, s_powerkey.pinHandle, NvOdmGpioPinMode_InputData); //GPIO interrupt registration if (NvOdmGpioInterruptRegister(s_powerkey.gpioHandle, &s_powerkey.intHandle, s_powerkey.pinHandle, NvOdmGpioPinMode_InputInterruptAny, powerkey_interrupt_handler, (void*)&s_powerkey, 0) == NV_FALSE) { printk(KERN_ERR "[star Powerkey] interrupt registeration fail!\n"); goto err_interrupt_register_fail; } // input device s_powerkey.inputDev = input_allocate_device(); if (!s_powerkey.inputDev) { printk(KERN_ERR "[star Powerkey] input_allocate_device Error!\n"); goto err_input_device_allocation_fail; } s_powerkey.inputDev->name = "powerkey"; //s_powerkey.inputDev->id.bustype = BUS_HOST; s_powerkey.inputDev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR); set_bit(KEY_POWER, s_powerkey.inputDev->keybit); ret = input_register_device(s_powerkey.inputDev); if (ret) { printk(KERN_ERR "[star powerkey] input_register_device Error\n"); goto err_input_device_register_fail; } //20100703, [email protected], PMIC reset [START] ret = sysfs_create_group(&pdev->dev.kobj, &star_pmic_group); if (ret) { printk(KERN_ERR "[star powerkey] sysfs_create_group ERROR\n"); goto err_pmic_sysfs_fail; } //20100703, [email protected], PMIC reset [END] ret = sysfs_create_group(&pdev->dev.kobj, &star_hwsku_group); if (ret) { printk(KERN_ERR "[star powerkey] sysfs_create_group ERROR\n"); goto err_hwsku_sysfs_fail; } //20101110, [email protected], Function for Warm-boot [START] ret = sysfs_create_group(&pdev->dev.kobj, &star_reset_group); if (ret) { printk(KERN_ERR "[star powerkey] sysfs_create_group ERROR\n"); goto err_reset_sysfs_fail; } //20101110, [email protected], Function for Warm-boot [END] // 20110209 [email protected] disable gpio interrupt during power-off [START] ret = sysfs_create_group(&pdev->dev.kobj, &star_poweroff_group); if (ret) { printk(KERN_ERR "[star powerkey] sysfs_create_group <star_poweroff_group> ERROR\n"); goto err_input_device_register_fail; } // 20110209 [email protected] disable gpio interrupt during power-off [END] return 0; err_reset_sysfs_fail: sysfs_remove_group(&pdev->dev.kobj, &star_hwsku_group); err_hwsku_sysfs_fail: sysfs_remove_group(&pdev->dev.kobj, &star_pmic_group); err_pmic_sysfs_fail: input_unregister_device(s_powerkey.inputDev); err_input_device_register_fail: input_free_device(s_powerkey.inputDev); err_input_device_allocation_fail: NvOdmGpioInterruptUnregister(s_powerkey.gpioHandle, s_powerkey.pinHandle, s_powerkey.intHandle); err_interrupt_register_fail: NvOdmGpioReleasePinHandle(s_powerkey.gpioHandle, s_powerkey.pinHandle); err_gpio_pin_acquire_fail: NvOdmGpioClose(s_powerkey.gpioHandle); err_open_gpio_fail: #ifdef POWERKEY_DELAYED_WORKQUEUE wake_lock_destroy(&s_powerkey.wlock); #endif err_probe_fail: //20100610, [email protected], sleep status gpio for modem [START] #ifdef AP_SUSPEND_STATUS NvOdmGpioReleasePinHandle(s_modemCheck.gpioHandle, s_modemCheck.pinHandle); err_modem_chk_gpio_pin_acquire_fail: NvOdmGpioClose(s_modemCheck.gpioHandle); err_open_modem_chk_gpio_fail: #endif //20100610, [email protected], sleep status gpio for modem [END] return -ENOSYS; }
//----------------------------------------------------------------- //--------------------------------New API-------------------------- //----------------------------------------------------------------- NvBool NvOdmGyroAccelOpen(NvOdmGyroAccelHandle* hDevice) { NvU32 i; NvBool foundGpio = NV_FALSE, foundI2cModule = NV_FALSE; const NvOdmPeripheralConnectivity *pConnectivity; NvOdmGyroAccelHandle hGyro; NvU32 reg_val = 0 ; #if 1 printk(" ## MPU3050 : [NvOdmGyroOpen:%d] \n",__LINE__) ; #endif hGyro = NvOdmOsAlloc(sizeof(NvOdmGyro)); if (hGyro == NULL) { printk("Error Allocating NvOdmAccel. \n"); return NV_FALSE; } NvOdmOsMemset(hGyro, 0, sizeof(NvOdmGyro)); hGyro->hPmu = NULL; hGyro->hOdmI2C = NULL; hGyro->hPmu = NvOdmServicesPmuOpen(); if (!hGyro->hPmu) { printk("NvOdmServicesPmuOpen Error \n"); goto error; } pConnectivity = (NvOdmPeripheralConnectivity*)NvOdmPeripheralGetGuid(NV_ODM_GUID('g','y','r','o','s','c','o','p')); if (!pConnectivity) { printk("NvOdmPeripheralGetGuid doesn't detect gyro_accel device\n"); goto error; } if(pConnectivity->Class != NvOdmPeripheralClass_Other) { goto error; } for (i = 0; i < pConnectivity->NumAddress; i++) { switch(pConnectivity->AddressList[i].Interface) { case NvOdmIoModule_I2c: hGyro->I2CChannelId = pConnectivity->AddressList[i].Instance; hGyro->nDevAddr = (pConnectivity->AddressList[i].Address << 1); foundI2cModule = NV_TRUE; foundGpio = NV_TRUE; //test #if 1 printk("## MPU3050 I2CChannelId = %x. ## \n", hGyro->I2CChannelId); printk("## MPU3050 i2c address = %x. ## \n", hGyro->nDevAddr); #endif break; /* case NvOdmIoModule_Gpio: hGyro->GPIOPortINT = pConnectivity->AddressList[i].Instance; hGyro->GPIOPinINT = pConnectivity->AddressList[i].Address; foundGpio = NV_TRUE; #if 1 printk("## MPU3050 GPIOPortINT = %x. ## \n",hGyro->GPIOPortINT); printk("## MPU3050 GPIOPinINT = %x. ## \n", hGyro->GPIOPinINT); #endif break;*/ case NvOdmIoModule_Vdd: hGyro->VddId = pConnectivity->AddressList[i].Address; #if 1 printk("## MPU3050 NvOdmIoModule_VddId = %x. ## \n", hGyro->VddId); #endif // Power on accelerometer according to Vddid NvGyroAccelSetPowerRail(hGyro->hPmu, hGyro->VddId, NV_TRUE); break; default: break; } } if (foundGpio != NV_TRUE || foundI2cModule != NV_TRUE) { printk("GyroAccel : didn't find any periperal in discovery query for touch device Error \n"); goto error; } // Set up I2C bus. if (NV_FALSE == NvGyroAccelI2COpen(&hGyro->hOdmI2C, hGyro->I2CChannelId)) { printk("GyroAccel : NvGyroAccelI2COpen Error \n"); goto error; }; printk(" ##1## GyroAccel : NvGyroAccelI2COpen check1 \n"); hGyro->RegsRead = NvGyroAccelI2CGetRegs; hGyro->RegsWrite = NvGyroAccelI2CSetRegs; printk(" ##2## GyroAccel : NvGyroAccelI2COpen check2 \n"); /* if(NV_FALSE == NvGyroAccelConnectSemaphore(hGyro)) { printk("GyroAccel : NvGyroAccelConnectSemaphore Error \n"); goto error; } */ *hDevice = hGyro; return NV_TRUE; error: // Release all of resources requested. if (NULL != hGyro) { NvGyroAccelSetPowerRail(hGyro->hPmu, hGyro->VddId, NV_FALSE); NvOdmServicesPmuClose(hGyro->hPmu); hGyro->hPmu = NULL; NvGyroAccelI2CClose(hGyro->hOdmI2C); hGyro->hOdmI2C = NULL; NvOdmOsFree(hGyro); *hDevice = NULL; } return NV_FALSE; }
static NvOdmPmuDevice* GetPmuInstance(NvOdmPmuDeviceHandle hDevice) { static NvOdmPmuDevice Pmu; static NvBool first = NV_TRUE; if (first) { NvOdmOsMemset(&Pmu, 0, sizeof(Pmu)); first = NV_FALSE; if (NvOdmPeripheralGetGuid(NV_ODM_GUID('t','p','s','6','5','8','6','x'))) { // fill in HAL functions here. Pmu.Hal = NV_TRUE; Pmu.pfnSetup = Tps6586xSetup; Pmu.pfnRelease = Tps6586xRelease; Pmu.pfnGetCaps = Tps6586xGetCapabilities; Pmu.pfnGetVoltage = Tps6586xGetVoltage; Pmu.pfnSetVoltage = Tps6586xSetVoltage; Pmu.pfnGetAcLineStatus = Tps6586xGetAcLineStatus; Pmu.pfnGetBatteryStatus = Tps6586xGetBatteryStatus; Pmu.pfnGetBatteryData = Tps6586xGetBatteryData; Pmu.pfnGetBatteryFullLifeTime = Tps6586xGetBatteryFullLifeTime; Pmu.pfnGetBatteryChemistry = Tps6586xGetBatteryChemistry; Pmu.pfnSetChargingCurrent = Tps6586xSetChargingCurrent; Pmu.pfnInterruptHandler = Tps6586xInterruptHandler; Pmu.pfnReadRtc = Tps6586xReadRtc; Pmu.pfnWriteRtc = Tps6586xWriteRtc; Pmu.pfnReadAlarm = Tps6586xReadAlarm; Pmu.pfnWriteAlarm = Tps6586xWriteAlarm; Pmu.pfnIsRtcInitialized = Tps6586xIsRtcInitialized; } else if (NvOdmPeripheralGetGuid(NV_ODM_GUID('p','c','f','_','p','m','u','0'))) { Pmu.pfnSetup = Pcf50626Setup; Pmu.pfnRelease = Pcf50626Release; Pmu.pfnGetCaps = Pcf50626GetCapabilities; Pmu.pfnGetVoltage = Pcf50626GetVoltage; Pmu.pfnSetVoltage = Pcf50626SetVoltage; Pmu.pfnGetAcLineStatus = Pcf50626GetAcLineStatus; Pmu.pfnGetBatteryStatus = Pcf50626GetBatteryStatus; Pmu.pfnGetBatteryData = Pcf50626GetBatteryData; Pmu.pfnGetBatteryFullLifeTime = Pcf50626GetBatteryFullLifeTime; Pmu.pfnGetBatteryChemistry = Pcf50626GetBatteryChemistry; Pmu.pfnSetChargingCurrent = Pcf50626SetChargingCurrent; Pmu.pfnInterruptHandler = Pcf50626InterruptHandler; Pmu.pfnReadRtc = Pcf50626RtcCountRead; Pmu.pfnWriteRtc = Pcf50626RtcCountWrite; Pmu.pfnReadAlarm = NULL; Pmu.pfnWriteAlarm = NULL; Pmu.pfnIsRtcInitialized = Pcf50626IsRtcInitialized; Pmu.pPrivate = NULL; Pmu.Hal = NV_TRUE; Pmu.Init = NV_FALSE; } else if (NvOdmPeripheralGetGuid(NV_ODM_GUID('m','a','x','8','9','0','7','b'))) { Pmu.pfnSetup = Max8907bSetup; Pmu.pfnRelease = Max8907bRelease; Pmu.pfnGetCaps = Max8907bGetCapabilities; Pmu.pfnGetVoltage = Max8907bGetVoltage; Pmu.pfnSetVoltage = Max8907bSetVoltage; Pmu.pfnGetAcLineStatus = Max8907bGetAcLineStatus; Pmu.pfnGetBatteryStatus = Max8907bGetBatteryStatus; Pmu.pfnGetBatteryData = Max8907bGetBatteryData; Pmu.pfnGetBatteryFullLifeTime = Max8907bGetBatteryFullLifeTime; Pmu.pfnGetBatteryChemistry = Max8907bGetBatteryChemistry; Pmu.pfnSetChargingCurrent = Max8907bSetChargingCurrent; Pmu.pfnInterruptHandler = Max8907bInterruptHandler; Pmu.pfnReadRtc = Max8907bRtcCountRead; Pmu.pfnWriteRtc = Max8907bRtcCountWrite; Pmu.pfnReadAlarm = NULL; Pmu.pfnWriteAlarm = NULL; Pmu.pfnIsRtcInitialized = Max8907bIsRtcInitialized; Pmu.pPrivate = NULL; Pmu.Hal = NV_TRUE; Pmu.Init = NV_FALSE; } } if (hDevice && Pmu.Hal) return &Pmu; return NULL; }
static int pmic_set(void *data, u64 val) { u32 settling_time; const NvOdmPeripheralConnectivity *con = NULL; int ldo_number; int j; NvU32 millivolts; NvU32 loop_count = MAX_REFCOUNT_LOOP; NvRmPmuVddRailCapabilities rail; struct pmic_struct *pmic_info = data; ldo_number = pmic_info->ldo_number; printk("PMIC(debugfs) : WARNING!! reference counter will be broken\n"); con = NvOdmPeripheralGetGuid(NV_ODM_GUID('a','l','l','p','o','w','e','r')); if (con == NULL){ printk("PMIC(debugfs) : query ERROR\n"); return 0; } if(ldo_number == 2){ printk("PMIC(debugfs) : skip LDO2 test, always on!!!\n"); return 0; } NvRmPmuGetVoltage(s_hRmGlobal, con->AddressList[ldo_number].Address, &millivolts); if(val){ if(millivolts){ printk("PMIC(debugfs) : LDO%d already turned on\n" , ldo_number+1); return 0; } NvRmPmuGetCapabilities(s_hRmGlobal, con->AddressList[ldo_number].Address, &rail); for(j=MAX_REFCOUNT_LOOP;j>powerRefCount[ldo_number];j--){ NvRmPmuSetVoltage(s_hRmGlobal, con->AddressList[ldo_number].Address, rail.requestMilliVolts, &settling_time); } printk("PMIC(debugfs) : LDO%d turn on\n", ldo_number+1); //udelay(settling_time); }else{ if(!millivolts){ printk("PMIC(debugfs) : LDO%d already turned off\n", ldo_number+1); return 0; } while(millivolts && loop_count--){ NvRmPmuSetVoltage(s_hRmGlobal, con->AddressList[ldo_number].Address, NVODM_VOLTAGE_OFF, &settling_time); NvRmPmuGetVoltage(s_hRmGlobal, con->AddressList[ldo_number].Address, &millivolts); if(!millivolts){ powerRefCount[ldo_number]=loop_count; printk("PMIC(debugfs) : LDO%d turn off\n", ldo_number+1); } } //udelay(settling_time); } return 0; }
static int vib_init( ) { const NvOdmPeripheralConnectivity *pcon; int err; NvBool found_gpio = NV_FALSE; int loop; g_vib = kzalloc( sizeof(*g_vib), GFP_KERNEL ); if ( g_vib == NULL ) { err = -1; printk( "[%s] fail vib\n", __func__ ); return err; } pcon = ( NvOdmPeripheralConnectivity* ) NvOdmPeripheralGetGuid( NV_ODM_GUID('v','i','b','r','a','t','o','r') ); for ( loop=0; loop< pcon->NumAddress; loop++ ) { switch ( pcon->AddressList[loop].Interface ) { case NvOdmIoModule_Gpio: g_vib->en_port = pcon->AddressList[loop].Instance; g_vib->en_pin = pcon->AddressList[loop].Address; found_gpio = NV_TRUE; break; case NvOdmIoModule_Vdd: g_vib->vdd_id = pcon->AddressList[loop].Address; DbgOut(( "VIB POWER %d\n", g_vib->vdd_id )); if ( vib_set_power_rail( g_vib->vdd_id, NV_TRUE) != 0 ) return -ENOSYS; break; default: break; } // end of switch } // end of for DbgOut(( "[ImmVibeSPI][%s] : vibrator Int Port = %c, Int Pin = %d\n", __func__, (g_vib->en_port+'a'), g_vib->en_pin )); g_vib->h_vib_gpio = NvOdmGpioOpen( ); if( ! g_vib->h_vib_gpio ) { printk( "[ImmVibeSPI][%s] : Failed to open gpio\n", __func__ ); err = - ENOSYS; return err; } #ifdef MACH_STAR_REV_A g_vib->en_port = 'u' - 'a'; g_vib->en_pin = 5; #endif #if defined ( CONFIG_MACH_STAR ) g_vib->en_port = 'u' - 'a'; g_vib->en_pin = 4; #endif g_vib->h_vib_gpio_pin = NvOdmGpioAcquirePinHandle( g_vib->h_vib_gpio, g_vib->en_port, g_vib->en_pin ); if ( ! g_vib->h_vib_gpio_pin ) { printk( "[ImmVibeSPI][%s] : Failed to acquire the pin handle\n", __func__ ); err = -ENOSYS; return err; } g_vib->hOdmPwm = NvOdmPwmOpen( ); if ( ! g_vib->hOdmPwm ) { printk( "[ImmVibeSPI][%s] : Failed to acquire the PWM handle\n", __func__ ); err = - ENOSYS; return err; } return 0; }
NvBool VIBE_TPS658620_I2cWrite8(NvU8 Addr, NvU8 Data) { NvBool RetVal = NV_TRUE; NvU8 WriteBuffer[2]; NvOdmI2cStatus status = NvOdmI2cStatus_Success; NvOdmI2cTransactionInfo TransactionInfo; NvU32 DeviceAddr = (NvU32)TPS658620_DEVICE_ADDR; NvU32 i = 0; NvOdmIoModule I2cModule = NvOdmIoModule_I2c; NvU32 I2cInstance = 0; NvU32 I2cAddress = 0; const NvOdmPeripheralConnectivity *pConnectivity = NvOdmPeripheralGetGuid(NV_ODM_GUID('t','p','s','6','5','8','6','x')); for (i = 0; i < pConnectivity->NumAddress; i ++) { if (pConnectivity->AddressList[i].Interface == NvOdmIoModule_I2c_Pmu) { I2cModule = NvOdmIoModule_I2c_Pmu; I2cInstance = pConnectivity->AddressList[i].Instance; I2cAddress = pConnectivity->AddressList[i].Address; break; } } s_hOdmI2c = NvOdmI2cOpen(I2cModule, I2cInstance); if (!s_hOdmI2c) { RetVal = NV_FALSE; goto VIBE_TPS658620_I2cWrite8_exit; } DEBUG_VIBRATOR_TRACE(("[VIBE] : Open vibrate I2C success!\n")); WriteBuffer[0] = Addr & 0xFF; // PMU offset //modify by ,set DPWM_MODE=0, fixed freq=250Hz ,duty cycle=0~127 //WriteBuffer[1] = Data & 0xFF; // written data WriteBuffer[1] = Data & 0x7F; // written data TransactionInfo.Address = DeviceAddr; TransactionInfo.Buf = WriteBuffer; TransactionInfo.Flags = NVODM_I2C_IS_WRITE; TransactionInfo.NumBytes = 2; status = NvOdmI2cTransaction(s_hOdmI2c, &TransactionInfo, 1, TPS658620_I2C_SPEED_KHZ, NV_WAIT_INFINITE); if (status == NvOdmI2cStatus_Success) { RetVal = NV_TRUE; DEBUG_VIBRATOR_TRACE(("[VIBE] : Write vibrate I2C success!\n")); } else { RetVal = NV_FALSE; goto VIBE_TPS658620_I2cWrite8_exit; DEBUG_VIBRATOR_TRACE(("[VIBE] : Write vibrate I2C fail!\n")); } NvOdmI2cClose(s_hOdmI2c); s_hOdmI2c = NULL; return RetVal; VIBE_TPS658620_I2cWrite8_exit: DEBUG_VIBRATOR_TRACE(("[VIBE] : Open or Write vibrate I2C fail!\n")); NvOdmI2cClose(s_hOdmI2c); s_hOdmI2c = NULL; return RetVal; }
//----------------------------------------------------------------- //--------------------------------New API-------------------------- //----------------------------------------------------------------- NvBool NvOdmAccelOpen(NvOdmAccelHandle* hDevice) { NvU32 test_val; NvU32 i; NvBool foundGpio = NV_FALSE, foundI2cModule = NV_FALSE; const NvOdmPeripheralConnectivity *pConnectivity; NvOdmAccelHandle hAccel; hAccel = NvOdmOsAlloc(sizeof(NvOdmAccel)); if (hAccel == NULL) { //NVODMACCELEROMETER_PRINTF("Error Allocating NvOdmAccel. \n"); return NV_FALSE; } NvOdmOsMemset(hAccel, 0, sizeof(NvOdmAccel)); hAccel->hPmu = NULL; hAccel->hOdmI2C = NULL; hAccel->nBusType = NV_ACCELEROMETER_BUS_I2C; // Chip init cfg info here, here just a sample for common interrupt now! // This part will move to a configuration table later. // Start here. // Only enable common interrupt // Enable common and single tap at the same time. hAccel->CtrlRegsList[0].RegAddr = XLR_CTL; //0x12 hAccel->CtrlRegsList[0].RegValue = 0x20; hAccel->CtrlRegsList[1].RegAddr = XLR_INTCONTROL; //0x13 hAccel->CtrlRegsList[1].RegValue = 0xF3; // modify so that sw is compatible hAccel->CtrlRegsList[2].RegAddr = XLR_INTCONTROL2; //0x14 hAccel->CtrlRegsList[2].RegValue = 0xe0; hAccel->CtrlRegsList[3].RegAddr = XLR_THRESHG; //0x1C hAccel->CtrlRegsList[3].RegValue = NV_ADI340_ACCELEROMETER_NORMAL_THRESHOLD; hAccel->CtrlRegsList[4].RegAddr = XLR_OFSX; //0x1E hAccel->CtrlRegsList[4].RegValue = 0; hAccel->CtrlRegsList[5].RegAddr = XLR_OFSY; //0x1F hAccel->CtrlRegsList[5].RegValue = 0; hAccel->CtrlRegsList[6].RegAddr = XLR_OFSZ; //0x20 hAccel->CtrlRegsList[6].RegValue = 0; hAccel->CtrlRegsList[7].RegAddr = XLR_THRESHC; //0x1D hAccel->CtrlRegsList[7].RegValue = NV_ADI340_ACCELEROMETER_TAP_THRESHOLD; hAccel->CtrlRegsList[8].RegAddr = XLR_DUR; //0x21 hAccel->CtrlRegsList[8].RegValue = 0x40; hAccel->CtrlRegsList[9].RegAddr = XLR_LATENT; //0x22 hAccel->CtrlRegsList[9].RegValue = 0xff; hAccel->CtrlRegsList[10].RegAddr = XLR_INTVL; //0x23 hAccel->CtrlRegsList[10].RegValue = 0; hAccel->CtrlRegsList[11].RegAddr = XLR_INTCONTROL2; //0x14 hAccel->CtrlRegsList[11].RegValue = 0xe1; hAccel->CtrlRegsList[12].RegAddr = XLR_INTCONTROL2; //0x14 hAccel->CtrlRegsList[12].RegValue = 0xe0; hAccel->nLength = 13; // Stop here. // Info of accelerometer with current setting. hAccel->Caption.MaxForceInGs = 2000; hAccel->Caption.MaxTapTimeDeltaInUs = 255; hAccel->Caption.NumMotionThresholds = 1; hAccel->Caption.SupportsFreefallInt = 0; hAccel->Caption.MaxSampleRate = 100; hAccel->Caption.MinSampleRate = 3; hAccel->PowerState = NvOdmAccelPower_Fullrun; hAccel->AxisXMapping = NvOdmAccelAxis_X; hAccel->AxisXDirection = 1; hAccel->AxisYMapping = NvOdmAccelAxis_Y; hAccel->AxisYDirection = 1; hAccel->AxisZMapping = NvOdmAccelAxis_Z; hAccel->AxisZDirection = -1; hAccel->hPmu = NvOdmServicesPmuOpen(); if (!hAccel->hPmu) { //NVODMACCELEROMETER_PRINTF("NvOdmServicesPmuOpen Error \n"); goto error; } pConnectivity = (NvOdmPeripheralConnectivity*)NvOdmPeripheralGetGuid(NV_ODM_GUID('a','c','c','e','l','e','r','o')); if (!pConnectivity) { NvOdmOsDebugPrintf("NvOdmPeripheralGetGuid doesn't detect accelerometer device\n"); goto error; } if(pConnectivity->Class != NvOdmPeripheralClass_Other) { goto error; } for( i = 0; i < pConnectivity->NumAddress; i++) { switch(pConnectivity->AddressList[i].Interface) { case NvOdmIoModule_I2c: hAccel->I2CChannelId = pConnectivity->AddressList[i].Instance; hAccel->nDevAddr = (NvU8)pConnectivity->AddressList[i].Address; foundI2cModule = NV_TRUE; break; case NvOdmIoModule_Gpio: hAccel->GPIOPortINT = pConnectivity->AddressList[i].Instance; hAccel->GPIOPinINT = pConnectivity->AddressList[i].Address; foundGpio = NV_TRUE; break; case NvOdmIoModule_Vdd: hAccel->VddId = pConnectivity->AddressList[i].Address; // Power on accelerometer according to Vddid NvAccelerometerSetPowerRail(hAccel->hPmu, hAccel->VddId, NV_TRUE); break; default: break; } } if(foundGpio != NV_TRUE || foundI2cModule != NV_TRUE) { //NVODMACCELEROMETER_PRINTF("Accelerometer : didn't find any periperal in discovery query for touch device Error \n"); goto error; } // Set up I2C bus. if(NV_FALSE == NvAccelerometerI2COpen(&hAccel->hOdmI2C, hAccel->I2CChannelId)) { goto error; }; hAccel->RegsRead = NvAccelerometerI2CGetRegs; hAccel->RegsWrite = NvAccelerometerI2CSetRegs; NvOdmAccelerometerGetParameter(hAccel, XLR_WHOAMI, &test_val); if(XLR_IDNUM != test_val) { goto error; } NvOdmAccelerometerGetParameter(hAccel, XLR_DEVID, &test_val); if (test_val == XLR_NEWCHIPID) { // This chip is ADXL345 //NvOdmOsDebugPrintf("This chip is ADXL345!!!\n"); hAccel->CtrlRegsList[4].RegValue = 0x0A; // offset X hAccel->CtrlRegsList[5].RegValue = 0x0B; // offset Y hAccel->CtrlRegsList[6].RegValue = 0x14; // offset Z } //NVODMACCELEROMETER_PRINTF("ID is 0x%x\n", test_val); /* We don't know the reset state of the accelerometer. So, program the * accelerometer to disable generation of interrupts. * * Write to INTCONTROL register to disable genetration of the interrupts. * Write to INTCONTROL2 to clear the already latched interrupts. */ NvOdmAccelerometerSetParameter(hAccel, XLR_ATTR_INTCONTROL, 0x0); NvOdmAccelerometerSetParameter(hAccel, XLR_ATTR_INTCONTROL2, 0x1); if(NV_FALSE == NvAccelerometerConnectSemaphore(hAccel)) { goto error; } //init accelerometer for(i=0; i<hAccel->nLength; i++) { NvOdmAccelerometerSetParameter(hAccel, hAccel->CtrlRegsList[i].RegAddr, hAccel->CtrlRegsList[i].RegValue); } // Set up event. //NvOdmAccelerometerGetParameter(XLR_SCALE, hAccel); *hDevice = hAccel; return NV_TRUE; error: // Release all of resources requested. if(NULL != hAccel) { NvAccelerometerSetPowerRail(hAccel->hPmu, hAccel->VddId, NV_FALSE); NvOdmServicesPmuClose(hAccel->hPmu); hAccel->hPmu = NULL; NvAccelerometerI2CClose(hAccel->hOdmI2C); hAccel->hOdmI2C = NULL; NvOdmOsFree(hAccel); *hDevice = NULL; } return NV_FALSE; }