diff options
| -rw-r--r-- | Documentation/i2c/busses/i2c-viapro | 8 | ||||
| -rw-r--r-- | Documentation/i2c/dev-interface | 110 | ||||
| -rw-r--r-- | Documentation/i2c/smbus-protocol | 4 | ||||
| -rw-r--r-- | Documentation/i2c/writing-clients | 4 | ||||
| -rw-r--r-- | arch/arm/mach-omap1/board-h3.c | 4 | ||||
| -rw-r--r-- | arch/arm/mach-omap2/board-h4.c | 11 | ||||
| -rw-r--r-- | drivers/hwmon/dme1737.c | 320 | ||||
| -rw-r--r-- | drivers/i2c/busses/Kconfig | 20 | ||||
| -rw-r--r-- | drivers/i2c/busses/Makefile | 1 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-highlander.c | 498 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-parport-light.c | 39 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-pca-isa.c | 20 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-viapro.c | 17 | ||||
| -rw-r--r-- | drivers/i2c/chips/isp1301_omap.c | 141 | ||||
| -rw-r--r-- | drivers/i2c/chips/tps65010.c | 12 | ||||
| -rw-r--r-- | drivers/i2c/i2c-core.c | 35 |
16 files changed, 918 insertions, 326 deletions
diff --git a/Documentation/i2c/busses/i2c-viapro b/Documentation/i2c/busses/i2c-viapro index 1405fb69984c..22efedf60c87 100644 --- a/Documentation/i2c/busses/i2c-viapro +++ b/Documentation/i2c/busses/i2c-viapro | |||
| @@ -16,6 +16,9 @@ Supported adapters: | |||
| 16 | * VIA Technologies, Inc. CX700 | 16 | * VIA Technologies, Inc. CX700 |
| 17 | Datasheet: available on request and under NDA from VIA | 17 | Datasheet: available on request and under NDA from VIA |
| 18 | 18 | ||
| 19 | * VIA Technologies, Inc. VX800/VX820 | ||
| 20 | Datasheet: available on http://linux.via.com.tw | ||
| 21 | |||
| 19 | Authors: | 22 | Authors: |
| 20 | Kyösti Mälkki <kmalkki@cc.hut.fi>, | 23 | Kyösti Mälkki <kmalkki@cc.hut.fi>, |
| 21 | Mark D. Studebaker <mdsxyz123@yahoo.com>, | 24 | Mark D. Studebaker <mdsxyz123@yahoo.com>, |
| @@ -49,6 +52,7 @@ Your lspci -n listing must show one of these : | |||
| 49 | device 1106:3372 (VT8237S) | 52 | device 1106:3372 (VT8237S) |
| 50 | device 1106:3287 (VT8251) | 53 | device 1106:3287 (VT8251) |
| 51 | device 1106:8324 (CX700) | 54 | device 1106:8324 (CX700) |
| 55 | device 1106:8353 (VX800/VX820) | ||
| 52 | 56 | ||
| 53 | If none of these show up, you should look in the BIOS for settings like | 57 | If none of these show up, you should look in the BIOS for settings like |
| 54 | enable ACPI / SMBus or even USB. | 58 | enable ACPI / SMBus or even USB. |
| @@ -57,5 +61,5 @@ Except for the oldest chips (VT82C596A/B, VT82C686A and most probably | |||
| 57 | VT8231), this driver supports I2C block transactions. Such transactions | 61 | VT8231), this driver supports I2C block transactions. Such transactions |
| 58 | are mainly useful to read from and write to EEPROMs. | 62 | are mainly useful to read from and write to EEPROMs. |
| 59 | 63 | ||
| 60 | The CX700 additionally appears to support SMBus PEC, although this driver | 64 | The CX700/VX800/VX820 additionally appears to support SMBus PEC, although |
| 61 | doesn't implement it yet. | 65 | this driver doesn't implement it yet. |
diff --git a/Documentation/i2c/dev-interface b/Documentation/i2c/dev-interface index 9dd79123ddd9..3e742ba25536 100644 --- a/Documentation/i2c/dev-interface +++ b/Documentation/i2c/dev-interface | |||
| @@ -4,6 +4,10 @@ the /dev interface. You need to load module i2c-dev for this. | |||
| 4 | 4 | ||
| 5 | Each registered i2c adapter gets a number, counting from 0. You can | 5 | Each registered i2c adapter gets a number, counting from 0. You can |
| 6 | examine /sys/class/i2c-dev/ to see what number corresponds to which adapter. | 6 | examine /sys/class/i2c-dev/ to see what number corresponds to which adapter. |
| 7 | Alternatively, you can run "i2cdetect -l" to obtain a formated list of all | ||
| 8 | i2c adapters present on your system at a given time. i2cdetect is part of | ||
| 9 | the i2c-tools package. | ||
| 10 | |||
| 7 | I2C device files are character device files with major device number 89 | 11 | I2C device files are character device files with major device number 89 |
| 8 | and a minor device number corresponding to the number assigned as | 12 | and a minor device number corresponding to the number assigned as |
| 9 | explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ..., | 13 | explained above. They should be called "i2c-%d" (i2c-0, i2c-1, ..., |
| @@ -17,30 +21,34 @@ So let's say you want to access an i2c adapter from a C program. The | |||
| 17 | first thing to do is "#include <linux/i2c-dev.h>". Please note that | 21 | first thing to do is "#include <linux/i2c-dev.h>". Please note that |
| 18 | there are two files named "i2c-dev.h" out there, one is distributed | 22 | there are two files named "i2c-dev.h" out there, one is distributed |
| 19 | with the Linux kernel and is meant to be included from kernel | 23 | with the Linux kernel and is meant to be included from kernel |
| 20 | driver code, the other one is distributed with lm_sensors and is | 24 | driver code, the other one is distributed with i2c-tools and is |
| 21 | meant to be included from user-space programs. You obviously want | 25 | meant to be included from user-space programs. You obviously want |
| 22 | the second one here. | 26 | the second one here. |
| 23 | 27 | ||
| 24 | Now, you have to decide which adapter you want to access. You should | 28 | Now, you have to decide which adapter you want to access. You should |
| 25 | inspect /sys/class/i2c-dev/ to decide this. Adapter numbers are assigned | 29 | inspect /sys/class/i2c-dev/ or run "i2cdetect -l" to decide this. |
| 26 | somewhat dynamically, so you can not even assume /dev/i2c-0 is the | 30 | Adapter numbers are assigned somewhat dynamically, so you can not |
| 27 | first adapter. | 31 | assume much about them. They can even change from one boot to the next. |
| 28 | 32 | ||
| 29 | Next thing, open the device file, as follows: | 33 | Next thing, open the device file, as follows: |
| 34 | |||
| 30 | int file; | 35 | int file; |
| 31 | int adapter_nr = 2; /* probably dynamically determined */ | 36 | int adapter_nr = 2; /* probably dynamically determined */ |
| 32 | char filename[20]; | 37 | char filename[20]; |
| 33 | 38 | ||
| 34 | sprintf(filename,"/dev/i2c-%d",adapter_nr); | 39 | snprintf(filename, 19, "/dev/i2c-%d", adapter_nr); |
| 35 | if ((file = open(filename,O_RDWR)) < 0) { | 40 | file = open(filename, O_RDWR); |
| 41 | if (file < 0) { | ||
| 36 | /* ERROR HANDLING; you can check errno to see what went wrong */ | 42 | /* ERROR HANDLING; you can check errno to see what went wrong */ |
| 37 | exit(1); | 43 | exit(1); |
| 38 | } | 44 | } |
| 39 | 45 | ||
| 40 | When you have opened the device, you must specify with what device | 46 | When you have opened the device, you must specify with what device |
| 41 | address you want to communicate: | 47 | address you want to communicate: |
| 48 | |||
| 42 | int addr = 0x40; /* The I2C address */ | 49 | int addr = 0x40; /* The I2C address */ |
| 43 | if (ioctl(file,I2C_SLAVE,addr) < 0) { | 50 | |
| 51 | if (ioctl(file, I2C_SLAVE, addr) < 0) { | ||
| 44 | /* ERROR HANDLING; you can check errno to see what went wrong */ | 52 | /* ERROR HANDLING; you can check errno to see what went wrong */ |
| 45 | exit(1); | 53 | exit(1); |
| 46 | } | 54 | } |
| @@ -48,31 +56,41 @@ address you want to communicate: | |||
| 48 | Well, you are all set up now. You can now use SMBus commands or plain | 56 | Well, you are all set up now. You can now use SMBus commands or plain |
| 49 | I2C to communicate with your device. SMBus commands are preferred if | 57 | I2C to communicate with your device. SMBus commands are preferred if |
| 50 | the device supports them. Both are illustrated below. | 58 | the device supports them. Both are illustrated below. |
| 59 | |||
| 51 | __u8 register = 0x10; /* Device register to access */ | 60 | __u8 register = 0x10; /* Device register to access */ |
| 52 | __s32 res; | 61 | __s32 res; |
| 53 | char buf[10]; | 62 | char buf[10]; |
| 63 | |||
| 54 | /* Using SMBus commands */ | 64 | /* Using SMBus commands */ |
| 55 | res = i2c_smbus_read_word_data(file,register); | 65 | res = i2c_smbus_read_word_data(file, register); |
| 56 | if (res < 0) { | 66 | if (res < 0) { |
| 57 | /* ERROR HANDLING: i2c transaction failed */ | 67 | /* ERROR HANDLING: i2c transaction failed */ |
| 58 | } else { | 68 | } else { |
| 59 | /* res contains the read word */ | 69 | /* res contains the read word */ |
| 60 | } | 70 | } |
| 71 | |||
| 61 | /* Using I2C Write, equivalent of | 72 | /* Using I2C Write, equivalent of |
| 62 | i2c_smbus_write_word_data(file,register,0x6543) */ | 73 | i2c_smbus_write_word_data(file, register, 0x6543) */ |
| 63 | buf[0] = register; | 74 | buf[0] = register; |
| 64 | buf[1] = 0x43; | 75 | buf[1] = 0x43; |
| 65 | buf[2] = 0x65; | 76 | buf[2] = 0x65; |
| 66 | if ( write(file,buf,3) != 3) { | 77 | if (write(file, buf, 3) ! =3) { |
| 67 | /* ERROR HANDLING: i2c transaction failed */ | 78 | /* ERROR HANDLING: i2c transaction failed */ |
| 68 | } | 79 | } |
| 80 | |||
| 69 | /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */ | 81 | /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */ |
| 70 | if (read(file,buf,1) != 1) { | 82 | if (read(file, buf, 1) != 1) { |
| 71 | /* ERROR HANDLING: i2c transaction failed */ | 83 | /* ERROR HANDLING: i2c transaction failed */ |
| 72 | } else { | 84 | } else { |
| 73 | /* buf[0] contains the read byte */ | 85 | /* buf[0] contains the read byte */ |
| 74 | } | 86 | } |
| 75 | 87 | ||
| 88 | Note that only a subset of the I2C and SMBus protocols can be achieved by | ||
| 89 | the means of read() and write() calls. In particular, so-called combined | ||
| 90 | transactions (mixing read and write messages in the same transaction) | ||
| 91 | aren't supported. For this reason, this interface is almost never used by | ||
| 92 | user-space programs. | ||
| 93 | |||
| 76 | IMPORTANT: because of the use of inline functions, you *have* to use | 94 | IMPORTANT: because of the use of inline functions, you *have* to use |
| 77 | '-O' or some variation when you compile your program! | 95 | '-O' or some variation when you compile your program! |
| 78 | 96 | ||
| @@ -80,31 +98,29 @@ IMPORTANT: because of the use of inline functions, you *have* to use | |||
| 80 | Full interface description | 98 | Full interface description |
| 81 | ========================== | 99 | ========================== |
| 82 | 100 | ||
| 83 | The following IOCTLs are defined and fully supported | 101 | The following IOCTLs are defined: |
| 84 | (see also i2c-dev.h): | ||
| 85 | 102 | ||
| 86 | ioctl(file,I2C_SLAVE,long addr) | 103 | ioctl(file, I2C_SLAVE, long addr) |
| 87 | Change slave address. The address is passed in the 7 lower bits of the | 104 | Change slave address. The address is passed in the 7 lower bits of the |
| 88 | argument (except for 10 bit addresses, passed in the 10 lower bits in this | 105 | argument (except for 10 bit addresses, passed in the 10 lower bits in this |
| 89 | case). | 106 | case). |
| 90 | 107 | ||
| 91 | ioctl(file,I2C_TENBIT,long select) | 108 | ioctl(file, I2C_TENBIT, long select) |
| 92 | Selects ten bit addresses if select not equals 0, selects normal 7 bit | 109 | Selects ten bit addresses if select not equals 0, selects normal 7 bit |
| 93 | addresses if select equals 0. Default 0. This request is only valid | 110 | addresses if select equals 0. Default 0. This request is only valid |
| 94 | if the adapter has I2C_FUNC_10BIT_ADDR. | 111 | if the adapter has I2C_FUNC_10BIT_ADDR. |
| 95 | 112 | ||
| 96 | ioctl(file,I2C_PEC,long select) | 113 | ioctl(file, I2C_PEC, long select) |
| 97 | Selects SMBus PEC (packet error checking) generation and verification | 114 | Selects SMBus PEC (packet error checking) generation and verification |
| 98 | if select not equals 0, disables if select equals 0. Default 0. | 115 | if select not equals 0, disables if select equals 0. Default 0. |
| 99 | Used only for SMBus transactions. This request only has an effect if the | 116 | Used only for SMBus transactions. This request only has an effect if the |
| 100 | the adapter has I2C_FUNC_SMBUS_PEC; it is still safe if not, it just | 117 | the adapter has I2C_FUNC_SMBUS_PEC; it is still safe if not, it just |
| 101 | doesn't have any effect. | 118 | doesn't have any effect. |
| 102 | 119 | ||
| 103 | ioctl(file,I2C_FUNCS,unsigned long *funcs) | 120 | ioctl(file, I2C_FUNCS, unsigned long *funcs) |
| 104 | Gets the adapter functionality and puts it in *funcs. | 121 | Gets the adapter functionality and puts it in *funcs. |
| 105 | 122 | ||
| 106 | ioctl(file,I2C_RDWR,struct i2c_rdwr_ioctl_data *msgset) | 123 | ioctl(file, I2C_RDWR, struct i2c_rdwr_ioctl_data *msgset) |
| 107 | |||
| 108 | Do combined read/write transaction without stop in between. | 124 | Do combined read/write transaction without stop in between. |
| 109 | Only valid if the adapter has I2C_FUNC_I2C. The argument is | 125 | Only valid if the adapter has I2C_FUNC_I2C. The argument is |
| 110 | a pointer to a | 126 | a pointer to a |
| @@ -120,10 +136,9 @@ ioctl(file,I2C_RDWR,struct i2c_rdwr_ioctl_data *msgset) | |||
| 120 | The slave address and whether to use ten bit address mode has to be | 136 | The slave address and whether to use ten bit address mode has to be |
| 121 | set in each message, overriding the values set with the above ioctl's. | 137 | set in each message, overriding the values set with the above ioctl's. |
| 122 | 138 | ||
| 123 | 139 | ioctl(file, I2C_SMBUS, struct i2c_smbus_ioctl_data *args) | |
| 124 | Other values are NOT supported at this moment, except for I2C_SMBUS, | 140 | Not meant to be called directly; instead, use the access functions |
| 125 | which you should never directly call; instead, use the access functions | 141 | below. |
| 126 | below. | ||
| 127 | 142 | ||
| 128 | You can do plain i2c transactions by using read(2) and write(2) calls. | 143 | You can do plain i2c transactions by using read(2) and write(2) calls. |
| 129 | You do not need to pass the address byte; instead, set it through | 144 | You do not need to pass the address byte; instead, set it through |
| @@ -148,7 +163,52 @@ what happened. The 'write' transactions return 0 on success; the | |||
| 148 | returns the number of values read. The block buffers need not be longer | 163 | returns the number of values read. The block buffers need not be longer |
| 149 | than 32 bytes. | 164 | than 32 bytes. |
| 150 | 165 | ||
| 151 | The above functions are all macros, that resolve to calls to the | 166 | The above functions are all inline functions, that resolve to calls to |
| 152 | i2c_smbus_access function, that on its turn calls a specific ioctl | 167 | the i2c_smbus_access function, that on its turn calls a specific ioctl |
| 153 | with the data in a specific format. Read the source code if you | 168 | with the data in a specific format. Read the source code if you |
| 154 | want to know what happens behind the screens. | 169 | want to know what happens behind the screens. |
| 170 | |||
| 171 | |||
| 172 | Implementation details | ||
| 173 | ====================== | ||
| 174 | |||
| 175 | For the interested, here's the code flow which happens inside the kernel | ||
| 176 | when you use the /dev interface to I2C: | ||
| 177 | |||
| 178 | 1* Your program opens /dev/i2c-N and calls ioctl() on it, as described in | ||
| 179 | section "C example" above. | ||
| 180 | |||
| 181 | 2* These open() and ioctl() calls are handled by the i2c-dev kernel | ||
| 182 | driver: see i2c-dev.c:i2cdev_open() and i2c-dev.c:i2cdev_ioctl(), | ||
| 183 | respectively. You can think of i2c-dev as a generic I2C chip driver | ||
| 184 | that can be programmed from user-space. | ||
| 185 | |||
| 186 | 3* Some ioctl() calls are for administrative tasks and are handled by | ||
| 187 | i2c-dev directly. Examples include I2C_SLAVE (set the address of the | ||
| 188 | device you want to access) and I2C_PEC (enable or disable SMBus error | ||
| 189 | checking on future transactions.) | ||
| 190 | |||
| 191 | 4* Other ioctl() calls are converted to in-kernel function calls by | ||
| 192 | i2c-dev. Examples include I2C_FUNCS, which queries the I2C adapter | ||
| 193 | functionality using i2c.h:i2c_get_functionality(), and I2C_SMBUS, which | ||
| 194 | performs an SMBus transaction using i2c-core.c:i2c_smbus_xfer(). | ||
| 195 | |||
| 196 | The i2c-dev driver is responsible for checking all the parameters that | ||
| 197 | come from user-space for validity. After this point, there is no | ||
| 198 | difference between these calls that came from user-space through i2c-dev | ||
| 199 | and calls that would have been performed by kernel I2C chip drivers | ||
| 200 | directly. This means that I2C bus drivers don't need to implement | ||
| 201 | anything special to support access from user-space. | ||
| 202 | |||
| 203 | 5* These i2c-core.c/i2c.h functions are wrappers to the actual | ||
| 204 | implementation of your I2C bus driver. Each adapter must declare | ||
| 205 | callback functions implementing these standard calls. | ||
| 206 | i2c.h:i2c_get_functionality() calls i2c_adapter.algo->functionality(), | ||
| 207 | while i2c-core.c:i2c_smbus_xfer() calls either | ||
| 208 | adapter.algo->smbus_xfer() if it is implemented, or if not, | ||
| 209 | i2c-core.c:i2c_smbus_xfer_emulated() which in turn calls | ||
| 210 | i2c_adapter.algo->master_xfer(). | ||
| 211 | |||
| 212 | After your I2C bus driver has processed these requests, execution runs | ||
| 213 | up the call chain, with almost no processing done, except by i2c-dev to | ||
| 214 | package the returned data, if any, in suitable format for the ioctl. | ||
diff --git a/Documentation/i2c/smbus-protocol b/Documentation/i2c/smbus-protocol index 24bfb65da17d..9df47441f0e7 100644 --- a/Documentation/i2c/smbus-protocol +++ b/Documentation/i2c/smbus-protocol | |||
| @@ -109,8 +109,8 @@ specified through the Comm byte. | |||
| 109 | S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P | 109 | S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P |
| 110 | 110 | ||
| 111 | 111 | ||
| 112 | SMBus Process Call | 112 | SMBus Process Call: i2c_smbus_process_call() |
| 113 | ================== | 113 | ============================================= |
| 114 | 114 | ||
| 115 | This command selects a device register (through the Comm byte), sends | 115 | This command selects a device register (through the Comm byte), sends |
| 116 | 16 bits of data to it, and reads 16 bits of data in return. | 116 | 16 bits of data to it, and reads 16 bits of data in return. |
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index 6b61b3a2e90b..d73ee117a8ca 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
| @@ -606,6 +606,8 @@ SMBus communication | |||
| 606 | extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); | 606 | extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); |
| 607 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, | 607 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, |
| 608 | u8 command, u16 value); | 608 | u8 command, u16 value); |
| 609 | extern s32 i2c_smbus_process_call(struct i2c_client *client, | ||
| 610 | u8 command, u16 value); | ||
| 609 | extern s32 i2c_smbus_read_block_data(struct i2c_client * client, | 611 | extern s32 i2c_smbus_read_block_data(struct i2c_client * client, |
| 610 | u8 command, u8 *values); | 612 | u8 command, u8 *values); |
| 611 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, | 613 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, |
| @@ -621,8 +623,6 @@ These ones were removed from i2c-core because they had no users, but could | |||
| 621 | be added back later if needed: | 623 | be added back later if needed: |
| 622 | 624 | ||
| 623 | extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); | 625 | extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); |
| 624 | extern s32 i2c_smbus_process_call(struct i2c_client * client, | ||
| 625 | u8 command, u16 value); | ||
| 626 | extern s32 i2c_smbus_block_process_call(struct i2c_client *client, | 626 | extern s32 i2c_smbus_block_process_call(struct i2c_client *client, |
| 627 | u8 command, u8 length, | 627 | u8 command, u8 length, |
| 628 | u8 *values) | 628 | u8 *values) |
diff --git a/arch/arm/mach-omap1/board-h3.c b/arch/arm/mach-omap1/board-h3.c index 2ced6d9984d2..adfcd7b51393 100644 --- a/arch/arm/mach-omap1/board-h3.c +++ b/arch/arm/mach-omap1/board-h3.c | |||
| @@ -476,6 +476,10 @@ static struct i2c_board_info __initdata h3_i2c_board_info[] = { | |||
| 476 | I2C_BOARD_INFO("tps65013", 0x48), | 476 | I2C_BOARD_INFO("tps65013", 0x48), |
| 477 | /* .irq = OMAP_GPIO_IRQ(??), */ | 477 | /* .irq = OMAP_GPIO_IRQ(??), */ |
| 478 | }, | 478 | }, |
| 479 | { | ||
| 480 | I2C_BOARD_INFO("isp1301_omap", 0x2d), | ||
| 481 | .irq = OMAP_GPIO_IRQ(14), | ||
| 482 | }, | ||
| 479 | }; | 483 | }; |
| 480 | 484 | ||
| 481 | static struct omap_gpio_switch h3_gpio_switches[] __initdata = { | 485 | static struct omap_gpio_switch h3_gpio_switches[] __initdata = { |
diff --git a/arch/arm/mach-omap2/board-h4.c b/arch/arm/mach-omap2/board-h4.c index d4e3b6fc4705..2fef2c845083 100644 --- a/arch/arm/mach-omap2/board-h4.c +++ b/arch/arm/mach-omap2/board-h4.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include <linux/mtd/partitions.h> | 18 | #include <linux/mtd/partitions.h> |
| 19 | #include <linux/delay.h> | 19 | #include <linux/delay.h> |
| 20 | #include <linux/workqueue.h> | 20 | #include <linux/workqueue.h> |
| 21 | #include <linux/i2c.h> | ||
| 21 | #include <linux/input.h> | 22 | #include <linux/input.h> |
| 22 | #include <linux/err.h> | 23 | #include <linux/err.h> |
| 23 | #include <linux/clk.h> | 24 | #include <linux/clk.h> |
| @@ -391,6 +392,13 @@ static struct omap_board_config_kernel h4_config[] = { | |||
| 391 | { OMAP_TAG_LCD, &h4_lcd_config }, | 392 | { OMAP_TAG_LCD, &h4_lcd_config }, |
| 392 | }; | 393 | }; |
| 393 | 394 | ||
| 395 | static struct i2c_board_info __initdata h4_i2c_board_info[] = { | ||
| 396 | { | ||
| 397 | I2C_BOARD_INFO("isp1301_omap", 0x2d), | ||
| 398 | .irq = OMAP_GPIO_IRQ(125), | ||
| 399 | }, | ||
| 400 | }; | ||
| 401 | |||
| 394 | static void __init omap_h4_init(void) | 402 | static void __init omap_h4_init(void) |
| 395 | { | 403 | { |
| 396 | /* | 404 | /* |
| @@ -411,6 +419,9 @@ static void __init omap_h4_init(void) | |||
| 411 | } | 419 | } |
| 412 | #endif | 420 | #endif |
| 413 | 421 | ||
| 422 | i2c_register_board_info(1, h4_i2c_board_info, | ||
| 423 | ARRAY_SIZE(h4_i2c_board_info)); | ||
| 424 | |||
| 414 | platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices)); | 425 | platform_add_devices(h4_devices, ARRAY_SIZE(h4_devices)); |
| 415 | omap_board_config = h4_config; | 426 | omap_board_config = h4_config; |
| 416 | omap_board_config_size = ARRAY_SIZE(h4_config); | 427 | omap_board_config_size = ARRAY_SIZE(h4_config); |
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c index cdb8311e4ef7..27a5d397f9a1 100644 --- a/drivers/hwmon/dme1737.c +++ b/drivers/hwmon/dme1737.c | |||
| @@ -175,11 +175,11 @@ static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23}; | |||
| 175 | * Data structures and manipulation thereof | 175 | * Data structures and manipulation thereof |
| 176 | * --------------------------------------------------------------------- */ | 176 | * --------------------------------------------------------------------- */ |
| 177 | 177 | ||
| 178 | /* For ISA chips, we abuse the i2c_client addr and name fields. We also use | ||
| 179 | the driver field to differentiate between I2C and ISA chips. */ | ||
| 180 | struct dme1737_data { | 178 | struct dme1737_data { |
| 181 | struct i2c_client client; | 179 | struct i2c_client *client; /* for I2C devices only */ |
| 182 | struct device *hwmon_dev; | 180 | struct device *hwmon_dev; |
| 181 | const char *name; | ||
| 182 | unsigned int addr; /* for ISA devices only */ | ||
| 183 | 183 | ||
| 184 | struct mutex update_lock; | 184 | struct mutex update_lock; |
| 185 | int valid; /* !=0 if following fields are valid */ | 185 | int valid; /* !=0 if following fields are valid */ |
| @@ -512,11 +512,12 @@ static inline int PWM_OFF_TO_REG(int val, int ix, int reg) | |||
| 512 | * before calling dme1737_read or dme1737_write. | 512 | * before calling dme1737_read or dme1737_write. |
| 513 | * --------------------------------------------------------------------- */ | 513 | * --------------------------------------------------------------------- */ |
| 514 | 514 | ||
| 515 | static u8 dme1737_read(struct i2c_client *client, u8 reg) | 515 | static u8 dme1737_read(const struct dme1737_data *data, u8 reg) |
| 516 | { | 516 | { |
| 517 | struct i2c_client *client = data->client; | ||
| 517 | s32 val; | 518 | s32 val; |
| 518 | 519 | ||
| 519 | if (client->driver) { /* I2C device */ | 520 | if (client) { /* I2C device */ |
| 520 | val = i2c_smbus_read_byte_data(client, reg); | 521 | val = i2c_smbus_read_byte_data(client, reg); |
| 521 | 522 | ||
| 522 | if (val < 0) { | 523 | if (val < 0) { |
| @@ -525,18 +526,19 @@ static u8 dme1737_read(struct i2c_client *client, u8 reg) | |||
| 525 | "maintainer.\n", reg); | 526 | "maintainer.\n", reg); |
| 526 | } | 527 | } |
| 527 | } else { /* ISA device */ | 528 | } else { /* ISA device */ |
| 528 | outb(reg, client->addr); | 529 | outb(reg, data->addr); |
| 529 | val = inb(client->addr + 1); | 530 | val = inb(data->addr + 1); |
| 530 | } | 531 | } |
| 531 | 532 | ||
| 532 | return val; | 533 | return val; |
| 533 | } | 534 | } |
| 534 | 535 | ||
| 535 | static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val) | 536 | static s32 dme1737_write(const struct dme1737_data *data, u8 reg, u8 val) |
| 536 | { | 537 | { |
| 538 | struct i2c_client *client = data->client; | ||
| 537 | s32 res = 0; | 539 | s32 res = 0; |
| 538 | 540 | ||
| 539 | if (client->driver) { /* I2C device */ | 541 | if (client) { /* I2C device */ |
| 540 | res = i2c_smbus_write_byte_data(client, reg, val); | 542 | res = i2c_smbus_write_byte_data(client, reg, val); |
| 541 | 543 | ||
| 542 | if (res < 0) { | 544 | if (res < 0) { |
| @@ -545,8 +547,8 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val) | |||
| 545 | "maintainer.\n", reg); | 547 | "maintainer.\n", reg); |
| 546 | } | 548 | } |
| 547 | } else { /* ISA device */ | 549 | } else { /* ISA device */ |
| 548 | outb(reg, client->addr); | 550 | outb(reg, data->addr); |
| 549 | outb(val, client->addr + 1); | 551 | outb(val, data->addr + 1); |
| 550 | } | 552 | } |
| 551 | 553 | ||
| 552 | return res; | 554 | return res; |
| @@ -555,7 +557,6 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val) | |||
| 555 | static struct dme1737_data *dme1737_update_device(struct device *dev) | 557 | static struct dme1737_data *dme1737_update_device(struct device *dev) |
| 556 | { | 558 | { |
| 557 | struct dme1737_data *data = dev_get_drvdata(dev); | 559 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 558 | struct i2c_client *client = &data->client; | ||
| 559 | int ix; | 560 | int ix; |
| 560 | u8 lsb[5]; | 561 | u8 lsb[5]; |
| 561 | 562 | ||
| @@ -563,7 +564,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
| 563 | 564 | ||
| 564 | /* Enable a Vbat monitoring cycle every 10 mins */ | 565 | /* Enable a Vbat monitoring cycle every 10 mins */ |
| 565 | if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) { | 566 | if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) { |
| 566 | dme1737_write(client, DME1737_REG_CONFIG, dme1737_read(client, | 567 | dme1737_write(data, DME1737_REG_CONFIG, dme1737_read(data, |
| 567 | DME1737_REG_CONFIG) | 0x10); | 568 | DME1737_REG_CONFIG) | 0x10); |
| 568 | data->last_vbat = jiffies; | 569 | data->last_vbat = jiffies; |
| 569 | } | 570 | } |
| @@ -571,7 +572,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
| 571 | /* Sample register contents every 1 sec */ | 572 | /* Sample register contents every 1 sec */ |
| 572 | if (time_after(jiffies, data->last_update + HZ) || !data->valid) { | 573 | if (time_after(jiffies, data->last_update + HZ) || !data->valid) { |
| 573 | if (data->type != sch5027) { | 574 | if (data->type != sch5027) { |
| 574 | data->vid = dme1737_read(client, DME1737_REG_VID) & | 575 | data->vid = dme1737_read(data, DME1737_REG_VID) & |
| 575 | 0x3f; | 576 | 0x3f; |
| 576 | } | 577 | } |
| 577 | 578 | ||
| @@ -580,11 +581,11 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
| 580 | /* Voltage inputs are stored as 16 bit values even | 581 | /* Voltage inputs are stored as 16 bit values even |
| 581 | * though they have only 12 bits resolution. This is | 582 | * though they have only 12 bits resolution. This is |
| 582 | * to make it consistent with the temp inputs. */ | 583 | * to make it consistent with the temp inputs. */ |
| 583 | data->in[ix] = dme1737_read(client, | 584 | data->in[ix] = dme1737_read(data, |
| 584 | DME1737_REG_IN(ix)) << 8; | 585 | DME1737_REG_IN(ix)) << 8; |
| 585 | data->in_min[ix] = dme1737_read(client, | 586 | data->in_min[ix] = dme1737_read(data, |
| 586 | DME1737_REG_IN_MIN(ix)); | 587 | DME1737_REG_IN_MIN(ix)); |
| 587 | data->in_max[ix] = dme1737_read(client, | 588 | data->in_max[ix] = dme1737_read(data, |
| 588 | DME1737_REG_IN_MAX(ix)); | 589 | DME1737_REG_IN_MAX(ix)); |
| 589 | } | 590 | } |
| 590 | 591 | ||
| @@ -595,14 +596,14 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
| 595 | * to take advantage of implicit conversions between | 596 | * to take advantage of implicit conversions between |
| 596 | * register values (2's complement) and temp values | 597 | * register values (2's complement) and temp values |
| 597 | * (signed decimal). */ | 598 | * (signed decimal). */ |
| 598 | data->temp[ix] = dme1737_read(client, | 599 | data->temp[ix] = dme1737_read(data, |
| 599 | DME1737_REG_TEMP(ix)) << 8; | 600 | DME1737_REG_TEMP(ix)) << 8; |
| 600 | data->temp_min[ix] = dme1737_read(client, | 601 | data->temp_min[ix] = dme1737_read(data, |
| 601 | DME1737_REG_TEMP_MIN(ix)); | 602 | DME1737_REG_TEMP_MIN(ix)); |
| 602 | data->temp_max[ix] = dme1737_read(client, | 603 | data->temp_max[ix] = dme1737_read(data, |
| 603 | DME1737_REG_TEMP_MAX(ix)); | 604 | DME1737_REG_TEMP_MAX(ix)); |
| 604 | if (data->type != sch5027) { | 605 | if (data->type != sch5027) { |
| 605 | data->temp_offset[ix] = dme1737_read(client, | 606 | data->temp_offset[ix] = dme1737_read(data, |
| 606 | DME1737_REG_TEMP_OFFSET(ix)); | 607 | DME1737_REG_TEMP_OFFSET(ix)); |
| 607 | } | 608 | } |
| 608 | } | 609 | } |
| @@ -612,7 +613,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
| 612 | * which the registers are read (MSB first, then LSB) is | 613 | * which the registers are read (MSB first, then LSB) is |
| 613 | * important! */ | 614 | * important! */ |
| 614 | for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { | 615 | for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { |
| 615 | lsb[ix] = dme1737_read(client, | 616 | lsb[ix] = dme1737_read(data, |
| 616 | DME1737_REG_IN_TEMP_LSB(ix)); | 617 | DME1737_REG_IN_TEMP_LSB(ix)); |
| 617 | } | 618 | } |
| 618 | for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { | 619 | for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { |
| @@ -631,19 +632,19 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
| 631 | if (!(data->has_fan & (1 << ix))) { | 632 | if (!(data->has_fan & (1 << ix))) { |
| 632 | continue; | 633 | continue; |
| 633 | } | 634 | } |
| 634 | data->fan[ix] = dme1737_read(client, | 635 | data->fan[ix] = dme1737_read(data, |
| 635 | DME1737_REG_FAN(ix)); | 636 | DME1737_REG_FAN(ix)); |
| 636 | data->fan[ix] |= dme1737_read(client, | 637 | data->fan[ix] |= dme1737_read(data, |
| 637 | DME1737_REG_FAN(ix) + 1) << 8; | 638 | DME1737_REG_FAN(ix) + 1) << 8; |
| 638 | data->fan_min[ix] = dme1737_read(client, | 639 | data->fan_min[ix] = dme1737_read(data, |
| 639 | DME1737_REG_FAN_MIN(ix)); | 640 | DME1737_REG_FAN_MIN(ix)); |
| 640 | data->fan_min[ix] |= dme1737_read(client, | 641 | data->fan_min[ix] |= dme1737_read(data, |
| 641 | DME1737_REG_FAN_MIN(ix) + 1) << 8; | 642 | DME1737_REG_FAN_MIN(ix) + 1) << 8; |
| 642 | data->fan_opt[ix] = dme1737_read(client, | 643 | data->fan_opt[ix] = dme1737_read(data, |
| 643 | DME1737_REG_FAN_OPT(ix)); | 644 | DME1737_REG_FAN_OPT(ix)); |
| 644 | /* fan_max exists only for fan[5-6] */ | 645 | /* fan_max exists only for fan[5-6] */ |
| 645 | if (ix > 3) { | 646 | if (ix > 3) { |
| 646 | data->fan_max[ix - 4] = dme1737_read(client, | 647 | data->fan_max[ix - 4] = dme1737_read(data, |
| 647 | DME1737_REG_FAN_MAX(ix)); | 648 | DME1737_REG_FAN_MAX(ix)); |
| 648 | } | 649 | } |
| 649 | } | 650 | } |
| @@ -655,63 +656,63 @@ static struct dme1737_data *dme1737_update_device(struct device *dev) | |||
| 655 | if (!(data->has_pwm & (1 << ix))) { | 656 | if (!(data->has_pwm & (1 << ix))) { |
| 656 | continue; | 657 | continue; |
| 657 | } | 658 | } |
| 658 | data->pwm[ix] = dme1737_read(client, | 659 | data->pwm[ix] = dme1737_read(data, |
| 659 | DME1737_REG_PWM(ix)); | 660 | DME1737_REG_PWM(ix)); |
| 660 | data->pwm_freq[ix] = dme1737_read(client, | 661 | data->pwm_freq[ix] = dme1737_read(data, |
| 661 | DME1737_REG_PWM_FREQ(ix)); | 662 | DME1737_REG_PWM_FREQ(ix)); |
| 662 | /* pwm_config and pwm_min exist only for pwm[1-3] */ | 663 | /* pwm_config and pwm_min exist only for pwm[1-3] */ |
| 663 | if (ix < 3) { | 664 | if (ix < 3) { |
| 664 | data->pwm_config[ix] = dme1737_read(client, | 665 | data->pwm_config[ix] = dme1737_read(data, |
| 665 | DME1737_REG_PWM_CONFIG(ix)); | 666 | DME1737_REG_PWM_CONFIG(ix)); |
| 666 | data->pwm_min[ix] = dme1737_read(client, | 667 | data->pwm_min[ix] = dme1737_read(data, |
| 667 | DME1737_REG_PWM_MIN(ix)); | 668 | DME1737_REG_PWM_MIN(ix)); |
| 668 | } | 669 | } |
| 669 | } | 670 | } |
| 670 | for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) { | 671 | for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) { |
| 671 | data->pwm_rr[ix] = dme1737_read(client, | 672 | data->pwm_rr[ix] = dme1737_read(data, |
| 672 | DME1737_REG_PWM_RR(ix)); | 673 | DME1737_REG_PWM_RR(ix)); |
| 673 | } | 674 | } |
| 674 | 675 | ||
| 675 | /* Thermal zone registers */ | 676 | /* Thermal zone registers */ |
| 676 | for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { | 677 | for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { |
| 677 | data->zone_low[ix] = dme1737_read(client, | 678 | data->zone_low[ix] = dme1737_read(data, |
| 678 | DME1737_REG_ZONE_LOW(ix)); | 679 | DME1737_REG_ZONE_LOW(ix)); |
| 679 | data->zone_abs[ix] = dme1737_read(client, | 680 | data->zone_abs[ix] = dme1737_read(data, |
| 680 | DME1737_REG_ZONE_ABS(ix)); | 681 | DME1737_REG_ZONE_ABS(ix)); |
| 681 | } | 682 | } |
| 682 | if (data->type != sch5027) { | 683 | if (data->type != sch5027) { |
| 683 | for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { | 684 | for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { |
| 684 | data->zone_hyst[ix] = dme1737_read(client, | 685 | data->zone_hyst[ix] = dme1737_read(data, |
| 685 | DME1737_REG_ZONE_HYST(ix)); | 686 | DME1737_REG_ZONE_HYST(ix)); |
| 686 | } | 687 | } |
| 687 | } | 688 | } |
| 688 | 689 | ||
| 689 | /* Alarm registers */ | 690 | /* Alarm registers */ |
| 690 | data->alarms = dme1737_read(client, | 691 | data->alarms = dme1737_read(data, |
| 691 | DME1737_REG_ALARM1); | 692 | DME1737_REG_ALARM1); |
| 692 | /* Bit 7 tells us if the other alarm registers are non-zero and | 693 | /* Bit 7 tells us if the other alarm registers are non-zero and |
| 693 | * therefore also need to be read */ | 694 | * therefore also need to be read */ |
| 694 | if (data->alarms & 0x80) { | 695 | if (data->alarms & 0x80) { |
| 695 | data->alarms |= dme1737_read(client, | 696 | data->alarms |= dme1737_read(data, |
| 696 | DME1737_REG_ALARM2) << 8; | 697 | DME1737_REG_ALARM2) << 8; |
| 697 | data->alarms |= dme1737_read(client, | 698 | data->alarms |= dme1737_read(data, |
| 698 | DME1737_REG_ALARM3) << 16; | 699 | DME1737_REG_ALARM3) << 16; |
| 699 | } | 700 | } |
| 700 | 701 | ||
| 701 | /* The ISA chips require explicit clearing of alarm bits. | 702 | /* The ISA chips require explicit clearing of alarm bits. |
| 702 | * Don't worry, an alarm will come back if the condition | 703 | * Don't worry, an alarm will come back if the condition |
| 703 | * that causes it still exists */ | 704 | * that causes it still exists */ |
| 704 | if (!client->driver) { | 705 | if (!data->client) { |
| 705 | if (data->alarms & 0xff0000) { | 706 | if (data->alarms & 0xff0000) { |
| 706 | dme1737_write(client, DME1737_REG_ALARM3, | 707 | dme1737_write(data, DME1737_REG_ALARM3, |
| 707 | 0xff); | 708 | 0xff); |
| 708 | } | 709 | } |
| 709 | if (data->alarms & 0xff00) { | 710 | if (data->alarms & 0xff00) { |
| 710 | dme1737_write(client, DME1737_REG_ALARM2, | 711 | dme1737_write(data, DME1737_REG_ALARM2, |
| 711 | 0xff); | 712 | 0xff); |
| 712 | } | 713 | } |
| 713 | if (data->alarms & 0xff) { | 714 | if (data->alarms & 0xff) { |
| 714 | dme1737_write(client, DME1737_REG_ALARM1, | 715 | dme1737_write(data, DME1737_REG_ALARM1, |
| 715 | 0xff); | 716 | 0xff); |
| 716 | } | 717 | } |
| 717 | } | 718 | } |
| @@ -770,7 +771,6 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr, | |||
| 770 | const char *buf, size_t count) | 771 | const char *buf, size_t count) |
| 771 | { | 772 | { |
| 772 | struct dme1737_data *data = dev_get_drvdata(dev); | 773 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 773 | struct i2c_client *client = &data->client; | ||
| 774 | struct sensor_device_attribute_2 | 774 | struct sensor_device_attribute_2 |
| 775 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 775 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 776 | int ix = sensor_attr_2->index; | 776 | int ix = sensor_attr_2->index; |
| @@ -781,12 +781,12 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr, | |||
| 781 | switch (fn) { | 781 | switch (fn) { |
| 782 | case SYS_IN_MIN: | 782 | case SYS_IN_MIN: |
| 783 | data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]); | 783 | data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]); |
| 784 | dme1737_write(client, DME1737_REG_IN_MIN(ix), | 784 | dme1737_write(data, DME1737_REG_IN_MIN(ix), |
| 785 | data->in_min[ix]); | 785 | data->in_min[ix]); |
| 786 | break; | 786 | break; |
| 787 | case SYS_IN_MAX: | 787 | case SYS_IN_MAX: |
| 788 | data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]); | 788 | data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]); |
| 789 | dme1737_write(client, DME1737_REG_IN_MAX(ix), | 789 | dme1737_write(data, DME1737_REG_IN_MAX(ix), |
| 790 | data->in_max[ix]); | 790 | data->in_max[ix]); |
| 791 | break; | 791 | break; |
| 792 | default: | 792 | default: |
| @@ -850,7 +850,6 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr, | |||
| 850 | const char *buf, size_t count) | 850 | const char *buf, size_t count) |
| 851 | { | 851 | { |
| 852 | struct dme1737_data *data = dev_get_drvdata(dev); | 852 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 853 | struct i2c_client *client = &data->client; | ||
| 854 | struct sensor_device_attribute_2 | 853 | struct sensor_device_attribute_2 |
| 855 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 854 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 856 | int ix = sensor_attr_2->index; | 855 | int ix = sensor_attr_2->index; |
| @@ -861,17 +860,17 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr, | |||
| 861 | switch (fn) { | 860 | switch (fn) { |
| 862 | case SYS_TEMP_MIN: | 861 | case SYS_TEMP_MIN: |
| 863 | data->temp_min[ix] = TEMP_TO_REG(val); | 862 | data->temp_min[ix] = TEMP_TO_REG(val); |
| 864 | dme1737_write(client, DME1737_REG_TEMP_MIN(ix), | 863 | dme1737_write(data, DME1737_REG_TEMP_MIN(ix), |
| 865 | data->temp_min[ix]); | 864 | data->temp_min[ix]); |
| 866 | break; | 865 | break; |
| 867 | case SYS_TEMP_MAX: | 866 | case SYS_TEMP_MAX: |
| 868 | data->temp_max[ix] = TEMP_TO_REG(val); | 867 | data->temp_max[ix] = TEMP_TO_REG(val); |
| 869 | dme1737_write(client, DME1737_REG_TEMP_MAX(ix), | 868 | dme1737_write(data, DME1737_REG_TEMP_MAX(ix), |
| 870 | data->temp_max[ix]); | 869 | data->temp_max[ix]); |
| 871 | break; | 870 | break; |
| 872 | case SYS_TEMP_OFFSET: | 871 | case SYS_TEMP_OFFSET: |
| 873 | data->temp_offset[ix] = TEMP_TO_REG(val); | 872 | data->temp_offset[ix] = TEMP_TO_REG(val); |
| 874 | dme1737_write(client, DME1737_REG_TEMP_OFFSET(ix), | 873 | dme1737_write(data, DME1737_REG_TEMP_OFFSET(ix), |
| 875 | data->temp_offset[ix]); | 874 | data->temp_offset[ix]); |
| 876 | break; | 875 | break; |
| 877 | default: | 876 | default: |
| @@ -939,7 +938,6 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr, | |||
| 939 | const char *buf, size_t count) | 938 | const char *buf, size_t count) |
| 940 | { | 939 | { |
| 941 | struct dme1737_data *data = dev_get_drvdata(dev); | 940 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 942 | struct i2c_client *client = &data->client; | ||
| 943 | struct sensor_device_attribute_2 | 941 | struct sensor_device_attribute_2 |
| 944 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 942 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 945 | int ix = sensor_attr_2->index; | 943 | int ix = sensor_attr_2->index; |
| @@ -950,37 +948,37 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr, | |||
| 950 | switch (fn) { | 948 | switch (fn) { |
| 951 | case SYS_ZONE_AUTO_POINT1_TEMP_HYST: | 949 | case SYS_ZONE_AUTO_POINT1_TEMP_HYST: |
| 952 | /* Refresh the cache */ | 950 | /* Refresh the cache */ |
| 953 | data->zone_low[ix] = dme1737_read(client, | 951 | data->zone_low[ix] = dme1737_read(data, |
| 954 | DME1737_REG_ZONE_LOW(ix)); | 952 | DME1737_REG_ZONE_LOW(ix)); |
| 955 | /* Modify the temp hyst value */ | 953 | /* Modify the temp hyst value */ |
| 956 | data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG( | 954 | data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG( |
| 957 | TEMP_FROM_REG(data->zone_low[ix], 8) - | 955 | TEMP_FROM_REG(data->zone_low[ix], 8) - |
| 958 | val, ix, dme1737_read(client, | 956 | val, ix, dme1737_read(data, |
| 959 | DME1737_REG_ZONE_HYST(ix == 2))); | 957 | DME1737_REG_ZONE_HYST(ix == 2))); |
| 960 | dme1737_write(client, DME1737_REG_ZONE_HYST(ix == 2), | 958 | dme1737_write(data, DME1737_REG_ZONE_HYST(ix == 2), |
| 961 | data->zone_hyst[ix == 2]); | 959 | data->zone_hyst[ix == 2]); |
| 962 | break; | 960 | break; |
| 963 | case SYS_ZONE_AUTO_POINT1_TEMP: | 961 | case SYS_ZONE_AUTO_POINT1_TEMP: |
| 964 | data->zone_low[ix] = TEMP_TO_REG(val); | 962 | data->zone_low[ix] = TEMP_TO_REG(val); |
| 965 | dme1737_write(client, DME1737_REG_ZONE_LOW(ix), | 963 | dme1737_write(data, DME1737_REG_ZONE_LOW(ix), |
| 966 | data->zone_low[ix]); | 964 | data->zone_low[ix]); |
| 967 | break; | 965 | break; |
| 968 | case SYS_ZONE_AUTO_POINT2_TEMP: | 966 | case SYS_ZONE_AUTO_POINT2_TEMP: |
| 969 | /* Refresh the cache */ | 967 | /* Refresh the cache */ |
| 970 | data->zone_low[ix] = dme1737_read(client, | 968 | data->zone_low[ix] = dme1737_read(data, |
| 971 | DME1737_REG_ZONE_LOW(ix)); | 969 | DME1737_REG_ZONE_LOW(ix)); |
| 972 | /* Modify the temp range value (which is stored in the upper | 970 | /* Modify the temp range value (which is stored in the upper |
| 973 | * nibble of the pwm_freq register) */ | 971 | * nibble of the pwm_freq register) */ |
| 974 | data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - | 972 | data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - |
| 975 | TEMP_FROM_REG(data->zone_low[ix], 8), | 973 | TEMP_FROM_REG(data->zone_low[ix], 8), |
| 976 | dme1737_read(client, | 974 | dme1737_read(data, |
| 977 | DME1737_REG_PWM_FREQ(ix))); | 975 | DME1737_REG_PWM_FREQ(ix))); |
| 978 | dme1737_write(client, DME1737_REG_PWM_FREQ(ix), | 976 | dme1737_write(data, DME1737_REG_PWM_FREQ(ix), |
| 979 | data->pwm_freq[ix]); | 977 | data->pwm_freq[ix]); |
| 980 | break; | 978 | break; |
| 981 | case SYS_ZONE_AUTO_POINT3_TEMP: | 979 | case SYS_ZONE_AUTO_POINT3_TEMP: |
| 982 | data->zone_abs[ix] = TEMP_TO_REG(val); | 980 | data->zone_abs[ix] = TEMP_TO_REG(val); |
| 983 | dme1737_write(client, DME1737_REG_ZONE_ABS(ix), | 981 | dme1737_write(data, DME1737_REG_ZONE_ABS(ix), |
| 984 | data->zone_abs[ix]); | 982 | data->zone_abs[ix]); |
| 985 | break; | 983 | break; |
| 986 | default: | 984 | default: |
| @@ -1046,7 +1044,6 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr, | |||
| 1046 | const char *buf, size_t count) | 1044 | const char *buf, size_t count) |
| 1047 | { | 1045 | { |
| 1048 | struct dme1737_data *data = dev_get_drvdata(dev); | 1046 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 1049 | struct i2c_client *client = &data->client; | ||
| 1050 | struct sensor_device_attribute_2 | 1047 | struct sensor_device_attribute_2 |
| 1051 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 1048 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 1052 | int ix = sensor_attr_2->index; | 1049 | int ix = sensor_attr_2->index; |
| @@ -1060,21 +1057,21 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr, | |||
| 1060 | data->fan_min[ix] = FAN_TO_REG(val, 0); | 1057 | data->fan_min[ix] = FAN_TO_REG(val, 0); |
| 1061 | } else { | 1058 | } else { |
| 1062 | /* Refresh the cache */ | 1059 | /* Refresh the cache */ |
| 1063 | data->fan_opt[ix] = dme1737_read(client, | 1060 | data->fan_opt[ix] = dme1737_read(data, |
| 1064 | DME1737_REG_FAN_OPT(ix)); | 1061 | DME1737_REG_FAN_OPT(ix)); |
| 1065 | /* Modify the fan min value */ | 1062 | /* Modify the fan min value */ |
| 1066 | data->fan_min[ix] = FAN_TO_REG(val, | 1063 | data->fan_min[ix] = FAN_TO_REG(val, |
| 1067 | FAN_TPC_FROM_REG(data->fan_opt[ix])); | 1064 | FAN_TPC_FROM_REG(data->fan_opt[ix])); |
| 1068 | } | 1065 | } |
| 1069 | dme1737_write(client, DME1737_REG_FAN_MIN(ix), | 1066 | dme1737_write(data, DME1737_REG_FAN_MIN(ix), |
| 1070 | data->fan_min[ix] & 0xff); | 1067 | data->fan_min[ix] & 0xff); |
| 1071 | dme1737_write(client, DME1737_REG_FAN_MIN(ix) + 1, | 1068 | dme1737_write(data, DME1737_REG_FAN_MIN(ix) + 1, |
| 1072 | data->fan_min[ix] >> 8); | 1069 | data->fan_min[ix] >> 8); |
| 1073 | break; | 1070 | break; |
| 1074 | case SYS_FAN_MAX: | 1071 | case SYS_FAN_MAX: |
| 1075 | /* Only valid for fan[5-6] */ | 1072 | /* Only valid for fan[5-6] */ |
| 1076 | data->fan_max[ix - 4] = FAN_MAX_TO_REG(val); | 1073 | data->fan_max[ix - 4] = FAN_MAX_TO_REG(val); |
| 1077 | dme1737_write(client, DME1737_REG_FAN_MAX(ix), | 1074 | dme1737_write(data, DME1737_REG_FAN_MAX(ix), |
| 1078 | data->fan_max[ix - 4]); | 1075 | data->fan_max[ix - 4]); |
| 1079 | break; | 1076 | break; |
| 1080 | case SYS_FAN_TYPE: | 1077 | case SYS_FAN_TYPE: |
| @@ -1086,9 +1083,9 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr, | |||
| 1086 | val); | 1083 | val); |
| 1087 | goto exit; | 1084 | goto exit; |
| 1088 | } | 1085 | } |
| 1089 | data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(client, | 1086 | data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(data, |
| 1090 | DME1737_REG_FAN_OPT(ix))); | 1087 | DME1737_REG_FAN_OPT(ix))); |
| 1091 | dme1737_write(client, DME1737_REG_FAN_OPT(ix), | 1088 | dme1737_write(data, DME1737_REG_FAN_OPT(ix), |
| 1092 | data->fan_opt[ix]); | 1089 | data->fan_opt[ix]); |
| 1093 | break; | 1090 | break; |
| 1094 | default: | 1091 | default: |
| @@ -1185,7 +1182,6 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1185 | const char *buf, size_t count) | 1182 | const char *buf, size_t count) |
| 1186 | { | 1183 | { |
| 1187 | struct dme1737_data *data = dev_get_drvdata(dev); | 1184 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 1188 | struct i2c_client *client = &data->client; | ||
| 1189 | struct sensor_device_attribute_2 | 1185 | struct sensor_device_attribute_2 |
| 1190 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 1186 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
| 1191 | int ix = sensor_attr_2->index; | 1187 | int ix = sensor_attr_2->index; |
| @@ -1196,12 +1192,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1196 | switch (fn) { | 1192 | switch (fn) { |
| 1197 | case SYS_PWM: | 1193 | case SYS_PWM: |
| 1198 | data->pwm[ix] = SENSORS_LIMIT(val, 0, 255); | 1194 | data->pwm[ix] = SENSORS_LIMIT(val, 0, 255); |
| 1199 | dme1737_write(client, DME1737_REG_PWM(ix), data->pwm[ix]); | 1195 | dme1737_write(data, DME1737_REG_PWM(ix), data->pwm[ix]); |
| 1200 | break; | 1196 | break; |
| 1201 | case SYS_PWM_FREQ: | 1197 | case SYS_PWM_FREQ: |
| 1202 | data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(client, | 1198 | data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(data, |
| 1203 | DME1737_REG_PWM_FREQ(ix))); | 1199 | DME1737_REG_PWM_FREQ(ix))); |
| 1204 | dme1737_write(client, DME1737_REG_PWM_FREQ(ix), | 1200 | dme1737_write(data, DME1737_REG_PWM_FREQ(ix), |
| 1205 | data->pwm_freq[ix]); | 1201 | data->pwm_freq[ix]); |
| 1206 | break; | 1202 | break; |
| 1207 | case SYS_PWM_ENABLE: | 1203 | case SYS_PWM_ENABLE: |
| @@ -1214,7 +1210,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1214 | goto exit; | 1210 | goto exit; |
| 1215 | } | 1211 | } |
| 1216 | /* Refresh the cache */ | 1212 | /* Refresh the cache */ |
| 1217 | data->pwm_config[ix] = dme1737_read(client, | 1213 | data->pwm_config[ix] = dme1737_read(data, |
| 1218 | DME1737_REG_PWM_CONFIG(ix)); | 1214 | DME1737_REG_PWM_CONFIG(ix)); |
| 1219 | if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) { | 1215 | if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) { |
| 1220 | /* Bail out if no change */ | 1216 | /* Bail out if no change */ |
| @@ -1226,14 +1222,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1226 | data->pwm_acz[ix] = PWM_ACZ_FROM_REG( | 1222 | data->pwm_acz[ix] = PWM_ACZ_FROM_REG( |
| 1227 | data->pwm_config[ix]); | 1223 | data->pwm_config[ix]); |
| 1228 | /* Save the current ramp rate state and disable it */ | 1224 | /* Save the current ramp rate state and disable it */ |
| 1229 | data->pwm_rr[ix > 0] = dme1737_read(client, | 1225 | data->pwm_rr[ix > 0] = dme1737_read(data, |
| 1230 | DME1737_REG_PWM_RR(ix > 0)); | 1226 | DME1737_REG_PWM_RR(ix > 0)); |
| 1231 | data->pwm_rr_en &= ~(1 << ix); | 1227 | data->pwm_rr_en &= ~(1 << ix); |
| 1232 | if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) { | 1228 | if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) { |
| 1233 | data->pwm_rr_en |= (1 << ix); | 1229 | data->pwm_rr_en |= (1 << ix); |
| 1234 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix, | 1230 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix, |
| 1235 | data->pwm_rr[ix > 0]); | 1231 | data->pwm_rr[ix > 0]); |
| 1236 | dme1737_write(client, | 1232 | dme1737_write(data, |
| 1237 | DME1737_REG_PWM_RR(ix > 0), | 1233 | DME1737_REG_PWM_RR(ix > 0), |
| 1238 | data->pwm_rr[ix > 0]); | 1234 | data->pwm_rr[ix > 0]); |
| 1239 | } | 1235 | } |
| @@ -1247,14 +1243,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1247 | /* Turn fan fully on */ | 1243 | /* Turn fan fully on */ |
| 1248 | data->pwm_config[ix] = PWM_EN_TO_REG(0, | 1244 | data->pwm_config[ix] = PWM_EN_TO_REG(0, |
| 1249 | data->pwm_config[ix]); | 1245 | data->pwm_config[ix]); |
| 1250 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | 1246 | dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), |
| 1251 | data->pwm_config[ix]); | 1247 | data->pwm_config[ix]); |
| 1252 | break; | 1248 | break; |
| 1253 | case 1: | 1249 | case 1: |
| 1254 | /* Turn on manual mode */ | 1250 | /* Turn on manual mode */ |
| 1255 | data->pwm_config[ix] = PWM_EN_TO_REG(1, | 1251 | data->pwm_config[ix] = PWM_EN_TO_REG(1, |
| 1256 | data->pwm_config[ix]); | 1252 | data->pwm_config[ix]); |
| 1257 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | 1253 | dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), |
| 1258 | data->pwm_config[ix]); | 1254 | data->pwm_config[ix]); |
| 1259 | /* Change permissions of pwm[ix] to read-writeable */ | 1255 | /* Change permissions of pwm[ix] to read-writeable */ |
| 1260 | dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix], | 1256 | dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix], |
| @@ -1269,14 +1265,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1269 | data->pwm_config[ix] = PWM_ACZ_TO_REG( | 1265 | data->pwm_config[ix] = PWM_ACZ_TO_REG( |
| 1270 | data->pwm_acz[ix], | 1266 | data->pwm_acz[ix], |
| 1271 | data->pwm_config[ix]); | 1267 | data->pwm_config[ix]); |
| 1272 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | 1268 | dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), |
| 1273 | data->pwm_config[ix]); | 1269 | data->pwm_config[ix]); |
| 1274 | /* Enable PWM ramp rate if previously enabled */ | 1270 | /* Enable PWM ramp rate if previously enabled */ |
| 1275 | if (data->pwm_rr_en & (1 << ix)) { | 1271 | if (data->pwm_rr_en & (1 << ix)) { |
| 1276 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix, | 1272 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix, |
| 1277 | dme1737_read(client, | 1273 | dme1737_read(data, |
| 1278 | DME1737_REG_PWM_RR(ix > 0))); | 1274 | DME1737_REG_PWM_RR(ix > 0))); |
| 1279 | dme1737_write(client, | 1275 | dme1737_write(data, |
| 1280 | DME1737_REG_PWM_RR(ix > 0), | 1276 | DME1737_REG_PWM_RR(ix > 0), |
| 1281 | data->pwm_rr[ix > 0]); | 1277 | data->pwm_rr[ix > 0]); |
| 1282 | } | 1278 | } |
| @@ -1286,9 +1282,9 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1286 | case SYS_PWM_RAMP_RATE: | 1282 | case SYS_PWM_RAMP_RATE: |
| 1287 | /* Only valid for pwm[1-3] */ | 1283 | /* Only valid for pwm[1-3] */ |
| 1288 | /* Refresh the cache */ | 1284 | /* Refresh the cache */ |
| 1289 | data->pwm_config[ix] = dme1737_read(client, | 1285 | data->pwm_config[ix] = dme1737_read(data, |
| 1290 | DME1737_REG_PWM_CONFIG(ix)); | 1286 | DME1737_REG_PWM_CONFIG(ix)); |
| 1291 | data->pwm_rr[ix > 0] = dme1737_read(client, | 1287 | data->pwm_rr[ix > 0] = dme1737_read(data, |
| 1292 | DME1737_REG_PWM_RR(ix > 0)); | 1288 | DME1737_REG_PWM_RR(ix > 0)); |
| 1293 | /* Set the ramp rate value */ | 1289 | /* Set the ramp rate value */ |
| 1294 | if (val > 0) { | 1290 | if (val > 0) { |
| @@ -1301,7 +1297,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1301 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, | 1297 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, |
| 1302 | data->pwm_rr[ix > 0]); | 1298 | data->pwm_rr[ix > 0]); |
| 1303 | } | 1299 | } |
| 1304 | dme1737_write(client, DME1737_REG_PWM_RR(ix > 0), | 1300 | dme1737_write(data, DME1737_REG_PWM_RR(ix > 0), |
| 1305 | data->pwm_rr[ix > 0]); | 1301 | data->pwm_rr[ix > 0]); |
| 1306 | break; | 1302 | break; |
| 1307 | case SYS_PWM_AUTO_CHANNELS_ZONE: | 1303 | case SYS_PWM_AUTO_CHANNELS_ZONE: |
| @@ -1315,14 +1311,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1315 | goto exit; | 1311 | goto exit; |
| 1316 | } | 1312 | } |
| 1317 | /* Refresh the cache */ | 1313 | /* Refresh the cache */ |
| 1318 | data->pwm_config[ix] = dme1737_read(client, | 1314 | data->pwm_config[ix] = dme1737_read(data, |
| 1319 | DME1737_REG_PWM_CONFIG(ix)); | 1315 | DME1737_REG_PWM_CONFIG(ix)); |
| 1320 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { | 1316 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { |
| 1321 | /* PWM is already in auto mode so update the temp | 1317 | /* PWM is already in auto mode so update the temp |
| 1322 | * channel assignment */ | 1318 | * channel assignment */ |
| 1323 | data->pwm_config[ix] = PWM_ACZ_TO_REG(val, | 1319 | data->pwm_config[ix] = PWM_ACZ_TO_REG(val, |
| 1324 | data->pwm_config[ix]); | 1320 | data->pwm_config[ix]); |
| 1325 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | 1321 | dme1737_write(data, DME1737_REG_PWM_CONFIG(ix), |
| 1326 | data->pwm_config[ix]); | 1322 | data->pwm_config[ix]); |
| 1327 | } else { | 1323 | } else { |
| 1328 | /* PWM is not in auto mode so we save the temp | 1324 | /* PWM is not in auto mode so we save the temp |
| @@ -1333,7 +1329,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1333 | case SYS_PWM_AUTO_PWM_MIN: | 1329 | case SYS_PWM_AUTO_PWM_MIN: |
| 1334 | /* Only valid for pwm[1-3] */ | 1330 | /* Only valid for pwm[1-3] */ |
| 1335 | /* Refresh the cache */ | 1331 | /* Refresh the cache */ |
| 1336 | data->pwm_min[ix] = dme1737_read(client, | 1332 | data->pwm_min[ix] = dme1737_read(data, |
| 1337 | DME1737_REG_PWM_MIN(ix)); | 1333 | DME1737_REG_PWM_MIN(ix)); |
| 1338 | /* There are only 2 values supported for the auto_pwm_min | 1334 | /* There are only 2 values supported for the auto_pwm_min |
| 1339 | * value: 0 or auto_point1_pwm. So if the temperature drops | 1335 | * value: 0 or auto_point1_pwm. So if the temperature drops |
| @@ -1341,20 +1337,20 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
| 1341 | * off or runs at auto_point1_pwm duty-cycle. */ | 1337 | * off or runs at auto_point1_pwm duty-cycle. */ |
| 1342 | if (val > ((data->pwm_min[ix] + 1) / 2)) { | 1338 | if (val > ((data->pwm_min[ix] + 1) / 2)) { |
| 1343 | data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, | 1339 | data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, |
| 1344 | dme1737_read(client, | 1340 | dme1737_read(data, |
| 1345 | DME1737_REG_PWM_RR(0))); | 1341 | DME1737_REG_PWM_RR(0))); |
| 1346 | } else { | 1342 | } else { |
| 1347 | data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, | 1343 | data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, |
| 1348 | dme1737_read(client, | 1344 | dme1737_read(data, |
| 1349 | DME1737_REG_PWM_RR(0))); | 1345 | DME1737_REG_PWM_RR(0))); |
| 1350 | } | 1346 | } |
| 1351 | dme1737_write(client, DME1737_REG_PWM_RR(0), | 1347 | dme1737_write(data, DME1737_REG_PWM_RR(0), |
| 1352 | data->pwm_rr[0]); | 1348 | data->pwm_rr[0]); |
| 1353 | break; | 1349 | break; |
| 1354 | case SYS_PWM_AUTO_POINT1_PWM: | 1350 | case SYS_PWM_AUTO_POINT1_PWM: |
| 1355 | /* Only valid for pwm[1-3] */ | 1351 | /* Only valid for pwm[1-3] */ |
| 1356 | data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255); | 1352 | data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255); |
| 1357 | dme1737_write(client, DME1737_REG_PWM_MIN(ix), | 1353 | dme1737_write(data, DME1737_REG_PWM_MIN(ix), |
| 1358 | data->pwm_min[ix]); | 1354 | data->pwm_min[ix]); |
| 1359 | break; | 1355 | break; |
| 1360 | default: | 1356 | default: |
| @@ -1402,7 +1398,7 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr, | |||
| 1402 | { | 1398 | { |
| 1403 | struct dme1737_data *data = dev_get_drvdata(dev); | 1399 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 1404 | 1400 | ||
| 1405 | return sprintf(buf, "%s\n", data->client.name); | 1401 | return sprintf(buf, "%s\n", data->name); |
| 1406 | } | 1402 | } |
| 1407 | 1403 | ||
| 1408 | /* --------------------------------------------------------------------- | 1404 | /* --------------------------------------------------------------------- |
| @@ -1908,7 +1904,7 @@ static void dme1737_remove_files(struct device *dev) | |||
| 1908 | 1904 | ||
| 1909 | sysfs_remove_group(&dev->kobj, &dme1737_group); | 1905 | sysfs_remove_group(&dev->kobj, &dme1737_group); |
| 1910 | 1906 | ||
| 1911 | if (!data->client.driver) { | 1907 | if (!data->client) { |
| 1912 | sysfs_remove_file(&dev->kobj, &dev_attr_name.attr); | 1908 | sysfs_remove_file(&dev->kobj, &dev_attr_name.attr); |
| 1913 | } | 1909 | } |
| 1914 | } | 1910 | } |
| @@ -1919,7 +1915,7 @@ static int dme1737_create_files(struct device *dev) | |||
| 1919 | int err, ix; | 1915 | int err, ix; |
| 1920 | 1916 | ||
| 1921 | /* Create a name attribute for ISA devices */ | 1917 | /* Create a name attribute for ISA devices */ |
| 1922 | if (!data->client.driver && | 1918 | if (!data->client && |
| 1923 | (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) { | 1919 | (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) { |
| 1924 | goto exit; | 1920 | goto exit; |
| 1925 | } | 1921 | } |
| @@ -2013,14 +2009,14 @@ exit: | |||
| 2013 | static int dme1737_init_device(struct device *dev) | 2009 | static int dme1737_init_device(struct device *dev) |
| 2014 | { | 2010 | { |
| 2015 | struct dme1737_data *data = dev_get_drvdata(dev); | 2011 | struct dme1737_data *data = dev_get_drvdata(dev); |
| 2016 | struct i2c_client *client = &data->client; | 2012 | struct i2c_client *client = data->client; |
| 2017 | int ix; | 2013 | int ix; |
| 2018 | u8 reg; | 2014 | u8 reg; |
| 2019 | 2015 | ||
| 2020 | /* Point to the right nominal voltages array */ | 2016 | /* Point to the right nominal voltages array */ |
| 2021 | data->in_nominal = IN_NOMINAL(data->type); | 2017 | data->in_nominal = IN_NOMINAL(data->type); |
| 2022 | 2018 | ||
| 2023 | data->config = dme1737_read(client, DME1737_REG_CONFIG); | 2019 | data->config = dme1737_read(data, DME1737_REG_CONFIG); |
| 2024 | /* Inform if part is not monitoring/started */ | 2020 | /* Inform if part is not monitoring/started */ |
| 2025 | if (!(data->config & 0x01)) { | 2021 | if (!(data->config & 0x01)) { |
| 2026 | if (!force_start) { | 2022 | if (!force_start) { |
| @@ -2032,7 +2028,7 @@ static int dme1737_init_device(struct device *dev) | |||
| 2032 | 2028 | ||
| 2033 | /* Force monitoring */ | 2029 | /* Force monitoring */ |
| 2034 | data->config |= 0x01; | 2030 | data->config |= 0x01; |
| 2035 | dme1737_write(client, DME1737_REG_CONFIG, data->config); | 2031 | dme1737_write(data, DME1737_REG_CONFIG, data->config); |
| 2036 | } | 2032 | } |
| 2037 | /* Inform if part is not ready */ | 2033 | /* Inform if part is not ready */ |
| 2038 | if (!(data->config & 0x04)) { | 2034 | if (!(data->config & 0x04)) { |
| @@ -2041,8 +2037,8 @@ static int dme1737_init_device(struct device *dev) | |||
| 2041 | } | 2037 | } |
| 2042 | 2038 | ||
| 2043 | /* Determine which optional fan and pwm features are enabled/present */ | 2039 | /* Determine which optional fan and pwm features are enabled/present */ |
| 2044 | if (client->driver) { /* I2C chip */ | 2040 | if (client) { /* I2C chip */ |
| 2045 | data->config2 = dme1737_read(client, DME1737_REG_CONFIG2); | 2041 | data->config2 = dme1737_read(data, DME1737_REG_CONFIG2); |
| 2046 | /* Check if optional fan3 input is enabled */ | 2042 | /* Check if optional fan3 input is enabled */ |
| 2047 | if (data->config2 & 0x04) { | 2043 | if (data->config2 & 0x04) { |
| 2048 | data->has_fan |= (1 << 2); | 2044 | data->has_fan |= (1 << 2); |
| @@ -2051,7 +2047,7 @@ static int dme1737_init_device(struct device *dev) | |||
| 2051 | /* Fan4 and pwm3 are only available if the client's I2C address | 2047 | /* Fan4 and pwm3 are only available if the client's I2C address |
| 2052 | * is the default 0x2e. Otherwise the I/Os associated with | 2048 | * is the default 0x2e. Otherwise the I/Os associated with |
| 2053 | * these functions are used for addr enable/select. */ | 2049 | * these functions are used for addr enable/select. */ |
| 2054 | if (data->client.addr == 0x2e) { | 2050 | if (client->addr == 0x2e) { |
| 2055 | data->has_fan |= (1 << 3); | 2051 | data->has_fan |= (1 << 3); |
| 2056 | data->has_pwm |= (1 << 2); | 2052 | data->has_pwm |= (1 << 2); |
| 2057 | } | 2053 | } |
| @@ -2086,16 +2082,16 @@ static int dme1737_init_device(struct device *dev) | |||
| 2086 | (data->has_fan & (1 << 4)) ? "yes" : "no", | 2082 | (data->has_fan & (1 << 4)) ? "yes" : "no", |
| 2087 | (data->has_fan & (1 << 5)) ? "yes" : "no"); | 2083 | (data->has_fan & (1 << 5)) ? "yes" : "no"); |
| 2088 | 2084 | ||
| 2089 | reg = dme1737_read(client, DME1737_REG_TACH_PWM); | 2085 | reg = dme1737_read(data, DME1737_REG_TACH_PWM); |
| 2090 | /* Inform if fan-to-pwm mapping differs from the default */ | 2086 | /* Inform if fan-to-pwm mapping differs from the default */ |
| 2091 | if (client->driver && reg != 0xa4) { /* I2C chip */ | 2087 | if (client && reg != 0xa4) { /* I2C chip */ |
| 2092 | dev_warn(dev, "Non-standard fan to pwm mapping: " | 2088 | dev_warn(dev, "Non-standard fan to pwm mapping: " |
| 2093 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " | 2089 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " |
| 2094 | "fan4->pwm%d. Please report to the driver " | 2090 | "fan4->pwm%d. Please report to the driver " |
| 2095 | "maintainer.\n", | 2091 | "maintainer.\n", |
| 2096 | (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, | 2092 | (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, |
| 2097 | ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1); | 2093 | ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1); |
| 2098 | } else if (!client->driver && reg != 0x24) { /* ISA chip */ | 2094 | } else if (!client && reg != 0x24) { /* ISA chip */ |
| 2099 | dev_warn(dev, "Non-standard fan to pwm mapping: " | 2095 | dev_warn(dev, "Non-standard fan to pwm mapping: " |
| 2100 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. " | 2096 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. " |
| 2101 | "Please report to the driver maintainer.\n", | 2097 | "Please report to the driver maintainer.\n", |
| @@ -2108,7 +2104,7 @@ static int dme1737_init_device(struct device *dev) | |||
| 2108 | * disabled). */ | 2104 | * disabled). */ |
| 2109 | if (!(data->config & 0x02)) { | 2105 | if (!(data->config & 0x02)) { |
| 2110 | for (ix = 0; ix < 3; ix++) { | 2106 | for (ix = 0; ix < 3; ix++) { |
| 2111 | data->pwm_config[ix] = dme1737_read(client, | 2107 | data->pwm_config[ix] = dme1737_read(data, |
| 2112 | DME1737_REG_PWM_CONFIG(ix)); | 2108 | DME1737_REG_PWM_CONFIG(ix)); |
| 2113 | if ((data->has_pwm & (1 << ix)) && | 2109 | if ((data->has_pwm & (1 << ix)) && |
| 2114 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { | 2110 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { |
| @@ -2116,8 +2112,8 @@ static int dme1737_init_device(struct device *dev) | |||
| 2116 | "manual mode.\n", ix + 1); | 2112 | "manual mode.\n", ix + 1); |
| 2117 | data->pwm_config[ix] = PWM_EN_TO_REG(1, | 2113 | data->pwm_config[ix] = PWM_EN_TO_REG(1, |
| 2118 | data->pwm_config[ix]); | 2114 | data->pwm_config[ix]); |
| 2119 | dme1737_write(client, DME1737_REG_PWM(ix), 0); | 2115 | dme1737_write(data, DME1737_REG_PWM(ix), 0); |
| 2120 | dme1737_write(client, | 2116 | dme1737_write(data, |
| 2121 | DME1737_REG_PWM_CONFIG(ix), | 2117 | DME1737_REG_PWM_CONFIG(ix), |
| 2122 | data->pwm_config[ix]); | 2118 | data->pwm_config[ix]); |
| 2123 | } | 2119 | } |
| @@ -2191,37 +2187,24 @@ exit: | |||
| 2191 | return err; | 2187 | return err; |
| 2192 | } | 2188 | } |
| 2193 | 2189 | ||
| 2194 | static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address, | 2190 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
| 2195 | int kind) | 2191 | static int dme1737_i2c_detect(struct i2c_client *client, int kind, |
| 2192 | struct i2c_board_info *info) | ||
| 2196 | { | 2193 | { |
| 2194 | struct i2c_adapter *adapter = client->adapter; | ||
| 2195 | struct device *dev = &adapter->dev; | ||
| 2197 | u8 company, verstep = 0; | 2196 | u8 company, verstep = 0; |
| 2198 | struct i2c_client *client; | ||
| 2199 | struct dme1737_data *data; | ||
| 2200 | struct device *dev; | ||
| 2201 | int err = 0; | ||
| 2202 | const char *name; | 2197 | const char *name; |
| 2203 | 2198 | ||
| 2204 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 2199 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
| 2205 | goto exit; | 2200 | return -ENODEV; |
| 2206 | } | ||
| 2207 | |||
| 2208 | if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) { | ||
| 2209 | err = -ENOMEM; | ||
| 2210 | goto exit; | ||
| 2211 | } | 2201 | } |
| 2212 | 2202 | ||
| 2213 | client = &data->client; | ||
| 2214 | i2c_set_clientdata(client, data); | ||
| 2215 | client->addr = address; | ||
| 2216 | client->adapter = adapter; | ||
| 2217 | client->driver = &dme1737_i2c_driver; | ||
| 2218 | dev = &client->dev; | ||
| 2219 | |||
| 2220 | /* A negative kind means that the driver was loaded with no force | 2203 | /* A negative kind means that the driver was loaded with no force |
| 2221 | * parameter (default), so we must identify the chip. */ | 2204 | * parameter (default), so we must identify the chip. */ |
| 2222 | if (kind < 0) { | 2205 | if (kind < 0) { |
| 2223 | company = dme1737_read(client, DME1737_REG_COMPANY); | 2206 | company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY); |
| 2224 | verstep = dme1737_read(client, DME1737_REG_VERSTEP); | 2207 | verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP); |
| 2225 | 2208 | ||
| 2226 | if (company == DME1737_COMPANY_SMSC && | 2209 | if (company == DME1737_COMPANY_SMSC && |
| 2227 | (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { | 2210 | (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { |
| @@ -2230,8 +2213,7 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address, | |||
| 2230 | verstep == SCH5027_VERSTEP) { | 2213 | verstep == SCH5027_VERSTEP) { |
| 2231 | kind = sch5027; | 2214 | kind = sch5027; |
| 2232 | } else { | 2215 | } else { |
| 2233 | err = -ENODEV; | 2216 | return -ENODEV; |
| 2234 | goto exit_kfree; | ||
| 2235 | } | 2217 | } |
| 2236 | } | 2218 | } |
| 2237 | 2219 | ||
| @@ -2241,32 +2223,44 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address, | |||
| 2241 | kind = dme1737; | 2223 | kind = dme1737; |
| 2242 | name = "dme1737"; | 2224 | name = "dme1737"; |
| 2243 | } | 2225 | } |
| 2244 | data->type = kind; | ||
| 2245 | |||
| 2246 | /* Fill in the remaining client fields and put it into the global | ||
| 2247 | * list */ | ||
| 2248 | strlcpy(client->name, name, I2C_NAME_SIZE); | ||
| 2249 | mutex_init(&data->update_lock); | ||
| 2250 | |||
| 2251 | /* Tell the I2C layer a new client has arrived */ | ||
| 2252 | if ((err = i2c_attach_client(client))) { | ||
| 2253 | goto exit_kfree; | ||
| 2254 | } | ||
| 2255 | 2226 | ||
| 2256 | dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", | 2227 | dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", |
| 2257 | kind == sch5027 ? "SCH5027" : "DME1737", client->addr, | 2228 | kind == sch5027 ? "SCH5027" : "DME1737", client->addr, |
| 2258 | verstep); | 2229 | verstep); |
| 2230 | strlcpy(info->type, name, I2C_NAME_SIZE); | ||
| 2231 | |||
| 2232 | return 0; | ||
| 2233 | } | ||
| 2234 | |||
| 2235 | static int dme1737_i2c_probe(struct i2c_client *client, | ||
| 2236 | const struct i2c_device_id *id) | ||
| 2237 | { | ||
| 2238 | struct dme1737_data *data; | ||
| 2239 | struct device *dev = &client->dev; | ||
| 2240 | int err; | ||
| 2241 | |||
| 2242 | data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL); | ||
| 2243 | if (!data) { | ||
| 2244 | err = -ENOMEM; | ||
| 2245 | goto exit; | ||
| 2246 | } | ||
| 2247 | |||
| 2248 | i2c_set_clientdata(client, data); | ||
| 2249 | data->type = id->driver_data; | ||
| 2250 | data->client = client; | ||
| 2251 | data->name = client->name; | ||
| 2252 | mutex_init(&data->update_lock); | ||
| 2259 | 2253 | ||
| 2260 | /* Initialize the DME1737 chip */ | 2254 | /* Initialize the DME1737 chip */ |
| 2261 | if ((err = dme1737_init_device(dev))) { | 2255 | if ((err = dme1737_init_device(dev))) { |
| 2262 | dev_err(dev, "Failed to initialize device.\n"); | 2256 | dev_err(dev, "Failed to initialize device.\n"); |
| 2263 | goto exit_detach; | 2257 | goto exit_kfree; |
| 2264 | } | 2258 | } |
| 2265 | 2259 | ||
| 2266 | /* Create sysfs files */ | 2260 | /* Create sysfs files */ |
| 2267 | if ((err = dme1737_create_files(dev))) { | 2261 | if ((err = dme1737_create_files(dev))) { |
| 2268 | dev_err(dev, "Failed to create sysfs files.\n"); | 2262 | dev_err(dev, "Failed to create sysfs files.\n"); |
| 2269 | goto exit_detach; | 2263 | goto exit_kfree; |
| 2270 | } | 2264 | } |
| 2271 | 2265 | ||
| 2272 | /* Register device */ | 2266 | /* Register device */ |
| @@ -2281,45 +2275,40 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address, | |||
| 2281 | 2275 | ||
| 2282 | exit_remove: | 2276 | exit_remove: |
| 2283 | dme1737_remove_files(dev); | 2277 | dme1737_remove_files(dev); |
| 2284 | exit_detach: | ||
| 2285 | i2c_detach_client(client); | ||
| 2286 | exit_kfree: | 2278 | exit_kfree: |
| 2287 | kfree(data); | 2279 | kfree(data); |
| 2288 | exit: | 2280 | exit: |
| 2289 | return err; | 2281 | return err; |
| 2290 | } | 2282 | } |
| 2291 | 2283 | ||
| 2292 | static int dme1737_i2c_attach_adapter(struct i2c_adapter *adapter) | 2284 | static int dme1737_i2c_remove(struct i2c_client *client) |
| 2293 | { | ||
| 2294 | if (!(adapter->class & I2C_CLASS_HWMON)) { | ||
| 2295 | return 0; | ||
| 2296 | } | ||
| 2297 | |||
| 2298 | return i2c_probe(adapter, &addr_data, dme1737_i2c_detect); | ||
| 2299 | } | ||
| 2300 | |||
| 2301 | static int dme1737_i2c_detach_client(struct i2c_client *client) | ||
| 2302 | { | 2285 | { |
| 2303 | struct dme1737_data *data = i2c_get_clientdata(client); | 2286 | struct dme1737_data *data = i2c_get_clientdata(client); |
| 2304 | int err; | ||
| 2305 | 2287 | ||
| 2306 | hwmon_device_unregister(data->hwmon_dev); | 2288 | hwmon_device_unregister(data->hwmon_dev); |
| 2307 | dme1737_remove_files(&client->dev); | 2289 | dme1737_remove_files(&client->dev); |
| 2308 | 2290 | ||
| 2309 | if ((err = i2c_detach_client(client))) { | ||
| 2310 | return err; | ||
| 2311 | } | ||
| 2312 | |||
| 2313 | kfree(data); | 2291 | kfree(data); |
| 2314 | return 0; | 2292 | return 0; |
| 2315 | } | 2293 | } |
| 2316 | 2294 | ||
| 2295 | static const struct i2c_device_id dme1737_id[] = { | ||
| 2296 | { "dme1737", dme1737 }, | ||
| 2297 | { "sch5027", sch5027 }, | ||
| 2298 | { } | ||
| 2299 | }; | ||
| 2300 | MODULE_DEVICE_TABLE(i2c, dme1737_id); | ||
| 2301 | |||
| 2317 | static struct i2c_driver dme1737_i2c_driver = { | 2302 | static struct i2c_driver dme1737_i2c_driver = { |
| 2303 | .class = I2C_CLASS_HWMON, | ||
| 2318 | .driver = { | 2304 | .driver = { |
| 2319 | .name = "dme1737", | 2305 | .name = "dme1737", |
| 2320 | }, | 2306 | }, |
| 2321 | .attach_adapter = dme1737_i2c_attach_adapter, | 2307 | .probe = dme1737_i2c_probe, |
| 2322 | .detach_client = dme1737_i2c_detach_client, | 2308 | .remove = dme1737_i2c_remove, |
| 2309 | .id_table = dme1737_id, | ||
| 2310 | .detect = dme1737_i2c_detect, | ||
| 2311 | .address_data = &addr_data, | ||
| 2323 | }; | 2312 | }; |
| 2324 | 2313 | ||
| 2325 | /* --------------------------------------------------------------------- | 2314 | /* --------------------------------------------------------------------- |
| @@ -2403,7 +2392,6 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev) | |||
| 2403 | { | 2392 | { |
| 2404 | u8 company, device; | 2393 | u8 company, device; |
| 2405 | struct resource *res; | 2394 | struct resource *res; |
| 2406 | struct i2c_client *client; | ||
| 2407 | struct dme1737_data *data; | 2395 | struct dme1737_data *data; |
| 2408 | struct device *dev = &pdev->dev; | 2396 | struct device *dev = &pdev->dev; |
| 2409 | int err; | 2397 | int err; |
| @@ -2422,15 +2410,13 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev) | |||
| 2422 | goto exit_release_region; | 2410 | goto exit_release_region; |
| 2423 | } | 2411 | } |
| 2424 | 2412 | ||
| 2425 | client = &data->client; | 2413 | data->addr = res->start; |
| 2426 | i2c_set_clientdata(client, data); | ||
| 2427 | client->addr = res->start; | ||
| 2428 | platform_set_drvdata(pdev, data); | 2414 | platform_set_drvdata(pdev, data); |
| 2429 | 2415 | ||
| 2430 | /* Skip chip detection if module is loaded with force_id parameter */ | 2416 | /* Skip chip detection if module is loaded with force_id parameter */ |
| 2431 | if (!force_id) { | 2417 | if (!force_id) { |
| 2432 | company = dme1737_read(client, DME1737_REG_COMPANY); | 2418 | company = dme1737_read(data, DME1737_REG_COMPANY); |
| 2433 | device = dme1737_read(client, DME1737_REG_DEVICE); | 2419 | device = dme1737_read(data, DME1737_REG_DEVICE); |
| 2434 | 2420 | ||
| 2435 | if (!((company == DME1737_COMPANY_SMSC) && | 2421 | if (!((company == DME1737_COMPANY_SMSC) && |
| 2436 | (device == SCH311X_DEVICE))) { | 2422 | (device == SCH311X_DEVICE))) { |
| @@ -2441,10 +2427,10 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev) | |||
| 2441 | data->type = sch311x; | 2427 | data->type = sch311x; |
| 2442 | 2428 | ||
| 2443 | /* Fill in the remaining client fields and initialize the mutex */ | 2429 | /* Fill in the remaining client fields and initialize the mutex */ |
| 2444 | strlcpy(client->name, "sch311x", I2C_NAME_SIZE); | 2430 | data->name = "sch311x"; |
| 2445 | mutex_init(&data->update_lock); | 2431 | mutex_init(&data->update_lock); |
| 2446 | 2432 | ||
| 2447 | dev_info(dev, "Found a SCH311x chip at 0x%04x\n", client->addr); | 2433 | dev_info(dev, "Found a SCH311x chip at 0x%04x\n", data->addr); |
| 2448 | 2434 | ||
| 2449 | /* Initialize the chip */ | 2435 | /* Initialize the chip */ |
| 2450 | if ((err = dme1737_init_device(dev))) { | 2436 | if ((err = dme1737_init_device(dev))) { |
| @@ -2485,7 +2471,7 @@ static int __devexit dme1737_isa_remove(struct platform_device *pdev) | |||
| 2485 | 2471 | ||
| 2486 | hwmon_device_unregister(data->hwmon_dev); | 2472 | hwmon_device_unregister(data->hwmon_dev); |
| 2487 | dme1737_remove_files(&pdev->dev); | 2473 | dme1737_remove_files(&pdev->dev); |
| 2488 | release_region(data->client.addr, DME1737_EXTENT); | 2474 | release_region(data->addr, DME1737_EXTENT); |
| 2489 | platform_set_drvdata(pdev, NULL); | 2475 | platform_set_drvdata(pdev, NULL); |
| 2490 | kfree(data); | 2476 | kfree(data); |
| 2491 | 2477 | ||
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 6ee997b2817c..acadbc51fc0f 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
| @@ -55,7 +55,7 @@ config I2C_AMD756 | |||
| 55 | 55 | ||
| 56 | config I2C_AMD756_S4882 | 56 | config I2C_AMD756_S4882 |
| 57 | tristate "SMBus multiplexing on the Tyan S4882" | 57 | tristate "SMBus multiplexing on the Tyan S4882" |
| 58 | depends on I2C_AMD756 && EXPERIMENTAL | 58 | depends on I2C_AMD756 && X86 && EXPERIMENTAL |
| 59 | help | 59 | help |
| 60 | Enabling this option will add specific SMBus support for the Tyan | 60 | Enabling this option will add specific SMBus support for the Tyan |
| 61 | S4882 motherboard. On this 4-CPU board, the SMBus is multiplexed | 61 | S4882 motherboard. On this 4-CPU board, the SMBus is multiplexed |
| @@ -148,7 +148,7 @@ config I2C_NFORCE2 | |||
| 148 | 148 | ||
| 149 | config I2C_NFORCE2_S4985 | 149 | config I2C_NFORCE2_S4985 |
| 150 | tristate "SMBus multiplexing on the Tyan S4985" | 150 | tristate "SMBus multiplexing on the Tyan S4985" |
| 151 | depends on I2C_NFORCE2 && EXPERIMENTAL | 151 | depends on I2C_NFORCE2 && X86 && EXPERIMENTAL |
| 152 | help | 152 | help |
| 153 | Enabling this option will add specific SMBus support for the Tyan | 153 | Enabling this option will add specific SMBus support for the Tyan |
| 154 | S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed | 154 | S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed |
| @@ -209,7 +209,7 @@ config I2C_VIA | |||
| 209 | will be called i2c-via. | 209 | will be called i2c-via. |
| 210 | 210 | ||
| 211 | config I2C_VIAPRO | 211 | config I2C_VIAPRO |
| 212 | tristate "VIA VT82C596/82C686/82xx and CX700" | 212 | tristate "VIA VT82C596/82C686/82xx and CX700/VX800/VX820" |
| 213 | depends on PCI | 213 | depends on PCI |
| 214 | help | 214 | help |
| 215 | If you say yes to this option, support will be included for the VIA | 215 | If you say yes to this option, support will be included for the VIA |
| @@ -223,6 +223,8 @@ config I2C_VIAPRO | |||
| 223 | VT8237R/A/S | 223 | VT8237R/A/S |
| 224 | VT8251 | 224 | VT8251 |
| 225 | CX700 | 225 | CX700 |
| 226 | VX800 | ||
| 227 | VX820 | ||
| 226 | 228 | ||
| 227 | This driver can also be built as a module. If so, the module | 229 | This driver can also be built as a module. If so, the module |
| 228 | will be called i2c-viapro. | 230 | will be called i2c-viapro. |
| @@ -330,6 +332,18 @@ config I2C_GPIO | |||
| 330 | This is a very simple bitbanging I2C driver utilizing the | 332 | This is a very simple bitbanging I2C driver utilizing the |
| 331 | arch-neutral GPIO API to control the SCL and SDA lines. | 333 | arch-neutral GPIO API to control the SCL and SDA lines. |
| 332 | 334 | ||
| 335 | config I2C_HIGHLANDER | ||
| 336 | tristate "Highlander FPGA SMBus interface" | ||
| 337 | depends on SH_HIGHLANDER | ||
| 338 | help | ||
| 339 | If you say yes to this option, support will be included for | ||
| 340 | the SMBus interface located in the FPGA on various Highlander | ||
| 341 | boards, particularly the R0P7780LC0011RL and R0P7785LC0011RL | ||
| 342 | FPGAs. This is wholly unrelated to the SoC I2C. | ||
| 343 | |||
| 344 | This driver can also be built as a module. If so, the module | ||
| 345 | will be called i2c-highlander. | ||
| 346 | |||
| 333 | config I2C_IBM_IIC | 347 | config I2C_IBM_IIC |
| 334 | tristate "IBM PPC 4xx on-chip I2C interface" | 348 | tristate "IBM PPC 4xx on-chip I2C interface" |
| 335 | depends on 4xx | 349 | depends on 4xx |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 97dbfa2107fe..0c2c4b26cdf1 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
| @@ -31,6 +31,7 @@ obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o | |||
| 31 | obj-$(CONFIG_I2C_CPM) += i2c-cpm.o | 31 | obj-$(CONFIG_I2C_CPM) += i2c-cpm.o |
| 32 | obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o | 32 | obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o |
| 33 | obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o | 33 | obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o |
| 34 | obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o | ||
| 34 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o | 35 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o |
| 35 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o | 36 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o |
| 36 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o | 37 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o |
diff --git a/drivers/i2c/busses/i2c-highlander.c b/drivers/i2c/busses/i2c-highlander.c new file mode 100644 index 000000000000..f4d22ae9d294 --- /dev/null +++ b/drivers/i2c/busses/i2c-highlander.c | |||
| @@ -0,0 +1,498 @@ | |||
| 1 | /* | ||
| 2 | * Renesas Solutions Highlander FPGA I2C/SMBus support. | ||
| 3 | * | ||
| 4 | * Supported devices: R0P7780LC0011RL, R0P7785LC0011RL | ||
| 5 | * | ||
| 6 | * Copyright (C) 2008 Paul Mundt | ||
| 7 | * Copyright (C) 2008 Renesas Solutions Corp. | ||
| 8 | * Copyright (C) 2008 Atom Create Engineering Co., Ltd. | ||
| 9 | * | ||
| 10 | * This file is subject to the terms and conditions of the GNU General | ||
| 11 | * Public License version 2. See the file "COPYING" in the main directory | ||
| 12 | * of this archive for more details. | ||
| 13 | */ | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/interrupt.h> | ||
| 17 | #include <linux/i2c.h> | ||
| 18 | #include <linux/platform_device.h> | ||
| 19 | #include <linux/completion.h> | ||
| 20 | #include <linux/io.h> | ||
| 21 | #include <linux/delay.h> | ||
| 22 | |||
| 23 | #define SMCR 0x00 | ||
| 24 | #define SMCR_START (1 << 0) | ||
| 25 | #define SMCR_IRIC (1 << 1) | ||
| 26 | #define SMCR_BBSY (1 << 2) | ||
| 27 | #define SMCR_ACKE (1 << 3) | ||
| 28 | #define SMCR_RST (1 << 4) | ||
| 29 | #define SMCR_IEIC (1 << 6) | ||
| 30 | |||
| 31 | #define SMSMADR 0x02 | ||
| 32 | |||
| 33 | #define SMMR 0x04 | ||
| 34 | #define SMMR_MODE0 (1 << 0) | ||
| 35 | #define SMMR_MODE1 (1 << 1) | ||
| 36 | #define SMMR_CAP (1 << 3) | ||
| 37 | #define SMMR_TMMD (1 << 4) | ||
| 38 | #define SMMR_SP (1 << 7) | ||
| 39 | |||
| 40 | #define SMSADR 0x06 | ||
| 41 | #define SMTRDR 0x46 | ||
| 42 | |||
| 43 | struct highlander_i2c_dev { | ||
| 44 | struct device *dev; | ||
| 45 | void __iomem *base; | ||
| 46 | struct i2c_adapter adapter; | ||
| 47 | struct completion cmd_complete; | ||
| 48 | unsigned long last_read_time; | ||
| 49 | int irq; | ||
| 50 | u8 *buf; | ||
| 51 | size_t buf_len; | ||
| 52 | }; | ||
| 53 | |||
| 54 | static int iic_force_poll, iic_force_normal; | ||
| 55 | static int iic_timeout = 1000, iic_read_delay; | ||
| 56 | |||
| 57 | static inline void highlander_i2c_irq_enable(struct highlander_i2c_dev *dev) | ||
| 58 | { | ||
| 59 | iowrite16(ioread16(dev->base + SMCR) | SMCR_IEIC, dev->base + SMCR); | ||
| 60 | } | ||
| 61 | |||
| 62 | static inline void highlander_i2c_irq_disable(struct highlander_i2c_dev *dev) | ||
| 63 | { | ||
| 64 | iowrite16(ioread16(dev->base + SMCR) & ~SMCR_IEIC, dev->base + SMCR); | ||
| 65 | } | ||
| 66 | |||
| 67 | static inline void highlander_i2c_start(struct highlander_i2c_dev *dev) | ||
| 68 | { | ||
| 69 | iowrite16(ioread16(dev->base + SMCR) | SMCR_START, dev->base + SMCR); | ||
| 70 | } | ||
| 71 | |||
| 72 | static inline void highlander_i2c_done(struct highlander_i2c_dev *dev) | ||
| 73 | { | ||
| 74 | iowrite16(ioread16(dev->base + SMCR) | SMCR_IRIC, dev->base + SMCR); | ||
| 75 | } | ||
| 76 | |||
| 77 | static void highlander_i2c_setup(struct highlander_i2c_dev *dev) | ||
| 78 | { | ||
| 79 | u16 smmr; | ||
| 80 | |||
| 81 | smmr = ioread16(dev->base + SMMR); | ||
| 82 | smmr |= SMMR_TMMD; | ||
| 83 | |||
| 84 | if (iic_force_normal) | ||
| 85 | smmr &= ~SMMR_SP; | ||
| 86 | else | ||
| 87 | smmr |= SMMR_SP; | ||
| 88 | |||
| 89 | iowrite16(smmr, dev->base + SMMR); | ||
| 90 | } | ||
| 91 | |||
| 92 | static void smbus_write_data(u8 *src, u16 *dst, int len) | ||
| 93 | { | ||
| 94 | for (; len > 1; len -= 2) { | ||
| 95 | *dst++ = be16_to_cpup((u16 *)src); | ||
| 96 | src += 2; | ||
| 97 | } | ||
| 98 | |||
| 99 | if (len) | ||
| 100 | *dst = *src << 8; | ||
| 101 | } | ||
| 102 | |||
| 103 | static void smbus_read_data(u16 *src, u8 *dst, int len) | ||
| 104 | { | ||
| 105 | for (; len > 1; len -= 2) { | ||
| 106 | *(u16 *)dst = cpu_to_be16p(src++); | ||
| 107 | dst += 2; | ||
| 108 | } | ||
| 109 | |||
| 110 | if (len) | ||
| 111 | *dst = *src >> 8; | ||
| 112 | } | ||
| 113 | |||
| 114 | static void highlander_i2c_command(struct highlander_i2c_dev *dev, | ||
| 115 | u8 command, int len) | ||
| 116 | { | ||
| 117 | unsigned int i; | ||
| 118 | u16 cmd = (command << 8) | command; | ||
| 119 | |||
| 120 | for (i = 0; i < len; i += 2) { | ||
| 121 | if (len - i == 1) | ||
| 122 | cmd = command << 8; | ||
| 123 | iowrite16(cmd, dev->base + SMSADR + i); | ||
| 124 | dev_dbg(dev->dev, "command data[%x] 0x%04x\n", i/2, cmd); | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | static int highlander_i2c_wait_for_bbsy(struct highlander_i2c_dev *dev) | ||
| 129 | { | ||
| 130 | unsigned long timeout; | ||
| 131 | |||
| 132 | timeout = jiffies + msecs_to_jiffies(iic_timeout); | ||
| 133 | while (ioread16(dev->base + SMCR) & SMCR_BBSY) { | ||
| 134 | if (time_after(jiffies, timeout)) { | ||
| 135 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); | ||
| 136 | return -ETIMEDOUT; | ||
| 137 | } | ||
| 138 | |||
| 139 | msleep(1); | ||
| 140 | } | ||
| 141 | |||
| 142 | return 0; | ||
| 143 | } | ||
| 144 | |||
| 145 | static int highlander_i2c_reset(struct highlander_i2c_dev *dev) | ||
| 146 | { | ||
| 147 | iowrite16(ioread16(dev->base + SMCR) | SMCR_RST, dev->base + SMCR); | ||
| 148 | return highlander_i2c_wait_for_bbsy(dev); | ||
| 149 | } | ||
| 150 | |||
| 151 | static int highlander_i2c_wait_for_ack(struct highlander_i2c_dev *dev) | ||
| 152 | { | ||
| 153 | u16 tmp = ioread16(dev->base + SMCR); | ||
| 154 | |||
| 155 | if ((tmp & (SMCR_IRIC | SMCR_ACKE)) == SMCR_ACKE) { | ||
| 156 | dev_warn(dev->dev, "ack abnormality\n"); | ||
| 157 | return highlander_i2c_reset(dev); | ||
| 158 | } | ||
| 159 | |||
| 160 | return 0; | ||
| 161 | } | ||
| 162 | |||
| 163 | static irqreturn_t highlander_i2c_irq(int irq, void *dev_id) | ||
| 164 | { | ||
| 165 | struct highlander_i2c_dev *dev = dev_id; | ||
| 166 | |||
| 167 | highlander_i2c_done(dev); | ||
| 168 | complete(&dev->cmd_complete); | ||
| 169 | |||
| 170 | return IRQ_HANDLED; | ||
| 171 | } | ||
| 172 | |||
| 173 | static void highlander_i2c_poll(struct highlander_i2c_dev *dev) | ||
| 174 | { | ||
| 175 | unsigned long timeout; | ||
| 176 | u16 smcr; | ||
| 177 | |||
| 178 | timeout = jiffies + msecs_to_jiffies(iic_timeout); | ||
| 179 | for (;;) { | ||
| 180 | smcr = ioread16(dev->base + SMCR); | ||
| 181 | |||
| 182 | /* | ||
| 183 | * Don't bother checking ACKE here, this and the reset | ||
| 184 | * are handled in highlander_i2c_wait_xfer_done() when | ||
| 185 | * waiting for the ACK. | ||
| 186 | */ | ||
| 187 | |||
| 188 | if (smcr & SMCR_IRIC) | ||
| 189 | return; | ||
| 190 | if (time_after(jiffies, timeout)) | ||
| 191 | break; | ||
| 192 | |||
| 193 | cpu_relax(); | ||
| 194 | cond_resched(); | ||
| 195 | } | ||
| 196 | |||
| 197 | dev_err(dev->dev, "polling timed out\n"); | ||
| 198 | } | ||
| 199 | |||
| 200 | static inline int highlander_i2c_wait_xfer_done(struct highlander_i2c_dev *dev) | ||
| 201 | { | ||
| 202 | if (dev->irq) | ||
| 203 | wait_for_completion_timeout(&dev->cmd_complete, | ||
| 204 | msecs_to_jiffies(iic_timeout)); | ||
| 205 | else | ||
| 206 | /* busy looping, the IRQ of champions */ | ||
| 207 | highlander_i2c_poll(dev); | ||
| 208 | |||
| 209 | return highlander_i2c_wait_for_ack(dev); | ||
| 210 | } | ||
| 211 | |||
| 212 | static int highlander_i2c_read(struct highlander_i2c_dev *dev) | ||
| 213 | { | ||
| 214 | int i, cnt; | ||
| 215 | u16 data[16]; | ||
| 216 | |||
| 217 | if (highlander_i2c_wait_for_bbsy(dev)) | ||
| 218 | return -EAGAIN; | ||
| 219 | |||
| 220 | highlander_i2c_start(dev); | ||
| 221 | |||
| 222 | if (highlander_i2c_wait_xfer_done(dev)) { | ||
| 223 | dev_err(dev->dev, "Arbitration loss\n"); | ||
| 224 | return -EAGAIN; | ||
| 225 | } | ||
| 226 | |||
| 227 | /* | ||
| 228 | * The R0P7780LC0011RL FPGA needs a significant delay between | ||
| 229 | * data read cycles, otherwise the transciever gets confused and | ||
| 230 | * garbage is returned when the read is subsequently aborted. | ||
| 231 | * | ||
| 232 | * It is not sufficient to wait for BBSY. | ||
| 233 | * | ||
| 234 | * While this generally only applies to the older SH7780-based | ||
| 235 | * Highlanders, the same issue can be observed on SH7785 ones, | ||
| 236 | * albeit less frequently. SH7780-based Highlanders may need | ||
| 237 | * this to be as high as 1000 ms. | ||
| 238 | */ | ||
| 239 | if (iic_read_delay && time_before(jiffies, dev->last_read_time + | ||
| 240 | msecs_to_jiffies(iic_read_delay))) | ||
| 241 | msleep(jiffies_to_msecs((dev->last_read_time + | ||
| 242 | msecs_to_jiffies(iic_read_delay)) - jiffies)); | ||
| 243 | |||
| 244 | cnt = (dev->buf_len + 1) >> 1; | ||
| 245 | for (i = 0; i < cnt; i++) { | ||
| 246 | data[i] = ioread16(dev->base + SMTRDR + (i * sizeof(u16))); | ||
| 247 | dev_dbg(dev->dev, "read data[%x] 0x%04x\n", i, data[i]); | ||
| 248 | } | ||
| 249 | |||
| 250 | smbus_read_data(data, dev->buf, dev->buf_len); | ||
| 251 | |||
| 252 | dev->last_read_time = jiffies; | ||
| 253 | |||
| 254 | return 0; | ||
| 255 | } | ||
| 256 | |||
| 257 | static int highlander_i2c_write(struct highlander_i2c_dev *dev) | ||
| 258 | { | ||
| 259 | int i, cnt; | ||
| 260 | u16 data[16]; | ||
| 261 | |||
| 262 | smbus_write_data(dev->buf, data, dev->buf_len); | ||
| 263 | |||
| 264 | cnt = (dev->buf_len + 1) >> 1; | ||
| 265 | for (i = 0; i < cnt; i++) { | ||
| 266 | iowrite16(data[i], dev->base + SMTRDR + (i * sizeof(u16))); | ||
| 267 | dev_dbg(dev->dev, "write data[%x] 0x%04x\n", i, data[i]); | ||
| 268 | } | ||
| 269 | |||
| 270 | if (highlander_i2c_wait_for_bbsy(dev)) | ||
| 271 | return -EAGAIN; | ||
| 272 | |||
| 273 | highlander_i2c_start(dev); | ||
| 274 | |||
| 275 | return highlander_i2c_wait_xfer_done(dev); | ||
| 276 | } | ||
| 277 | |||
| 278 | static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr, | ||
| 279 | unsigned short flags, char read_write, | ||
| 280 | u8 command, int size, | ||
| 281 | union i2c_smbus_data *data) | ||
| 282 | { | ||
| 283 | struct highlander_i2c_dev *dev = i2c_get_adapdata(adap); | ||
| 284 | int read = read_write & I2C_SMBUS_READ; | ||
| 285 | u16 tmp; | ||
| 286 | |||
| 287 | init_completion(&dev->cmd_complete); | ||
| 288 | |||
| 289 | dev_dbg(dev->dev, "addr %04x, command %02x, read_write %d, size %d\n", | ||
| 290 | addr, command, read_write, size); | ||
| 291 | |||
| 292 | /* | ||
| 293 | * Set up the buffer and transfer size | ||
| 294 | */ | ||
| 295 | switch (size) { | ||
| 296 | case I2C_SMBUS_BYTE_DATA: | ||
| 297 | dev->buf = &data->byte; | ||
| 298 | dev->buf_len = 1; | ||
| 299 | break; | ||
| 300 | case I2C_SMBUS_I2C_BLOCK_DATA: | ||
| 301 | dev->buf = &data->block[1]; | ||
| 302 | dev->buf_len = data->block[0]; | ||
| 303 | break; | ||
| 304 | default: | ||
| 305 | dev_err(dev->dev, "unsupported command %d\n", size); | ||
| 306 | return -EINVAL; | ||
| 307 | } | ||
| 308 | |||
| 309 | /* | ||
| 310 | * Encode the mode setting | ||
| 311 | */ | ||
| 312 | tmp = ioread16(dev->base + SMMR); | ||
| 313 | tmp &= ~(SMMR_MODE0 | SMMR_MODE1); | ||
| 314 | |||
| 315 | switch (dev->buf_len) { | ||
| 316 | case 1: | ||
| 317 | /* default */ | ||
| 318 | break; | ||
| 319 | case 8: | ||
| 320 | tmp |= SMMR_MODE0; | ||
| 321 | break; | ||
| 322 | case 16: | ||
| 323 | tmp |= SMMR_MODE1; | ||
| 324 | break; | ||
| 325 | case 32: | ||
| 326 | tmp |= (SMMR_MODE0 | SMMR_MODE1); | ||
| 327 | break; | ||
| 328 | default: | ||
| 329 | dev_err(dev->dev, "unsupported xfer size %d\n", dev->buf_len); | ||
| 330 | return -EINVAL; | ||
| 331 | } | ||
| 332 | |||
| 333 | iowrite16(tmp, dev->base + SMMR); | ||
| 334 | |||
| 335 | /* Ensure we're in a sane state */ | ||
| 336 | highlander_i2c_done(dev); | ||
| 337 | |||
| 338 | /* Set slave address */ | ||
| 339 | iowrite16((addr << 1) | read, dev->base + SMSMADR); | ||
| 340 | |||
| 341 | highlander_i2c_command(dev, command, dev->buf_len); | ||
| 342 | |||
| 343 | if (read) | ||
| 344 | return highlander_i2c_read(dev); | ||
| 345 | else | ||
| 346 | return highlander_i2c_write(dev); | ||
| 347 | } | ||
| 348 | |||
| 349 | static u32 highlander_i2c_func(struct i2c_adapter *adapter) | ||
| 350 | { | ||
| 351 | return I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK; | ||
| 352 | } | ||
| 353 | |||
| 354 | static const struct i2c_algorithm highlander_i2c_algo = { | ||
| 355 | .smbus_xfer = highlander_i2c_smbus_xfer, | ||
| 356 | .functionality = highlander_i2c_func, | ||
| 357 | }; | ||
| 358 | |||
| 359 | static int __devinit highlander_i2c_probe(struct platform_device *pdev) | ||
| 360 | { | ||
| 361 | struct highlander_i2c_dev *dev; | ||
| 362 | struct i2c_adapter *adap; | ||
| 363 | struct resource *res; | ||
| 364 | int ret; | ||
| 365 | |||
| 366 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 367 | if (unlikely(!res)) { | ||
| 368 | dev_err(&pdev->dev, "no mem resource\n"); | ||
| 369 | return -ENODEV; | ||
| 370 | } | ||
| 371 | |||
| 372 | dev = kzalloc(sizeof(struct highlander_i2c_dev), GFP_KERNEL); | ||
| 373 | if (unlikely(!dev)) | ||
| 374 | return -ENOMEM; | ||
| 375 | |||
| 376 | dev->base = ioremap_nocache(res->start, res->end - res->start + 1); | ||
| 377 | if (unlikely(!dev->base)) { | ||
| 378 | ret = -ENXIO; | ||
| 379 | goto err; | ||
| 380 | } | ||
| 381 | |||
| 382 | dev->dev = &pdev->dev; | ||
| 383 | platform_set_drvdata(pdev, dev); | ||
| 384 | |||
| 385 | dev->irq = platform_get_irq(pdev, 0); | ||
| 386 | if (iic_force_poll) | ||
| 387 | dev->irq = 0; | ||
| 388 | |||
| 389 | if (dev->irq) { | ||
| 390 | ret = request_irq(dev->irq, highlander_i2c_irq, IRQF_DISABLED, | ||
| 391 | pdev->name, dev); | ||
| 392 | if (unlikely(ret)) | ||
| 393 | goto err_unmap; | ||
| 394 | |||
| 395 | highlander_i2c_irq_enable(dev); | ||
| 396 | } else { | ||
| 397 | dev_notice(&pdev->dev, "no IRQ, using polling mode\n"); | ||
| 398 | highlander_i2c_irq_disable(dev); | ||
| 399 | } | ||
| 400 | |||
| 401 | dev->last_read_time = jiffies; /* initial read jiffies */ | ||
| 402 | |||
| 403 | highlander_i2c_setup(dev); | ||
| 404 | |||
| 405 | adap = &dev->adapter; | ||
| 406 | i2c_set_adapdata(adap, dev); | ||
| 407 | adap->owner = THIS_MODULE; | ||
| 408 | adap->class = I2C_CLASS_HWMON; | ||
| 409 | strlcpy(adap->name, "HL FPGA I2C adapter", sizeof(adap->name)); | ||
| 410 | adap->algo = &highlander_i2c_algo; | ||
| 411 | adap->dev.parent = &pdev->dev; | ||
| 412 | adap->nr = pdev->id; | ||
| 413 | |||
| 414 | /* | ||
| 415 | * Reset the adapter | ||
| 416 | */ | ||
| 417 | ret = highlander_i2c_reset(dev); | ||
| 418 | if (unlikely(ret)) { | ||
| 419 | dev_err(&pdev->dev, "controller didn't come up\n"); | ||
| 420 | goto err_free_irq; | ||
| 421 | } | ||
| 422 | |||
| 423 | ret = i2c_add_numbered_adapter(adap); | ||
| 424 | if (unlikely(ret)) { | ||
| 425 | dev_err(&pdev->dev, "failure adding adapter\n"); | ||
| 426 | goto err_free_irq; | ||
| 427 | } | ||
| 428 | |||
| 429 | return 0; | ||
| 430 | |||
| 431 | err_free_irq: | ||
| 432 | if (dev->irq) | ||
| 433 | free_irq(dev->irq, dev); | ||
| 434 | err_unmap: | ||
| 435 | iounmap(dev->base); | ||
| 436 | err: | ||
| 437 | kfree(dev); | ||
| 438 | |||
| 439 | platform_set_drvdata(pdev, NULL); | ||
| 440 | |||
| 441 | return ret; | ||
| 442 | } | ||
| 443 | |||
| 444 | static int __devexit highlander_i2c_remove(struct platform_device *pdev) | ||
| 445 | { | ||
| 446 | struct highlander_i2c_dev *dev = platform_get_drvdata(pdev); | ||
| 447 | |||
| 448 | i2c_del_adapter(&dev->adapter); | ||
| 449 | |||
| 450 | if (dev->irq) | ||
| 451 | free_irq(dev->irq, dev); | ||
| 452 | |||
| 453 | iounmap(dev->base); | ||
| 454 | kfree(dev); | ||
| 455 | |||
| 456 | platform_set_drvdata(pdev, NULL); | ||
| 457 | |||
| 458 | return 0; | ||
| 459 | } | ||
| 460 | |||
| 461 | static struct platform_driver highlander_i2c_driver = { | ||
| 462 | .driver = { | ||
| 463 | .name = "i2c-highlander", | ||
| 464 | .owner = THIS_MODULE, | ||
| 465 | }, | ||
| 466 | |||
| 467 | .probe = highlander_i2c_probe, | ||
| 468 | .remove = __devexit_p(highlander_i2c_remove), | ||
| 469 | }; | ||
| 470 | |||
| 471 | static int __init highlander_i2c_init(void) | ||
| 472 | { | ||
| 473 | return platform_driver_register(&highlander_i2c_driver); | ||
| 474 | } | ||
| 475 | |||
| 476 | static void __exit highlander_i2c_exit(void) | ||
| 477 | { | ||
| 478 | platform_driver_unregister(&highlander_i2c_driver); | ||
| 479 | } | ||
| 480 | |||
| 481 | module_init(highlander_i2c_init); | ||
| 482 | module_exit(highlander_i2c_exit); | ||
| 483 | |||
| 484 | MODULE_AUTHOR("Paul Mundt"); | ||
| 485 | MODULE_DESCRIPTION("Renesas Highlander FPGA I2C/SMBus adapter"); | ||
| 486 | MODULE_LICENSE("GPL v2"); | ||
| 487 | |||
| 488 | module_param(iic_force_poll, bool, 0); | ||
| 489 | module_param(iic_force_normal, bool, 0); | ||
| 490 | module_param(iic_timeout, int, 0); | ||
| 491 | module_param(iic_read_delay, int, 0); | ||
| 492 | |||
| 493 | MODULE_PARM_DESC(iic_force_poll, "Force polling mode"); | ||
| 494 | MODULE_PARM_DESC(iic_force_normal, | ||
| 495 | "Force normal mode (100 kHz), default is fast mode (400 kHz)"); | ||
| 496 | MODULE_PARM_DESC(iic_timeout, "Set timeout value in msecs (default 1000 ms)"); | ||
| 497 | MODULE_PARM_DESC(iic_read_delay, | ||
| 498 | "Delay between data read cycles (default 0 ms)"); | ||
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c index c6faf9bdad18..b2b8380f6602 100644 --- a/drivers/i2c/busses/i2c-parport-light.c +++ b/drivers/i2c/busses/i2c-parport-light.c | |||
| @@ -123,11 +123,6 @@ static struct i2c_adapter parport_adapter = { | |||
| 123 | static int __devinit i2c_parport_probe(struct platform_device *pdev) | 123 | static int __devinit i2c_parport_probe(struct platform_device *pdev) |
| 124 | { | 124 | { |
| 125 | int err; | 125 | int err; |
| 126 | struct resource *res; | ||
| 127 | |||
| 128 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
| 129 | if (!request_region(res->start, res->end - res->start + 1, DRVNAME)) | ||
| 130 | return -EBUSY; | ||
| 131 | 126 | ||
| 132 | /* Reset hardware to a sane state (SCL and SDA high) */ | 127 | /* Reset hardware to a sane state (SCL and SDA high) */ |
| 133 | parport_setsda(NULL, 1); | 128 | parport_setsda(NULL, 1); |
| @@ -138,29 +133,19 @@ static int __devinit i2c_parport_probe(struct platform_device *pdev) | |||
| 138 | 133 | ||
| 139 | parport_adapter.dev.parent = &pdev->dev; | 134 | parport_adapter.dev.parent = &pdev->dev; |
| 140 | err = i2c_bit_add_bus(&parport_adapter); | 135 | err = i2c_bit_add_bus(&parport_adapter); |
| 141 | if (err) { | 136 | if (err) |
| 142 | dev_err(&pdev->dev, "Unable to register with I2C\n"); | 137 | dev_err(&pdev->dev, "Unable to register with I2C\n"); |
| 143 | goto exit_region; | ||
| 144 | } | ||
| 145 | return 0; | ||
| 146 | |||
| 147 | exit_region: | ||
| 148 | release_region(res->start, res->end - res->start + 1); | ||
| 149 | return err; | 138 | return err; |
| 150 | } | 139 | } |
| 151 | 140 | ||
| 152 | static int __devexit i2c_parport_remove(struct platform_device *pdev) | 141 | static int __devexit i2c_parport_remove(struct platform_device *pdev) |
| 153 | { | 142 | { |
| 154 | struct resource *res; | ||
| 155 | |||
| 156 | i2c_del_adapter(&parport_adapter); | 143 | i2c_del_adapter(&parport_adapter); |
| 157 | 144 | ||
| 158 | /* Un-init if needed (power off...) */ | 145 | /* Un-init if needed (power off...) */ |
| 159 | if (adapter_parm[type].init.val) | 146 | if (adapter_parm[type].init.val) |
| 160 | line_set(0, &adapter_parm[type].init); | 147 | line_set(0, &adapter_parm[type].init); |
| 161 | 148 | ||
| 162 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
| 163 | release_region(res->start, res->end - res->start + 1); | ||
| 164 | return 0; | 149 | return 0; |
| 165 | } | 150 | } |
| 166 | 151 | ||
| @@ -175,12 +160,6 @@ static struct platform_driver i2c_parport_driver = { | |||
| 175 | 160 | ||
| 176 | static int __init i2c_parport_device_add(u16 address) | 161 | static int __init i2c_parport_device_add(u16 address) |
| 177 | { | 162 | { |
| 178 | struct resource res = { | ||
| 179 | .start = address, | ||
| 180 | .end = address + 2, | ||
| 181 | .name = DRVNAME, | ||
| 182 | .flags = IORESOURCE_IO, | ||
| 183 | }; | ||
| 184 | int err; | 163 | int err; |
| 185 | 164 | ||
| 186 | pdev = platform_device_alloc(DRVNAME, -1); | 165 | pdev = platform_device_alloc(DRVNAME, -1); |
| @@ -190,13 +169,6 @@ static int __init i2c_parport_device_add(u16 address) | |||
| 190 | goto exit; | 169 | goto exit; |
| 191 | } | 170 | } |
| 192 | 171 | ||
| 193 | err = platform_device_add_resources(pdev, &res, 1); | ||
| 194 | if (err) { | ||
| 195 | printk(KERN_ERR DRVNAME ": Device resource addition failed " | ||
| 196 | "(%d)\n", err); | ||
| 197 | goto exit_device_put; | ||
| 198 | } | ||
| 199 | |||
| 200 | err = platform_device_add(pdev); | 172 | err = platform_device_add(pdev); |
| 201 | if (err) { | 173 | if (err) { |
| 202 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", | 174 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", |
| @@ -231,13 +203,16 @@ static int __init i2c_parport_init(void) | |||
| 231 | base = DEFAULT_BASE; | 203 | base = DEFAULT_BASE; |
| 232 | } | 204 | } |
| 233 | 205 | ||
| 206 | if (!request_region(base, 3, DRVNAME)) | ||
| 207 | return -EBUSY; | ||
| 208 | |||
| 234 | if (!adapter_parm[type].getscl.val) | 209 | if (!adapter_parm[type].getscl.val) |
| 235 | parport_algo_data.getscl = NULL; | 210 | parport_algo_data.getscl = NULL; |
| 236 | 211 | ||
| 237 | /* Sets global pdev as a side effect */ | 212 | /* Sets global pdev as a side effect */ |
| 238 | err = i2c_parport_device_add(base); | 213 | err = i2c_parport_device_add(base); |
| 239 | if (err) | 214 | if (err) |
| 240 | goto exit; | 215 | goto exit_release; |
| 241 | 216 | ||
| 242 | err = platform_driver_register(&i2c_parport_driver); | 217 | err = platform_driver_register(&i2c_parport_driver); |
| 243 | if (err) | 218 | if (err) |
| @@ -247,7 +222,8 @@ static int __init i2c_parport_init(void) | |||
| 247 | 222 | ||
| 248 | exit_device: | 223 | exit_device: |
| 249 | platform_device_unregister(pdev); | 224 | platform_device_unregister(pdev); |
| 250 | exit: | 225 | exit_release: |
| 226 | release_region(base, 3); | ||
| 251 | return err; | 227 | return err; |
| 252 | } | 228 | } |
| 253 | 229 | ||
| @@ -255,6 +231,7 @@ static void __exit i2c_parport_exit(void) | |||
| 255 | { | 231 | { |
| 256 | platform_driver_unregister(&i2c_parport_driver); | 232 | platform_driver_unregister(&i2c_parport_driver); |
| 257 | platform_device_unregister(pdev); | 233 | platform_device_unregister(pdev); |
| 234 | release_region(base, 3); | ||
| 258 | } | 235 | } |
| 259 | 236 | ||
| 260 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | 237 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c index a119784bae10..f80df9ae5054 100644 --- a/drivers/i2c/busses/i2c-pca-isa.c +++ b/drivers/i2c/busses/i2c-pca-isa.c | |||
| @@ -36,8 +36,8 @@ | |||
| 36 | #define DRIVER "i2c-pca-isa" | 36 | #define DRIVER "i2c-pca-isa" |
| 37 | #define IO_SIZE 4 | 37 | #define IO_SIZE 4 |
| 38 | 38 | ||
| 39 | static unsigned long base = 0x330; | 39 | static unsigned long base; |
| 40 | static int irq = 10; | 40 | static int irq = -1; |
| 41 | 41 | ||
| 42 | /* Data sheet recommends 59kHz for 100kHz operation due to variation | 42 | /* Data sheet recommends 59kHz for 100kHz operation due to variation |
| 43 | * in the actual clock rate */ | 43 | * in the actual clock rate */ |
| @@ -107,6 +107,19 @@ static struct i2c_adapter pca_isa_ops = { | |||
| 107 | .timeout = 100, | 107 | .timeout = 100, |
| 108 | }; | 108 | }; |
| 109 | 109 | ||
| 110 | static int __devinit pca_isa_match(struct device *dev, unsigned int id) | ||
| 111 | { | ||
| 112 | int match = base != 0; | ||
| 113 | |||
| 114 | if (match) { | ||
| 115 | if (irq <= -1) | ||
| 116 | dev_warn(dev, "Using polling mode (specify irq)\n"); | ||
| 117 | } else | ||
| 118 | dev_err(dev, "Please specify I/O base\n"); | ||
| 119 | |||
| 120 | return match; | ||
| 121 | } | ||
| 122 | |||
| 110 | static int __devinit pca_isa_probe(struct device *dev, unsigned int id) | 123 | static int __devinit pca_isa_probe(struct device *dev, unsigned int id) |
| 111 | { | 124 | { |
| 112 | init_waitqueue_head(&pca_wait); | 125 | init_waitqueue_head(&pca_wait); |
| @@ -153,7 +166,7 @@ static int __devexit pca_isa_remove(struct device *dev, unsigned int id) | |||
| 153 | { | 166 | { |
| 154 | i2c_del_adapter(&pca_isa_ops); | 167 | i2c_del_adapter(&pca_isa_ops); |
| 155 | 168 | ||
| 156 | if (irq > 0) { | 169 | if (irq > -1) { |
| 157 | disable_irq(irq); | 170 | disable_irq(irq); |
| 158 | free_irq(irq, &pca_isa_ops); | 171 | free_irq(irq, &pca_isa_ops); |
| 159 | } | 172 | } |
| @@ -163,6 +176,7 @@ static int __devexit pca_isa_remove(struct device *dev, unsigned int id) | |||
| 163 | } | 176 | } |
| 164 | 177 | ||
| 165 | static struct isa_driver pca_isa_driver = { | 178 | static struct isa_driver pca_isa_driver = { |
| 179 | .match = pca_isa_match, | ||
| 166 | .probe = pca_isa_probe, | 180 | .probe = pca_isa_probe, |
| 167 | .remove = __devexit_p(pca_isa_remove), | 181 | .remove = __devexit_p(pca_isa_remove), |
| 168 | .driver = { | 182 | .driver = { |
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c index 862eb352a2d9..73dc52e114eb 100644 --- a/drivers/i2c/busses/i2c-viapro.c +++ b/drivers/i2c/busses/i2c-viapro.c | |||
| @@ -36,6 +36,7 @@ | |||
| 36 | VT8237S 0x3372 yes | 36 | VT8237S 0x3372 yes |
| 37 | VT8251 0x3287 yes | 37 | VT8251 0x3287 yes |
| 38 | CX700 0x8324 yes | 38 | CX700 0x8324 yes |
| 39 | VX800/VX820 0x8353 yes | ||
| 39 | 40 | ||
| 40 | Note: we assume there can only be one device, with one SMBus interface. | 41 | Note: we assume there can only be one device, with one SMBus interface. |
| 41 | */ | 42 | */ |
| @@ -82,6 +83,7 @@ static unsigned short SMBHSTCFG = 0xD2; | |||
| 82 | #define VT596_BYTE 0x04 | 83 | #define VT596_BYTE 0x04 |
| 83 | #define VT596_BYTE_DATA 0x08 | 84 | #define VT596_BYTE_DATA 0x08 |
| 84 | #define VT596_WORD_DATA 0x0C | 85 | #define VT596_WORD_DATA 0x0C |
| 86 | #define VT596_PROC_CALL 0x10 | ||
| 85 | #define VT596_BLOCK_DATA 0x14 | 87 | #define VT596_BLOCK_DATA 0x14 |
| 86 | #define VT596_I2C_BLOCK_DATA 0x34 | 88 | #define VT596_I2C_BLOCK_DATA 0x34 |
| 87 | 89 | ||
| @@ -232,6 +234,12 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | |||
| 232 | } | 234 | } |
| 233 | size = VT596_WORD_DATA; | 235 | size = VT596_WORD_DATA; |
| 234 | break; | 236 | break; |
| 237 | case I2C_SMBUS_PROC_CALL: | ||
| 238 | outb_p(command, SMBHSTCMD); | ||
| 239 | outb_p(data->word & 0xff, SMBHSTDAT0); | ||
| 240 | outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); | ||
| 241 | size = VT596_PROC_CALL; | ||
| 242 | break; | ||
| 235 | case I2C_SMBUS_I2C_BLOCK_DATA: | 243 | case I2C_SMBUS_I2C_BLOCK_DATA: |
| 236 | if (!(vt596_features & FEATURE_I2CBLOCK)) | 244 | if (!(vt596_features & FEATURE_I2CBLOCK)) |
| 237 | goto exit_unsupported; | 245 | goto exit_unsupported; |
| @@ -262,6 +270,9 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | |||
| 262 | if (status) | 270 | if (status) |
| 263 | return status; | 271 | return status; |
| 264 | 272 | ||
| 273 | if (size == VT596_PROC_CALL) | ||
| 274 | read_write = I2C_SMBUS_READ; | ||
| 275 | |||
| 265 | if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) | 276 | if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) |
| 266 | return 0; | 277 | return 0; |
| 267 | 278 | ||
| @@ -271,6 +282,7 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, | |||
| 271 | data->byte = inb_p(SMBHSTDAT0); | 282 | data->byte = inb_p(SMBHSTDAT0); |
| 272 | break; | 283 | break; |
| 273 | case VT596_WORD_DATA: | 284 | case VT596_WORD_DATA: |
| 285 | case VT596_PROC_CALL: | ||
| 274 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); | 286 | data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); |
| 275 | break; | 287 | break; |
| 276 | case VT596_I2C_BLOCK_DATA: | 288 | case VT596_I2C_BLOCK_DATA: |
| @@ -295,7 +307,7 @@ static u32 vt596_func(struct i2c_adapter *adapter) | |||
| 295 | { | 307 | { |
| 296 | u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | | 308 | u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | |
| 297 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | | 309 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | |
| 298 | I2C_FUNC_SMBUS_BLOCK_DATA; | 310 | I2C_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_BLOCK_DATA; |
| 299 | 311 | ||
| 300 | if (vt596_features & FEATURE_I2CBLOCK) | 312 | if (vt596_features & FEATURE_I2CBLOCK) |
| 301 | func |= I2C_FUNC_SMBUS_I2C_BLOCK; | 313 | func |= I2C_FUNC_SMBUS_I2C_BLOCK; |
| @@ -396,6 +408,7 @@ found: | |||
| 396 | 408 | ||
| 397 | switch (pdev->device) { | 409 | switch (pdev->device) { |
| 398 | case PCI_DEVICE_ID_VIA_CX700: | 410 | case PCI_DEVICE_ID_VIA_CX700: |
| 411 | case PCI_DEVICE_ID_VIA_VX800: | ||
| 399 | case PCI_DEVICE_ID_VIA_8251: | 412 | case PCI_DEVICE_ID_VIA_8251: |
| 400 | case PCI_DEVICE_ID_VIA_8237: | 413 | case PCI_DEVICE_ID_VIA_8237: |
| 401 | case PCI_DEVICE_ID_VIA_8237A: | 414 | case PCI_DEVICE_ID_VIA_8237A: |
| @@ -459,6 +472,8 @@ static struct pci_device_id vt596_ids[] = { | |||
| 459 | .driver_data = SMBBA3 }, | 472 | .driver_data = SMBBA3 }, |
| 460 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700), | 473 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700), |
| 461 | .driver_data = SMBBA3 }, | 474 | .driver_data = SMBBA3 }, |
| 475 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX800), | ||
| 476 | .driver_data = SMBBA3 }, | ||
| 462 | { 0, } | 477 | { 0, } |
| 463 | }; | 478 | }; |
| 464 | 479 | ||
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c index 4655b794ebe3..28902ebd5539 100644 --- a/drivers/i2c/chips/isp1301_omap.c +++ b/drivers/i2c/chips/isp1301_omap.c | |||
| @@ -49,10 +49,9 @@ MODULE_LICENSE("GPL"); | |||
| 49 | 49 | ||
| 50 | struct isp1301 { | 50 | struct isp1301 { |
| 51 | struct otg_transceiver otg; | 51 | struct otg_transceiver otg; |
| 52 | struct i2c_client client; | 52 | struct i2c_client *client; |
| 53 | void (*i2c_release)(struct device *dev); | 53 | void (*i2c_release)(struct device *dev); |
| 54 | 54 | ||
| 55 | int irq; | ||
| 56 | int irq_type; | 55 | int irq_type; |
| 57 | 56 | ||
| 58 | u32 last_otg_ctrl; | 57 | u32 last_otg_ctrl; |
| @@ -138,14 +137,6 @@ static inline void notresponding(struct isp1301 *isp) | |||
| 138 | 137 | ||
| 139 | /*-------------------------------------------------------------------------*/ | 138 | /*-------------------------------------------------------------------------*/ |
| 140 | 139 | ||
| 141 | /* only two addresses possible */ | ||
| 142 | #define ISP_BASE 0x2c | ||
| 143 | static unsigned short normal_i2c[] = { | ||
| 144 | ISP_BASE, ISP_BASE + 1, | ||
| 145 | I2C_CLIENT_END }; | ||
| 146 | |||
| 147 | I2C_CLIENT_INSMOD; | ||
| 148 | |||
| 149 | static struct i2c_driver isp1301_driver; | 140 | static struct i2c_driver isp1301_driver; |
| 150 | 141 | ||
| 151 | /* smbus apis are used for portability */ | 142 | /* smbus apis are used for portability */ |
| @@ -153,25 +144,25 @@ static struct i2c_driver isp1301_driver; | |||
| 153 | static inline u8 | 144 | static inline u8 |
| 154 | isp1301_get_u8(struct isp1301 *isp, u8 reg) | 145 | isp1301_get_u8(struct isp1301 *isp, u8 reg) |
| 155 | { | 146 | { |
| 156 | return i2c_smbus_read_byte_data(&isp->client, reg + 0); | 147 | return i2c_smbus_read_byte_data(isp->client, reg + 0); |
| 157 | } | 148 | } |
| 158 | 149 | ||
| 159 | static inline int | 150 | static inline int |
| 160 | isp1301_get_u16(struct isp1301 *isp, u8 reg) | 151 | isp1301_get_u16(struct isp1301 *isp, u8 reg) |
| 161 | { | 152 | { |
| 162 | return i2c_smbus_read_word_data(&isp->client, reg); | 153 | return i2c_smbus_read_word_data(isp->client, reg); |
| 163 | } | 154 | } |
| 164 | 155 | ||
| 165 | static inline int | 156 | static inline int |
| 166 | isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits) | 157 | isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits) |
| 167 | { | 158 | { |
| 168 | return i2c_smbus_write_byte_data(&isp->client, reg + 0, bits); | 159 | return i2c_smbus_write_byte_data(isp->client, reg + 0, bits); |
| 169 | } | 160 | } |
| 170 | 161 | ||
| 171 | static inline int | 162 | static inline int |
| 172 | isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) | 163 | isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) |
| 173 | { | 164 | { |
| 174 | return i2c_smbus_write_byte_data(&isp->client, reg + 1, bits); | 165 | return i2c_smbus_write_byte_data(isp->client, reg + 1, bits); |
| 175 | } | 166 | } |
| 176 | 167 | ||
| 177 | /*-------------------------------------------------------------------------*/ | 168 | /*-------------------------------------------------------------------------*/ |
| @@ -349,10 +340,10 @@ isp1301_defer_work(struct isp1301 *isp, int work) | |||
| 349 | int status; | 340 | int status; |
| 350 | 341 | ||
| 351 | if (isp && !test_and_set_bit(work, &isp->todo)) { | 342 | if (isp && !test_and_set_bit(work, &isp->todo)) { |
| 352 | (void) get_device(&isp->client.dev); | 343 | (void) get_device(&isp->client->dev); |
| 353 | status = schedule_work(&isp->work); | 344 | status = schedule_work(&isp->work); |
| 354 | if (!status && !isp->working) | 345 | if (!status && !isp->working) |
| 355 | dev_vdbg(&isp->client.dev, | 346 | dev_vdbg(&isp->client->dev, |
| 356 | "work item %d may be lost\n", work); | 347 | "work item %d may be lost\n", work); |
| 357 | } | 348 | } |
| 358 | } | 349 | } |
| @@ -1135,7 +1126,7 @@ isp1301_work(struct work_struct *work) | |||
| 1135 | /* transfer state from otg engine to isp1301 */ | 1126 | /* transfer state from otg engine to isp1301 */ |
| 1136 | if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) { | 1127 | if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) { |
| 1137 | otg_update_isp(isp); | 1128 | otg_update_isp(isp); |
| 1138 | put_device(&isp->client.dev); | 1129 | put_device(&isp->client->dev); |
| 1139 | } | 1130 | } |
| 1140 | #endif | 1131 | #endif |
| 1141 | /* transfer state from isp1301 to otg engine */ | 1132 | /* transfer state from isp1301 to otg engine */ |
| @@ -1143,7 +1134,7 @@ isp1301_work(struct work_struct *work) | |||
| 1143 | u8 stat = isp1301_clear_latch(isp); | 1134 | u8 stat = isp1301_clear_latch(isp); |
| 1144 | 1135 | ||
| 1145 | isp_update_otg(isp, stat); | 1136 | isp_update_otg(isp, stat); |
| 1146 | put_device(&isp->client.dev); | 1137 | put_device(&isp->client->dev); |
| 1147 | } | 1138 | } |
| 1148 | 1139 | ||
| 1149 | if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) { | 1140 | if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) { |
| @@ -1178,7 +1169,7 @@ isp1301_work(struct work_struct *work) | |||
| 1178 | } | 1169 | } |
| 1179 | host_resume(isp); | 1170 | host_resume(isp); |
| 1180 | // mdelay(10); | 1171 | // mdelay(10); |
| 1181 | put_device(&isp->client.dev); | 1172 | put_device(&isp->client->dev); |
| 1182 | } | 1173 | } |
| 1183 | 1174 | ||
| 1184 | if (test_and_clear_bit(WORK_TIMER, &isp->todo)) { | 1175 | if (test_and_clear_bit(WORK_TIMER, &isp->todo)) { |
| @@ -1187,15 +1178,15 @@ isp1301_work(struct work_struct *work) | |||
| 1187 | if (!stop) | 1178 | if (!stop) |
| 1188 | mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); | 1179 | mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); |
| 1189 | #endif | 1180 | #endif |
| 1190 | put_device(&isp->client.dev); | 1181 | put_device(&isp->client->dev); |
| 1191 | } | 1182 | } |
| 1192 | 1183 | ||
| 1193 | if (isp->todo) | 1184 | if (isp->todo) |
| 1194 | dev_vdbg(&isp->client.dev, | 1185 | dev_vdbg(&isp->client->dev, |
| 1195 | "work done, todo = 0x%lx\n", | 1186 | "work done, todo = 0x%lx\n", |
| 1196 | isp->todo); | 1187 | isp->todo); |
| 1197 | if (stop) { | 1188 | if (stop) { |
| 1198 | dev_dbg(&isp->client.dev, "stop\n"); | 1189 | dev_dbg(&isp->client->dev, "stop\n"); |
| 1199 | break; | 1190 | break; |
| 1200 | } | 1191 | } |
| 1201 | } while (isp->todo); | 1192 | } while (isp->todo); |
| @@ -1219,7 +1210,7 @@ static void isp1301_release(struct device *dev) | |||
| 1219 | { | 1210 | { |
| 1220 | struct isp1301 *isp; | 1211 | struct isp1301 *isp; |
| 1221 | 1212 | ||
| 1222 | isp = container_of(dev, struct isp1301, client.dev); | 1213 | isp = dev_get_drvdata(dev); |
| 1223 | 1214 | ||
| 1224 | /* ugly -- i2c hijacks our memory hook to wait_for_completion() */ | 1215 | /* ugly -- i2c hijacks our memory hook to wait_for_completion() */ |
| 1225 | if (isp->i2c_release) | 1216 | if (isp->i2c_release) |
| @@ -1229,15 +1220,15 @@ static void isp1301_release(struct device *dev) | |||
| 1229 | 1220 | ||
| 1230 | static struct isp1301 *the_transceiver; | 1221 | static struct isp1301 *the_transceiver; |
| 1231 | 1222 | ||
| 1232 | static int isp1301_detach_client(struct i2c_client *i2c) | 1223 | static int __exit isp1301_remove(struct i2c_client *i2c) |
| 1233 | { | 1224 | { |
| 1234 | struct isp1301 *isp; | 1225 | struct isp1301 *isp; |
| 1235 | 1226 | ||
| 1236 | isp = container_of(i2c, struct isp1301, client); | 1227 | isp = i2c_get_clientdata(i2c); |
| 1237 | 1228 | ||
| 1238 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); | 1229 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); |
| 1239 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); | 1230 | isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); |
| 1240 | free_irq(isp->irq, isp); | 1231 | free_irq(i2c->irq, isp); |
| 1241 | #ifdef CONFIG_USB_OTG | 1232 | #ifdef CONFIG_USB_OTG |
| 1242 | otg_unbind(isp); | 1233 | otg_unbind(isp); |
| 1243 | #endif | 1234 | #endif |
| @@ -1252,7 +1243,7 @@ static int isp1301_detach_client(struct i2c_client *i2c) | |||
| 1252 | put_device(&i2c->dev); | 1243 | put_device(&i2c->dev); |
| 1253 | the_transceiver = 0; | 1244 | the_transceiver = 0; |
| 1254 | 1245 | ||
| 1255 | return i2c_detach_client(i2c); | 1246 | return 0; |
| 1256 | } | 1247 | } |
| 1257 | 1248 | ||
| 1258 | /*-------------------------------------------------------------------------*/ | 1249 | /*-------------------------------------------------------------------------*/ |
| @@ -1285,7 +1276,7 @@ static int isp1301_otg_enable(struct isp1301 *isp) | |||
| 1285 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, | 1276 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, |
| 1286 | INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); | 1277 | INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); |
| 1287 | 1278 | ||
| 1288 | dev_info(&isp->client.dev, "ready for dual-role USB ...\n"); | 1279 | dev_info(&isp->client->dev, "ready for dual-role USB ...\n"); |
| 1289 | 1280 | ||
| 1290 | return 0; | 1281 | return 0; |
| 1291 | } | 1282 | } |
| @@ -1310,7 +1301,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host) | |||
| 1310 | 1301 | ||
| 1311 | #ifdef CONFIG_USB_OTG | 1302 | #ifdef CONFIG_USB_OTG |
| 1312 | isp->otg.host = host; | 1303 | isp->otg.host = host; |
| 1313 | dev_dbg(&isp->client.dev, "registered host\n"); | 1304 | dev_dbg(&isp->client->dev, "registered host\n"); |
| 1314 | host_suspend(isp); | 1305 | host_suspend(isp); |
| 1315 | if (isp->otg.gadget) | 1306 | if (isp->otg.gadget) |
| 1316 | return isp1301_otg_enable(isp); | 1307 | return isp1301_otg_enable(isp); |
| @@ -1325,7 +1316,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host) | |||
| 1325 | if (machine_is_omap_h2()) | 1316 | if (machine_is_omap_h2()) |
| 1326 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); | 1317 | isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); |
| 1327 | 1318 | ||
| 1328 | dev_info(&isp->client.dev, "A-Host sessions ok\n"); | 1319 | dev_info(&isp->client->dev, "A-Host sessions ok\n"); |
| 1329 | isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, | 1320 | isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, |
| 1330 | INTR_ID_GND); | 1321 | INTR_ID_GND); |
| 1331 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, | 1322 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, |
| @@ -1343,7 +1334,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host) | |||
| 1343 | return 0; | 1334 | return 0; |
| 1344 | 1335 | ||
| 1345 | #else | 1336 | #else |
| 1346 | dev_dbg(&isp->client.dev, "host sessions not allowed\n"); | 1337 | dev_dbg(&isp->client->dev, "host sessions not allowed\n"); |
| 1347 | return -EINVAL; | 1338 | return -EINVAL; |
| 1348 | #endif | 1339 | #endif |
| 1349 | 1340 | ||
| @@ -1370,7 +1361,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) | |||
| 1370 | 1361 | ||
| 1371 | #ifdef CONFIG_USB_OTG | 1362 | #ifdef CONFIG_USB_OTG |
| 1372 | isp->otg.gadget = gadget; | 1363 | isp->otg.gadget = gadget; |
| 1373 | dev_dbg(&isp->client.dev, "registered gadget\n"); | 1364 | dev_dbg(&isp->client->dev, "registered gadget\n"); |
| 1374 | /* gadget driver may be suspended until vbus_connect () */ | 1365 | /* gadget driver may be suspended until vbus_connect () */ |
| 1375 | if (isp->otg.host) | 1366 | if (isp->otg.host) |
| 1376 | return isp1301_otg_enable(isp); | 1367 | return isp1301_otg_enable(isp); |
| @@ -1395,7 +1386,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) | |||
| 1395 | INTR_SESS_VLD); | 1386 | INTR_SESS_VLD); |
| 1396 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, | 1387 | isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, |
| 1397 | INTR_VBUS_VLD); | 1388 | INTR_VBUS_VLD); |
| 1398 | dev_info(&isp->client.dev, "B-Peripheral sessions ok\n"); | 1389 | dev_info(&isp->client->dev, "B-Peripheral sessions ok\n"); |
| 1399 | dump_regs(isp, __func__); | 1390 | dump_regs(isp, __func__); |
| 1400 | 1391 | ||
| 1401 | /* If this has a Mini-AB connector, this mode is highly | 1392 | /* If this has a Mini-AB connector, this mode is highly |
| @@ -1408,7 +1399,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) | |||
| 1408 | return 0; | 1399 | return 0; |
| 1409 | 1400 | ||
| 1410 | #else | 1401 | #else |
| 1411 | dev_dbg(&isp->client.dev, "peripheral sessions not allowed\n"); | 1402 | dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n"); |
| 1412 | return -EINVAL; | 1403 | return -EINVAL; |
| 1413 | #endif | 1404 | #endif |
| 1414 | } | 1405 | } |
| @@ -1508,12 +1499,10 @@ isp1301_start_hnp(struct otg_transceiver *dev) | |||
| 1508 | 1499 | ||
| 1509 | /*-------------------------------------------------------------------------*/ | 1500 | /*-------------------------------------------------------------------------*/ |
| 1510 | 1501 | ||
| 1511 | /* no error returns, they'd just make bus scanning stop */ | 1502 | static int __init isp1301_probe(struct i2c_client *i2c) |
| 1512 | static int isp1301_probe(struct i2c_adapter *bus, int address, int kind) | ||
| 1513 | { | 1503 | { |
| 1514 | int status; | 1504 | int status; |
| 1515 | struct isp1301 *isp; | 1505 | struct isp1301 *isp; |
| 1516 | struct i2c_client *i2c; | ||
| 1517 | 1506 | ||
| 1518 | if (the_transceiver) | 1507 | if (the_transceiver) |
| 1519 | return 0; | 1508 | return 0; |
| @@ -1527,37 +1516,19 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind) | |||
| 1527 | isp->timer.function = isp1301_timer; | 1516 | isp->timer.function = isp1301_timer; |
| 1528 | isp->timer.data = (unsigned long) isp; | 1517 | isp->timer.data = (unsigned long) isp; |
| 1529 | 1518 | ||
| 1530 | isp->irq = -1; | 1519 | i2c_set_clientdata(i2c, isp); |
| 1531 | isp->client.addr = address; | 1520 | isp->client = i2c; |
| 1532 | i2c_set_clientdata(&isp->client, isp); | ||
| 1533 | isp->client.adapter = bus; | ||
| 1534 | isp->client.driver = &isp1301_driver; | ||
| 1535 | strlcpy(isp->client.name, DRIVER_NAME, I2C_NAME_SIZE); | ||
| 1536 | i2c = &isp->client; | ||
| 1537 | |||
| 1538 | /* if this is a true probe, verify the chip ... */ | ||
| 1539 | if (kind < 0) { | ||
| 1540 | status = isp1301_get_u16(isp, ISP1301_VENDOR_ID); | ||
| 1541 | if (status != I2C_VENDOR_ID_PHILIPS) { | ||
| 1542 | dev_dbg(&bus->dev, "addr %d not philips id: %d\n", | ||
| 1543 | address, status); | ||
| 1544 | goto fail1; | ||
| 1545 | } | ||
| 1546 | status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID); | ||
| 1547 | if (status != I2C_PRODUCT_ID_PHILIPS_1301) { | ||
| 1548 | dev_dbg(&bus->dev, "%d not isp1301, %d\n", | ||
| 1549 | address, status); | ||
| 1550 | goto fail1; | ||
| 1551 | } | ||
| 1552 | } | ||
| 1553 | 1521 | ||
| 1554 | status = i2c_attach_client(i2c); | 1522 | /* verify the chip (shouldn't be necesary) */ |
| 1555 | if (status < 0) { | 1523 | status = isp1301_get_u16(isp, ISP1301_VENDOR_ID); |
| 1556 | dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n", | 1524 | if (status != I2C_VENDOR_ID_PHILIPS) { |
| 1557 | DRIVER_NAME, address, status); | 1525 | dev_dbg(&i2c->dev, "not philips id: %d\n", status); |
| 1558 | fail1: | 1526 | goto fail; |
| 1559 | kfree(isp); | 1527 | } |
| 1560 | return 0; | 1528 | status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID); |
| 1529 | if (status != I2C_PRODUCT_ID_PHILIPS_1301) { | ||
| 1530 | dev_dbg(&i2c->dev, "not isp1301, %d\n", status); | ||
| 1531 | goto fail; | ||
| 1561 | } | 1532 | } |
| 1562 | isp->i2c_release = i2c->dev.release; | 1533 | isp->i2c_release = i2c->dev.release; |
| 1563 | i2c->dev.release = isp1301_release; | 1534 | i2c->dev.release = isp1301_release; |
| @@ -1586,7 +1557,7 @@ fail1: | |||
| 1586 | status = otg_bind(isp); | 1557 | status = otg_bind(isp); |
| 1587 | if (status < 0) { | 1558 | if (status < 0) { |
| 1588 | dev_dbg(&i2c->dev, "can't bind OTG\n"); | 1559 | dev_dbg(&i2c->dev, "can't bind OTG\n"); |
| 1589 | goto fail2; | 1560 | goto fail; |
| 1590 | } | 1561 | } |
| 1591 | #endif | 1562 | #endif |
| 1592 | 1563 | ||
| @@ -1599,26 +1570,21 @@ fail1: | |||
| 1599 | 1570 | ||
| 1600 | /* IRQ wired at M14 */ | 1571 | /* IRQ wired at M14 */ |
| 1601 | omap_cfg_reg(M14_1510_GPIO2); | 1572 | omap_cfg_reg(M14_1510_GPIO2); |
| 1602 | isp->irq = OMAP_GPIO_IRQ(2); | ||
| 1603 | if (gpio_request(2, "isp1301") == 0) | 1573 | if (gpio_request(2, "isp1301") == 0) |
| 1604 | gpio_direction_input(2); | 1574 | gpio_direction_input(2); |
| 1605 | isp->irq_type = IRQF_TRIGGER_FALLING; | 1575 | isp->irq_type = IRQF_TRIGGER_FALLING; |
| 1606 | } | 1576 | } |
| 1607 | 1577 | ||
| 1608 | isp->irq_type |= IRQF_SAMPLE_RANDOM; | 1578 | isp->irq_type |= IRQF_SAMPLE_RANDOM; |
| 1609 | status = request_irq(isp->irq, isp1301_irq, | 1579 | status = request_irq(i2c->irq, isp1301_irq, |
| 1610 | isp->irq_type, DRIVER_NAME, isp); | 1580 | isp->irq_type, DRIVER_NAME, isp); |
| 1611 | if (status < 0) { | 1581 | if (status < 0) { |
| 1612 | dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", | 1582 | dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", |
| 1613 | isp->irq, status); | 1583 | i2c->irq, status); |
| 1614 | #ifdef CONFIG_USB_OTG | 1584 | goto fail; |
| 1615 | fail2: | ||
| 1616 | #endif | ||
| 1617 | i2c_detach_client(i2c); | ||
| 1618 | goto fail1; | ||
| 1619 | } | 1585 | } |
| 1620 | 1586 | ||
| 1621 | isp->otg.dev = &isp->client.dev; | 1587 | isp->otg.dev = &i2c->dev; |
| 1622 | isp->otg.label = DRIVER_NAME; | 1588 | isp->otg.label = DRIVER_NAME; |
| 1623 | 1589 | ||
| 1624 | isp->otg.set_host = isp1301_set_host, | 1590 | isp->otg.set_host = isp1301_set_host, |
| @@ -1649,22 +1615,25 @@ fail2: | |||
| 1649 | status); | 1615 | status); |
| 1650 | 1616 | ||
| 1651 | return 0; | 1617 | return 0; |
| 1652 | } | ||
| 1653 | 1618 | ||
| 1654 | static int isp1301_scan_bus(struct i2c_adapter *bus) | 1619 | fail: |
| 1655 | { | 1620 | kfree(isp); |
| 1656 | if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA | 1621 | return -ENODEV; |
| 1657 | | I2C_FUNC_SMBUS_READ_WORD_DATA)) | ||
| 1658 | return -EINVAL; | ||
| 1659 | return i2c_probe(bus, &addr_data, isp1301_probe); | ||
| 1660 | } | 1622 | } |
| 1661 | 1623 | ||
| 1624 | static const struct i2c_device_id isp1301_id[] = { | ||
| 1625 | { "isp1301_omap", 0 }, | ||
| 1626 | { } | ||
| 1627 | }; | ||
| 1628 | MODULE_DEVICE_TABLE(i2c, isp1301_id); | ||
| 1629 | |||
| 1662 | static struct i2c_driver isp1301_driver = { | 1630 | static struct i2c_driver isp1301_driver = { |
| 1663 | .driver = { | 1631 | .driver = { |
| 1664 | .name = "isp1301_omap", | 1632 | .name = "isp1301_omap", |
| 1665 | }, | 1633 | }, |
| 1666 | .attach_adapter = isp1301_scan_bus, | 1634 | .probe = isp1301_probe, |
| 1667 | .detach_client = isp1301_detach_client, | 1635 | .remove = __exit_p(isp1301_remove), |
| 1636 | .id_table = isp1301_id, | ||
| 1668 | }; | 1637 | }; |
| 1669 | 1638 | ||
| 1670 | /*-------------------------------------------------------------------------*/ | 1639 | /*-------------------------------------------------------------------------*/ |
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c index cf02e8fceb42..acf8b9d5f575 100644 --- a/drivers/i2c/chips/tps65010.c +++ b/drivers/i2c/chips/tps65010.c | |||
| @@ -456,14 +456,17 @@ static irqreturn_t tps65010_irq(int irq, void *_tps) | |||
| 456 | 456 | ||
| 457 | /* offsets 0..3 == GPIO1..GPIO4 | 457 | /* offsets 0..3 == GPIO1..GPIO4 |
| 458 | * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes) | 458 | * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes) |
| 459 | * offset 6 == vibrator motor driver | ||
| 459 | */ | 460 | */ |
| 460 | static void | 461 | static void |
| 461 | tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 462 | tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 462 | { | 463 | { |
| 463 | if (offset < 4) | 464 | if (offset < 4) |
| 464 | tps65010_set_gpio_out_value(offset + 1, value); | 465 | tps65010_set_gpio_out_value(offset + 1, value); |
| 465 | else | 466 | else if (offset < 6) |
| 466 | tps65010_set_led(offset - 3, value ? ON : OFF); | 467 | tps65010_set_led(offset - 3, value ? ON : OFF); |
| 468 | else | ||
| 469 | tps65010_set_vib(value); | ||
| 467 | } | 470 | } |
| 468 | 471 | ||
| 469 | static int | 472 | static int |
| @@ -477,8 +480,10 @@ tps65010_output(struct gpio_chip *chip, unsigned offset, int value) | |||
| 477 | if (!(tps->outmask & (1 << offset))) | 480 | if (!(tps->outmask & (1 << offset))) |
| 478 | return -EINVAL; | 481 | return -EINVAL; |
| 479 | tps65010_set_gpio_out_value(offset + 1, value); | 482 | tps65010_set_gpio_out_value(offset + 1, value); |
| 480 | } else | 483 | } else if (offset < 6) |
| 481 | tps65010_set_led(offset - 3, value ? ON : OFF); | 484 | tps65010_set_led(offset - 3, value ? ON : OFF); |
| 485 | else | ||
| 486 | tps65010_set_vib(value); | ||
| 482 | 487 | ||
| 483 | return 0; | 488 | return 0; |
| 484 | } | 489 | } |
| @@ -646,7 +651,7 @@ static int tps65010_probe(struct i2c_client *client, | |||
| 646 | tps->chip.get = tps65010_gpio_get; | 651 | tps->chip.get = tps65010_gpio_get; |
| 647 | 652 | ||
| 648 | tps->chip.base = board->base; | 653 | tps->chip.base = board->base; |
| 649 | tps->chip.ngpio = 6; | 654 | tps->chip.ngpio = 7; |
| 650 | tps->chip.can_sleep = 1; | 655 | tps->chip.can_sleep = 1; |
| 651 | 656 | ||
| 652 | status = gpiochip_add(&tps->chip); | 657 | status = gpiochip_add(&tps->chip); |
| @@ -675,6 +680,7 @@ static const struct i2c_device_id tps65010_id[] = { | |||
| 675 | { "tps65011", TPS65011 }, | 680 | { "tps65011", TPS65011 }, |
| 676 | { "tps65012", TPS65012 }, | 681 | { "tps65012", TPS65012 }, |
| 677 | { "tps65013", TPS65013 }, | 682 | { "tps65013", TPS65013 }, |
| 683 | { "tps65014", TPS65011 }, /* tps65011 charging at 6.5V max */ | ||
| 678 | { } | 684 | { } |
| 679 | }; | 685 | }; |
| 680 | MODULE_DEVICE_TABLE(i2c, tps65010_id); | 686 | MODULE_DEVICE_TABLE(i2c, tps65010_id); |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index b346a687ab59..42e852d79ffa 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
| @@ -437,6 +437,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap) | |||
| 437 | { | 437 | { |
| 438 | int res = 0, dummy; | 438 | int res = 0, dummy; |
| 439 | 439 | ||
| 440 | /* Can't register until after driver model init */ | ||
| 441 | if (unlikely(WARN_ON(!i2c_bus_type.p))) | ||
| 442 | return -EAGAIN; | ||
| 443 | |||
| 440 | mutex_init(&adap->bus_lock); | 444 | mutex_init(&adap->bus_lock); |
| 441 | mutex_init(&adap->clist_lock); | 445 | mutex_init(&adap->clist_lock); |
| 442 | INIT_LIST_HEAD(&adap->clients); | 446 | INIT_LIST_HEAD(&adap->clients); |
| @@ -696,6 +700,10 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver) | |||
| 696 | { | 700 | { |
| 697 | int res; | 701 | int res; |
| 698 | 702 | ||
| 703 | /* Can't register until after driver model init */ | ||
| 704 | if (unlikely(WARN_ON(!i2c_bus_type.p))) | ||
| 705 | return -EAGAIN; | ||
| 706 | |||
| 699 | /* new style driver methods can't mix with legacy ones */ | 707 | /* new style driver methods can't mix with legacy ones */ |
| 700 | if (is_newstyle_driver(driver)) { | 708 | if (is_newstyle_driver(driver)) { |
| 701 | if (driver->attach_adapter || driver->detach_adapter | 709 | if (driver->attach_adapter || driver->detach_adapter |
| @@ -978,7 +986,10 @@ static void __exit i2c_exit(void) | |||
| 978 | bus_unregister(&i2c_bus_type); | 986 | bus_unregister(&i2c_bus_type); |
| 979 | } | 987 | } |
| 980 | 988 | ||
| 981 | subsys_initcall(i2c_init); | 989 | /* We must initialize early, because some subsystems register i2c drivers |
| 990 | * in subsys_initcall() code, but are linked (and initialized) before i2c. | ||
| 991 | */ | ||
| 992 | postcore_initcall(i2c_init); | ||
| 982 | module_exit(i2c_exit); | 993 | module_exit(i2c_exit); |
| 983 | 994 | ||
| 984 | /* ---------------------------------------------------- | 995 | /* ---------------------------------------------------- |
| @@ -1677,6 +1688,28 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) | |||
| 1677 | EXPORT_SYMBOL(i2c_smbus_write_word_data); | 1688 | EXPORT_SYMBOL(i2c_smbus_write_word_data); |
| 1678 | 1689 | ||
| 1679 | /** | 1690 | /** |
| 1691 | * i2c_smbus_process_call - SMBus "process call" protocol | ||
| 1692 | * @client: Handle to slave device | ||
| 1693 | * @command: Byte interpreted by slave | ||
| 1694 | * @value: 16-bit "word" being written | ||
| 1695 | * | ||
| 1696 | * This executes the SMBus "process call" protocol, returning negative errno | ||
| 1697 | * else a 16-bit unsigned "word" received from the device. | ||
| 1698 | */ | ||
| 1699 | s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value) | ||
| 1700 | { | ||
| 1701 | union i2c_smbus_data data; | ||
| 1702 | int status; | ||
| 1703 | data.word = value; | ||
| 1704 | |||
| 1705 | status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, | ||
| 1706 | I2C_SMBUS_WRITE, command, | ||
| 1707 | I2C_SMBUS_PROC_CALL, &data); | ||
| 1708 | return (status < 0) ? status : data.word; | ||
| 1709 | } | ||
| 1710 | EXPORT_SYMBOL(i2c_smbus_process_call); | ||
| 1711 | |||
| 1712 | /** | ||
| 1680 | * i2c_smbus_read_block_data - SMBus "block read" protocol | 1713 | * i2c_smbus_read_block_data - SMBus "block read" protocol |
| 1681 | * @client: Handle to slave device | 1714 | * @client: Handle to slave device |
| 1682 | * @command: Byte interpreted by slave | 1715 | * @command: Byte interpreted by slave |
