Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * |
| 3 | * Copyright (c) 2007 by Silicon Motion, Inc. (SMI) |
| 4 | * |
| 5 | * All rights are reserved. Reproduction or in part is prohibited |
| 6 | * without the written consent of the copyright owner. |
| 7 | * |
| 8 | * swi2c.h --- SM750/SM718 DDK |
| 9 | * This file contains the definitions for i2c using software |
| 10 | * implementation. |
| 11 | * |
| 12 | *******************************************************************/ |
| 13 | #ifndef _SWI2C_H_ |
| 14 | #define _SWI2C_H_ |
| 15 | |
| 16 | /* Default i2c CLK and Data GPIO. These are the default i2c pins */ |
| 17 | #define DEFAULT_I2C_SCL 30 |
| 18 | #define DEFAULT_I2C_SDA 31 |
| 19 | |
| 20 | /* |
| 21 | * This function initializes the i2c attributes and bus |
| 22 | * |
| 23 | * Parameters: |
| 24 | * i2cClkGPIO - The GPIO pin to be used as i2c SCL |
| 25 | * i2cDataGPIO - The GPIO pin to be used as i2c SDA |
| 26 | * |
| 27 | * Return Value: |
| 28 | * -1 - Fail to initialize the i2c |
| 29 | * 0 - Success |
| 30 | */ |
Mike Rapoport | f2ea773 | 2015-09-12 11:07:38 +0300 | [diff] [blame] | 31 | long sm750_sw_i2c_init( |
Mike Rapoport | fe82004 | 2015-09-12 11:07:47 +0300 | [diff] [blame] | 32 | unsigned char clk_gpio, |
| 33 | unsigned char data_gpio |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 34 | ); |
| 35 | |
| 36 | /* |
| 37 | * This function reads the slave device's register |
| 38 | * |
| 39 | * Parameters: |
Mike Rapoport | fe82004 | 2015-09-12 11:07:47 +0300 | [diff] [blame] | 40 | * addr - i2c Slave device address which register |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 41 | * to be read from |
Mike Rapoport | fe82004 | 2015-09-12 11:07:47 +0300 | [diff] [blame] | 42 | * reg - Slave device's register to be read |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 43 | * |
| 44 | * Return Value: |
| 45 | * Register value |
| 46 | */ |
Mike Rapoport | 288836b | 2015-09-12 11:07:39 +0300 | [diff] [blame] | 47 | unsigned char sm750_sw_i2c_read_reg( |
Mike Rapoport | fe82004 | 2015-09-12 11:07:47 +0300 | [diff] [blame] | 48 | unsigned char addr, |
| 49 | unsigned char reg |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 50 | ); |
| 51 | |
| 52 | /* |
| 53 | * This function writes a value to the slave device's register |
| 54 | * |
| 55 | * Parameters: |
Mike Rapoport | fe82004 | 2015-09-12 11:07:47 +0300 | [diff] [blame] | 56 | * addr - i2c Slave device address which register |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 57 | * to be written |
Mike Rapoport | fe82004 | 2015-09-12 11:07:47 +0300 | [diff] [blame] | 58 | * reg - Slave device's register to be written |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 59 | * data - Data to be written to the register |
| 60 | * |
| 61 | * Result: |
| 62 | * 0 - Success |
| 63 | * -1 - Fail |
| 64 | */ |
Mike Rapoport | d33b420 | 2015-09-12 11:07:40 +0300 | [diff] [blame] | 65 | long sm750_sw_i2c_write_reg( |
Mike Rapoport | fe82004 | 2015-09-12 11:07:47 +0300 | [diff] [blame] | 66 | unsigned char addr, |
| 67 | unsigned char reg, |
Isaac Assegai | bf36fa2 | 2015-06-18 21:48:50 -0700 | [diff] [blame] | 68 | unsigned char data |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 69 | ); |
| 70 | |
Sudip Mukherjee | 81dee67 | 2015-03-03 16:21:06 +0530 | [diff] [blame] | 71 | #endif /* _SWI2C_H_ */ |