Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2009 NVIDIA Corporation.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of the NVIDIA Corporation nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- */
- #define NV_IDL_IS_DISPATCH
- #include <linux/kernel.h> //printk
- #include "nvcommon.h"
- #include "nvos.h"
- #include "nvassert.h"
- #include "nvreftrack.h"
- #include "nvidlcmd.h"
- #include "nvrm_i2c.h"
- #define OFFSET( s, e ) (NvU32)(void *)(&(((s*)0)->e))
- typedef struct NvRmI2cTransaction_in_t
- {
- NvU32 package_; // what?
- NvU32 function_; // what's this?
- NvRmI2cHandle hI2c; // address in here?
- NvU32 I2cPinMap; // hmm, maybe
- NvU32 WaitTimeoutInMilliSeconds; // ok
- NvU32 ClockSpeedKHz; // interesting, but won't need it for long
- NvU8 * Data; // interesting
- NvU32 DataLen; // sure, ok
- NvRmI2cTransactionInfo * Transaction; // what's this?
- NvU32 NumOfTransactions; // ok, sure. Why not.
- } NV_ALIGN(4) NvRmI2cTransaction_in;
- typedef struct NvRmI2cTransaction_inout_t
- {
- NvU32 dummy_;
- } NV_ALIGN(4) NvRmI2cTransaction_inout;
- typedef struct NvRmI2cTransaction_out_t
- {
- NvError ret_;
- } NV_ALIGN(4) NvRmI2cTransaction_out;
- typedef struct NvRmI2cTransaction_params_t
- {
- NvRmI2cTransaction_in in;
- NvRmI2cTransaction_inout inout;
- NvRmI2cTransaction_out out;
- } NvRmI2cTransaction_params;
- typedef struct NvRmI2cClose_in_t
- {
- NvU32 package_;
- NvU32 function_;
- NvRmI2cHandle hI2c;
- } NV_ALIGN(4) NvRmI2cClose_in;
- typedef struct NvRmI2cClose_inout_t
- {
- NvU32 dummy_;
- } NV_ALIGN(4) NvRmI2cClose_inout;
- typedef struct NvRmI2cClose_out_t
- {
- NvU32 dummy_;
- } NV_ALIGN(4) NvRmI2cClose_out;
- typedef struct NvRmI2cClose_params_t
- {
- NvRmI2cClose_in in;
- NvRmI2cClose_inout inout;
- NvRmI2cClose_out out;
- } NvRmI2cClose_params;
- typedef struct NvRmI2cOpen_in_t
- {
- NvU32 package_;
- NvU32 function_;
- NvRmDeviceHandle hDevice;
- NvU32 IoModule;
- NvU32 instance;
- } NV_ALIGN(4) NvRmI2cOpen_in;
- typedef struct NvRmI2cOpen_inout_t
- {
- NvU32 dummy_;
- } NV_ALIGN(4) NvRmI2cOpen_inout;
- typedef struct NvRmI2cOpen_out_t
- {
- NvError ret_;
- NvRmI2cHandle phI2c;
- } NV_ALIGN(4) NvRmI2cOpen_out;
- typedef struct NvRmI2cOpen_params_t
- {
- NvRmI2cOpen_in in;
- NvRmI2cOpen_inout inout;
- NvRmI2cOpen_out out;
- } NvRmI2cOpen_params;
- bool flash_read = 0;
- static NvError NvRmI2cTransaction_dispatch_( void *InBuffer, NvU32 InSize, void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx )
- {
- NvError err_ = NvSuccess;
- NvRmI2cTransaction_in *p_in;
- NvRmI2cTransaction_out *p_out;
- NvU8 *Data = NULL;
- NvRmI2cTransactionInfo *Transaction = NULL;
- bool print_data, print_read;
- int thing;
- NvU32 i2c_address; // the i2c device address
- p_in = (NvRmI2cTransaction_in *)InBuffer;
- p_out = (NvRmI2cTransaction_out *)((NvU8 *)OutBuffer + OFFSET(NvRmI2cTransaction_params, out) - OFFSET(NvRmI2cTransaction_params, inout));
- i2c_address = p_in->Transaction->Address;
- i2c_address = i2c_address >> 1;
- if( p_in->DataLen && p_in->Data )
- {
- Data = (NvU8 *)NvOsAlloc( p_in->DataLen * sizeof( NvU8 ) );
- if( !Data )
- {
- err_ = NvError_InsufficientMemory;
- goto clean;
- }
- if( p_in->Data )
- {
- err_ = NvOsCopyIn( Data, p_in->Data, p_in->DataLen * sizeof( NvU8 ) );
- if( err_ != NvSuccess )
- {
- err_ = NvError_BadParameter;
- goto clean;
- }
- }
- }
- if( p_in->NumOfTransactions && p_in->Transaction )
- {
- Transaction = (NvRmI2cTransactionInfo *)NvOsAlloc( p_in->NumOfTransactions * sizeof( NvRmI2cTransactionInfo ) );
- if( !Transaction )
- {
- err_ = NvError_InsufficientMemory;
- goto clean;
- }
- if( p_in->Transaction )
- {
- err_ = NvOsCopyIn( Transaction, p_in->Transaction, p_in->NumOfTransactions * sizeof( NvRmI2cTransactionInfo ) );
- if( err_ != NvSuccess )
- {
- err_ = NvError_BadParameter;
- goto clean;
- }
- }
- }
- print_data = 0; // whether or not to print out using the "for" loop
- print_read = 1; // print out read requests and read values?
- /* note that these addresses are only for Olympus. Any devices not using the same cameras
- * will likely have different addresses.
- *
- * cat /proc/kmsg | grep Thingie
- */
- switch(i2c_address) {
- /* front camera */
- case 0x3d:
- printk (KERN_INFO "Thingie: front cam: 0x%x",i2c_address);
- print_data = 1;
- break;
- /* rear camera */
- case 0x36:
- // The camera regisers are 16 bit addresses
- if (p_in->DataLen == 3){
- //printk (KERN_INFO "Thingie: i2cset -y 2 0x36 0x%x 0x%x 0x%x i", Data[0], Data[1], Data[2]);
- // This would be to format for drivers (untested)
- printk (KERN_INFO "Thingie: OV5650 {0x%4x, 0x%2x}", (int)Data[0] << 8 | Data[1], Data[2]);
- print_data = 0;
- }
- // This is for bulk transfers
- else if (p_in->DataLen > 3){
- //printk (KERN_INFO "Thingie rear cam: 0x%x", i2c_address);
- printk (KERN_INFO "# Thingie: Starting rear camera bulk transfer length: %d", p_in->DataLen);
- for (thing=0; thing< p_in->DataLen; thing+=3)
- {
- //printk (KERN_INFO "Thingie: i2cset -y 2 0x36 0x%x 0x%x 0x%x i", Data[thing], Data[thing + 1], Data[thing + 2]);
- printk (KERN_INFO "Thingie: OV5650 {0x%4x, 0x%2x}", (int)Data[thing] << 8 | Data[thing + 1], Data[thing + 2]);
- }
- printk (KERN_INFO "# Thingie: Finished bulk transfer");
- print_data = 0;
- }
- // a length of 2 indicates a read transaction
- // a length of 1 will follow the read transaction and is the actual value being read back
- else if ((p_in->DataLen == 2) && print_read){
- printk (KERN_INFO "# Thingie: Sending read request to rear camera");
- printk (KERN_INFO "Thingie: i2cset -y 2 0x36 0x%2x 0x%2x", Data[0], Data[1]);
- print_data = 0;
- }
- break;
- /* camera flash */
- case 0x53:
- if (p_in->DataLen == 2){
- printk (KERN_INFO "Thingie: i2cset -y 2 0x53 0x%2x 0x%2x", Data[0], Data[1]);
- print_data = 0;
- }
- else if (!flash_read) {
- printk (KERN_INFO "# Thingie: Sending read request to camera flash");
- printk (KERN_INFO "Thingie: i2cset -y 2 0x53 0x%2x", Data[0]);
- print_data = 1;
- flash_read = 1;
- }
- break;
- /* focuser */
- case 0x0c:
- //printk (KERN_INFO "Thingie focuser: 0x%x",i2c_address);
- print_data = 0; // too spammy right now
- break;
- /* only happens during probing on power up */
- default:
- // not much to see here
- // printk (KERN_INFO "Thingie: probing i2c address: 0x%2x",i2c_address);
- print_data = 0;
- break;
- }
- if ((print_data) && (p_in->DataLen > 1)){
- //printk (KERN_INFO "Thingie sizeof (Data): %d",sizeof(Data) );
- printk (KERN_INFO "Thingie: p_in->DataLen: %d",p_in->DataLen );
- //printk (KERN_INFO "Thingie Data: %d",Data);
- //for (thing=0; thing< sizeof(Data); thing++)
- for (thing=0; thing< p_in->DataLen; thing++)
- {
- printk (KERN_INFO "Thingie: Data[%d]: 0x%2x",thing, Data[thing]);
- }
- }
- // this is where the transaction actually takes place
- p_out->ret_ = NvRmI2cTransaction( p_in->hI2c, p_in->I2cPinMap, p_in->WaitTimeoutInMilliSeconds, p_in->ClockSpeedKHz, Data, p_in->DataLen, Transaction, p_in->NumOfTransactions );
- if ((p_in->DataLen == 1) && (print_read || flash_read)){
- printk (KERN_INFO "# Thingie: read value 0x%2x", Data[0]);
- printk (KERN_INFO "# Thingie: Finished read request");
- flash_read = 0;
- }
- if(p_in->Data && Data)
- {
- err_ = NvOsCopyOut( p_in->Data, Data, p_in->DataLen * sizeof( NvU8 ) );
- if( err_ != NvSuccess )
- {
- err_ = NvError_BadParameter;
- }
- }
- clean:
- NvOsFree( Data );
- NvOsFree( Transaction );
- return err_;
- }
- static NvError NvRmI2cClose_dispatch_( void *InBuffer, NvU32 InSize, void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx )
- {
- NvError err_ = NvSuccess;
- NvRmI2cClose_in *p_in;
- p_in = (NvRmI2cClose_in *)InBuffer;
- NvRtFreeObjRef(Ctx, NvRtObjType_NvRm_NvRmI2cHandle, p_in->hI2c);
- NvRmI2cClose( p_in->hI2c );
- return err_;
- }
- static NvError NvRmI2cOpen_dispatch_( void *InBuffer, NvU32 InSize, void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx )
- {
- NvError err_ = NvSuccess;
- NvRmI2cOpen_in *p_in;
- NvRmI2cOpen_out *p_out;
- NvRtObjRefHandle ref_phI2c = 0;
- p_in = (NvRmI2cOpen_in *)InBuffer;
- p_out = (NvRmI2cOpen_out *)((NvU8 *)OutBuffer + OFFSET(NvRmI2cOpen_params, out) - OFFSET(NvRmI2cOpen_params, inout));
- p_out->ret_ = NvRmI2cOpen( p_in->hDevice, p_in->IoModule, p_in->instance, &p_out->phI2c );
- if (p_out->ret_ != NvSuccess)
- {
- err_ = p_out->ret_;
- goto clean;
- }
- err_ = NvRtAllocObjRef(Ctx, &ref_phI2c);
- if (err_ == NvSuccess)
- {
- NvRtStoreObjRef(Ctx, ref_phI2c, NvRtObjType_NvRm_NvRmI2cHandle, p_out->phI2c);
- }
- else
- {
- NvRmI2cClose(p_out->phI2c);
- }
- clean:
- return err_;
- }
- NvError nvrm_i2c_Dispatch( NvU32 function, void *InBuffer, NvU32 InSize, void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx );
- NvError nvrm_i2c_Dispatch( NvU32 function, void *InBuffer, NvU32 InSize, void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx )
- {
- NvError err_ = NvSuccess;
- switch( function ) {
- case 2:
- err_ = NvRmI2cTransaction_dispatch_( InBuffer, InSize, OutBuffer, OutSize, Ctx );
- break;
- case 1:
- err_ = NvRmI2cClose_dispatch_( InBuffer, InSize, OutBuffer, OutSize, Ctx );
- break;
- case 0:
- err_ = NvRmI2cOpen_dispatch_( InBuffer, InSize, OutBuffer, OutSize, Ctx );
- break;
- default:
- err_ = NvError_BadParameter;
- break;
- }
- return err_;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement