David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _LINUX_BIF_CONSUMER_H_ |
| 14 | #define _LINUX_BIF_CONSUMER_H_ |
| 15 | |
| 16 | #include <linux/bitops.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/notifier.h> |
| 19 | |
| 20 | #define BIF_DEVICE_ID_BYTE_LENGTH 8 |
| 21 | #define BIF_UNIQUE_ID_BYTE_LENGTH 10 |
| 22 | #define BIF_UNIQUE_ID_BIT_LENGTH 80 |
| 23 | |
| 24 | #define BIF_PRIMARY_SLAVE_DEV_ADR 0x01 |
| 25 | |
| 26 | /** |
| 27 | * enum bif_transaction - BIF master bus transaction types |
| 28 | * %BIF_TRANS_WD: Write data |
| 29 | * %BIF_TRANS_ERA: Extended register address |
| 30 | * %BIF_TRANS_WRA: Write register address |
| 31 | * %BIF_TRANS_RRA: Read register address |
| 32 | * %BIF_TRANS_BC: Bus command |
| 33 | * %BIF_TRANS_EDA: Extended device address |
| 34 | * %BIF_TRANS_SDA: Slave device address |
| 35 | * |
| 36 | * These values correspond to BIF word bits: BCF, bit 9, bit 8. |
| 37 | * BCF_n bit is inserted automatically. |
| 38 | */ |
| 39 | enum bif_transaction { |
| 40 | BIF_TRANS_WD = 0x00, |
| 41 | BIF_TRANS_ERA = 0x01, |
| 42 | BIF_TRANS_WRA = 0x02, |
| 43 | BIF_TRANS_RRA = 0x03, |
| 44 | BIF_TRANS_BC = 0x04, |
| 45 | BIF_TRANS_EDA = 0x05, |
| 46 | BIF_TRANS_SDA = 0x06, |
| 47 | }; |
| 48 | |
| 49 | /* BIF slave response components */ |
| 50 | #define BIF_SLAVE_RD_ACK 0x200 |
| 51 | #define BIF_SLAVE_RD_EOT 0x100 |
| 52 | #define BIF_SLAVE_RD_DATA 0x0FF |
| 53 | #define BIF_SLAVE_RD_ERR 0x0FF |
| 54 | #define BIF_SLAVE_TACK_ACK 0x200 |
| 55 | #define BIF_SLAVE_TACK_WCNT 0x0FF |
| 56 | #define BIF_SLAVE_TACK_ERR 0x0FF |
| 57 | |
| 58 | /** |
| 59 | * enum bif_bus_command - MIPI defined bus commands to use in BC transaction |
| 60 | * %BIF_CMD_BRES: Bus reset of all slaves |
| 61 | * %BIF_CMD_PDWN: Put all slaves into power down mode |
| 62 | * %BIF_CMD_STBY: Put all slaves into standby mode |
| 63 | * %BIF_CMD_EINT: Enable interrupts for all slaves |
| 64 | * %BIF_CMD_ISTS: Poll interrupt status for all slaves. Expects BQ |
| 65 | * response if any slave has a pending interrupt. |
| 66 | * %BIF_CMD_RBL: Specify the burst read length for the next read |
| 67 | * transaction. Bits 3 to 0 should also be ORed on in |
| 68 | * order to specify the number of bytes to read. |
| 69 | * %BIF_CMD_RBE: Specify the extended burst read length for the next read |
| 70 | * transaction. Bits 3 to 0 should also be ORed on in |
| 71 | * order to specify the number of bytes to read. The burst |
| 72 | * read length for RBEy and RBLx = 16 * y + x. |
| 73 | * %BIF_CMD_DASM: Device activation stick mode. This keeps a slave |
| 74 | * selected if it would otherwise become unselected by the |
| 75 | * next transaction. |
| 76 | * %BIF_CMD_DISS: UID search start |
| 77 | * %BIF_CMD_DILC: UID length check. Expects BQ response if all 80 UID |
| 78 | * bits for a given slave have been entered. |
| 79 | * %BIF_CMD_DIE0: UID search enter 0 |
| 80 | * %BIF_CMD_DIE1: UID search enter 1 |
| 81 | * %BIF_CMD_DIP0: UID search probe 0 |
| 82 | * %BIF_CMD_DIP1: UID search probe 1 |
| 83 | * %BIF_CMD_DRES: Device reset of selected slaves |
| 84 | * %BIF_CMD_TQ: Transaction query; expects TACK response |
| 85 | * %BIF_CMD_AIO: Address increment off for the next transaction |
| 86 | * |
| 87 | * These values correspond to BIF word bits 7 to 0. |
| 88 | */ |
| 89 | enum bif_bus_command { |
| 90 | BIF_CMD_BRES = 0x00, |
| 91 | BIF_CMD_PDWN = 0x02, |
| 92 | BIF_CMD_STBY = 0x03, |
| 93 | BIF_CMD_EINT = 0x10, |
| 94 | BIF_CMD_ISTS = 0x11, |
| 95 | BIF_CMD_RBL = 0x20, |
| 96 | BIF_CMD_RBE = 0x30, |
| 97 | BIF_CMD_DASM = 0x40, |
| 98 | BIF_CMD_DISS = 0x80, |
| 99 | BIF_CMD_DILC = 0x81, |
| 100 | BIF_CMD_DIE0 = 0x84, |
| 101 | BIF_CMD_DIE1 = 0x85, |
| 102 | BIF_CMD_DIP0 = 0x86, |
| 103 | BIF_CMD_DIP1 = 0x87, |
| 104 | BIF_CMD_DRES = 0xC0, |
| 105 | BIF_CMD_TQ = 0xC2, |
| 106 | BIF_CMD_AIO = 0xC4, |
| 107 | }; |
| 108 | |
| 109 | /** |
| 110 | * struct bif_ddb_l1_data - MIPI defined L1 DDB data structure |
| 111 | * @revision: DDB version; should be 0x10 for DDB v1.0 |
| 112 | * @level: DDB level support; should be 0x03 for DDB L1 and L2 |
| 113 | * @device_class: MIPI device class; should be 0x0800 |
| 114 | * @manufacturer_id: Manufacturer ID number allocated by MIPI |
| 115 | * @product_id: Manufacturer specified product ID number |
| 116 | * @length: Size of L2 function directory in bytes |
| 117 | */ |
| 118 | struct bif_ddb_l1_data { |
| 119 | u8 revision; |
| 120 | u8 level; |
| 121 | u16 device_class; |
| 122 | u16 manufacturer_id; |
| 123 | u16 product_id; |
| 124 | u16 length; |
| 125 | }; |
| 126 | |
| 127 | /** |
| 128 | * struct bif_ddb_l2_data - MIPI defined L2 DDB function data structure |
| 129 | * @function_type: Defines the type of the function. The type may be |
| 130 | * either MIPI or manufacturer defined. |
| 131 | * @function_version: Defines the version of the function. The version may |
| 132 | * be either MIPI or manufacturer defined. |
| 133 | * @function_pointer: Address in BIF slave memory where the register map for |
| 134 | * the function begins. |
| 135 | */ |
| 136 | struct bif_ddb_l2_data { |
| 137 | u8 function_type; |
| 138 | u8 function_version; |
| 139 | u16 function_pointer; |
| 140 | }; |
| 141 | |
| 142 | /** |
| 143 | * enum bif_mipi_function_type - MIPI defined DDB L2 function types |
| 144 | * %BIF_FUNC_PROTOCOL: Protocol function which provides access to core |
| 145 | * BIF communication features. |
| 146 | * %BIF_FUNC_SLAVE_CONTROL: Slave control function which provides control |
| 147 | * for BIF slave interrupts and tasks. |
| 148 | * %BIF_FUNC_TEMPERATURE: Temperature sensor function which provides a |
| 149 | * means to accurately read the battery temperature |
| 150 | * in a single-shot or periodic fashion. |
| 151 | * %BIF_FUNC_NVM: Non-volatile memory function which provides a |
| 152 | * means to store data onto a BIF slave that is |
| 153 | * non-volatile. Secondary slave objects are also |
| 154 | * found through the NVM function. |
| 155 | * %BIF_FUNC_AUTHENTICATION: Authentication function which provides a means |
| 156 | * to authenticate batteries. This function does |
| 157 | * not have a MIPI defined implimentation. Instead |
| 158 | * all aspects of the authentication function are |
| 159 | * left to the discretion of the manufacturer. |
| 160 | */ |
| 161 | enum bif_mipi_function_type { |
| 162 | BIF_FUNC_PROTOCOL = 0x01, |
| 163 | BIF_FUNC_SLAVE_CONTROL = 0x02, |
| 164 | BIF_FUNC_TEMPERATURE = 0x03, |
| 165 | BIF_FUNC_NVM = 0x04, |
| 166 | BIF_FUNC_AUTHENTICATION = 0x05, |
| 167 | }; |
| 168 | |
| 169 | #define BIF_DDB_L1_BASE_ADDR 0x0000 |
| 170 | #define BIF_DDB_L2_BASE_ADDR 0x000A |
| 171 | |
| 172 | /** |
| 173 | * enum bif_slave_error_code - MIPI defined BIF slave error codes |
| 174 | * %BIF_ERR_NONE: No error occurred |
| 175 | * %BIF_ERR_GENERAL: An unenumerated error occurred |
| 176 | * %BIF_ERR_PARITY: A Hamming-15 parity check failed for a word |
| 177 | * sent on the bus |
| 178 | * %BIF_ERR_INVERSION: More than 8 bits in a word were 1 |
| 179 | * %BIF_ERR_BAD_LENGTH: Word had more or less than 17 bits |
| 180 | * %BIF_ERR_TIMING: Bit timing was violated in a word |
| 181 | * %BIF_ERR_UNKNOWN_CMD: Bus command was unknown to the slave |
| 182 | * %BIF_ERR_CMD_SEQ: Commands with ordering dependency were not |
| 183 | * sent in the right order |
| 184 | * %BIF_ERR_BUS_COLLISION: BCL was already low at the beginning of a new |
| 185 | * transaction |
| 186 | * %BIF_ERR_SLAVE_BUSY: Slave is busy and cannot respond |
| 187 | * %BIF_ERR_FATAL: Slave is in an unrecoverable error state and |
| 188 | * must be reset |
| 189 | * |
| 190 | * These values are present in the ERR portion of an RD or TACK slave response |
| 191 | * word. These values can also be found in the ERR_CODE register of the |
| 192 | * protocol function. |
| 193 | */ |
| 194 | enum bif_slave_error_code { |
| 195 | BIF_ERR_NONE = 0x00, |
| 196 | BIF_ERR_GENERAL = 0x10, |
| 197 | BIF_ERR_PARITY = 0x11, |
| 198 | BIF_ERR_INVERSION = 0x12, |
| 199 | BIF_ERR_BAD_LENGTH = 0x13, |
| 200 | BIF_ERR_TIMING = 0x14, |
| 201 | BIF_ERR_UNKNOWN_CMD = 0x15, |
| 202 | BIF_ERR_CMD_SEQ = 0x16, |
| 203 | BIF_ERR_BUS_COLLISION = 0x1F, |
| 204 | BIF_ERR_SLAVE_BUSY = 0x20, |
| 205 | BIF_ERR_FATAL = 0x7F, |
| 206 | }; |
| 207 | |
| 208 | /** |
| 209 | * struct bif_protocol_function - constant data present in protocol function |
| 210 | * @l2_entry: Pointer to protocol function L2 DDB data struct |
| 211 | * @protocol_pointer: BIF slave address where protocol registers begin |
| 212 | * @device_id_pointer: BIF slave address where device ID begins |
| 213 | * @device_id: The 8-byte unique device ID in MSB to LSB order |
| 214 | */ |
| 215 | struct bif_protocol_function { |
| 216 | struct bif_ddb_l2_data *l2_entry; |
| 217 | u16 protocol_pointer; |
| 218 | u16 device_id_pointer; |
| 219 | u8 device_id[BIF_DEVICE_ID_BYTE_LENGTH]; /* Unique ID */ |
| 220 | }; |
| 221 | |
| 222 | #define PROTOCOL_FUNC_DEV_ADR_ADDR(protocol_pointer) ((protocol_pointer) + 0) |
| 223 | #define PROTOCOL_FUNC_ERR_CODE_ADDR(protocol_pointer) ((protocol_pointer) + 2) |
| 224 | #define PROTOCOL_FUNC_ERR_CNT_ADDR(protocol_pointer) ((protocol_pointer) + 3) |
| 225 | #define PROTOCOL_FUNC_WORD_CNT_ADDR(protocol_pointer) ((protocol_pointer) + 4) |
| 226 | |
| 227 | /** |
| 228 | * struct bif_slave_control_function - constant data present in slave control |
| 229 | * function as well internal software state parameters |
| 230 | * @l2_entry: Pointer to slave control function L2 DDB data struct |
| 231 | * @slave_ctrl_pointer: BIF slave address where slave control registers begin |
| 232 | * @task_count: Number of tasks supported by the slave |
| 233 | * @irq_notifier_list: List of notifiers for consumers drivers that wish to be |
| 234 | * notified when any given interrupt triggers. This list |
| 235 | * is dynamically allocated with length task_count. |
| 236 | */ |
| 237 | struct bif_slave_control_function { |
| 238 | struct bif_ddb_l2_data *l2_entry; |
| 239 | u16 slave_ctrl_pointer; |
| 240 | unsigned int task_count; |
| 241 | struct blocking_notifier_head *irq_notifier_list; |
| 242 | }; |
| 243 | |
| 244 | #define SLAVE_CTRL_TASKS_PER_SET 8 |
| 245 | |
| 246 | /** |
| 247 | * bif_slave_control_task_is_valid() - returns true if the specified task |
| 248 | * is supported by the slave or false if it isn't |
| 249 | * @func: Pointer to slave's slave control function structure |
| 250 | * @task: Slave task number to check |
| 251 | */ |
| 252 | static inline bool |
| 253 | bif_slave_control_task_is_valid(struct bif_slave_control_function *func, |
| 254 | unsigned int task) |
| 255 | { |
| 256 | return func ? task < func->task_count : false; |
| 257 | } |
| 258 | |
| 259 | #define SLAVE_CTRL_FUNC_IRQ_EN_ADDR(slave_ctrl_pointer, task) \ |
| 260 | ((slave_ctrl_pointer) + 4 * ((task) / SLAVE_CTRL_TASKS_PER_SET) + 0) |
| 261 | |
| 262 | #define SLAVE_CTRL_FUNC_IRQ_STATUS_ADDR(slave_ctrl_pointer, task) \ |
| 263 | ((slave_ctrl_pointer) + 4 * ((task) / SLAVE_CTRL_TASKS_PER_SET) + 1) |
| 264 | #define SLAVE_CTRL_FUNC_IRQ_CLEAR_ADDR(slave_ctrl_pointer, task) \ |
| 265 | SLAVE_CTRL_FUNC_IRQ_STATUS_ADDR(slave_ctrl_pointer, task) |
| 266 | |
| 267 | #define SLAVE_CTRL_FUNC_TASK_TRIGGER_ADDR(slave_ctrl_pointer, task) \ |
| 268 | ((slave_ctrl_pointer) + 4 * ((task) / SLAVE_CTRL_TASKS_PER_SET) + 2) |
| 269 | #define SLAVE_CTRL_FUNC_TASK_BUSY_ADDR(slave_ctrl_pointer, task) \ |
| 270 | SLAVE_CTRL_FUNC_TASK_TRIGGER_ADDR(slave_ctrl_pointer, task) |
| 271 | |
| 272 | #define SLAVE_CTRL_FUNC_TASK_AUTO_TRIGGER_ADDR(slave_ctrl_pointer, task) \ |
| 273 | ((slave_ctrl_pointer) + 4 * ((task) / SLAVE_CTRL_TASKS_PER_SET) + 3) |
| 274 | |
| 275 | /** |
| 276 | * struct bif_temperature_function - constant data present in temperature |
| 277 | * sensor function |
| 278 | * @temperatuer_pointer: BIF slave address where temperature sensor |
| 279 | * control registers begin |
| 280 | * @slave_control_channel: Slave control channel associated with the |
| 281 | * temperature sensor function. This channel is |
| 282 | * also the task number. |
| 283 | * @accuracy_pointer: BIF slave address where temperature accuracy |
| 284 | * registers begin |
| 285 | */ |
| 286 | struct bif_temperature_function { |
| 287 | u16 temperature_pointer; |
| 288 | u8 slave_control_channel; |
| 289 | u16 accuracy_pointer; |
| 290 | }; |
| 291 | |
| 292 | /** |
| 293 | * enum bif_mipi_object_type - MIPI defined BIF object types |
| 294 | * %BIF_OBJ_END_OF_LIST: Indicates that the end of the object list in |
| 295 | * NVM has been reached |
| 296 | * %BIF_OBJ_SEC_SLAVE: Specifies the UIDs of secondary slaves found |
| 297 | * inside of the battery pack |
| 298 | * %BIF_OBJ_BATT_PARAM: Specifies some variety of battery parameter. |
| 299 | * There is no MIPI defined format for this object |
| 300 | * type so parsing is manufacturer specific. |
| 301 | */ |
| 302 | enum bif_mipi_object_type { |
| 303 | BIF_OBJ_END_OF_LIST = 0x00, |
| 304 | BIF_OBJ_SEC_SLAVE = 0x01, |
| 305 | BIF_OBJ_BATT_PARAM = 0x02, |
| 306 | }; |
| 307 | |
| 308 | /** |
| 309 | * struct bif_object - contains all header and data information for a slave |
| 310 | * data object |
| 311 | * @type: Object type |
| 312 | * @version: Object version |
| 313 | * @manufacturer_id: Manufacturer ID number allocated by MIPI |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 314 | * @length: Length of the entire object including header and CRC; |
| 315 | * data length == total length - 8. |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 316 | * @data: Raw byte data found in the object |
| 317 | * @crc: CRC of the object calculated using CRC-CCITT |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 318 | * @list: Linked-list connection parameter; internal use only |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 319 | * @addr: BIF slave address correspond to the start of the object |
| 320 | * |
| 321 | * manufacturer_id == 0x0000 if MIPI type and version. |
| 322 | */ |
| 323 | struct bif_object { |
| 324 | u8 type; |
| 325 | u8 version; |
| 326 | u16 manufacturer_id; |
| 327 | u16 length; |
| 328 | u8 *data; |
| 329 | u16 crc; |
| 330 | struct list_head list; |
| 331 | u16 addr; |
| 332 | }; |
| 333 | |
| 334 | /** |
| 335 | * struct bif_nvm_function - constant data present in non-volatile memory |
| 336 | * function as well internal software state |
| 337 | * parameters |
| 338 | * @nvm_pointer: BIF slave address where NVM registers begin |
| 339 | * @slave_control_channel: Slave control channel associated with the |
| 340 | * NVM function. This channel is also the task |
| 341 | * number. |
| 342 | * @write_buffer_size: Size in bytes of the NVM write buffer. 0x00 |
| 343 | * is used to denote a 256 byte buffer. |
| 344 | * @nvm_base_address: BIF slave address where NVM begins |
| 345 | * @nvm_size: NVM size in bytes |
David Collins | 95738fe | 2013-09-18 17:17:08 -0700 | [diff] [blame] | 346 | * @nvm_lock_offset: Offset from the beginning of NVM of the first |
| 347 | * writable address |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 348 | * @object_count: Number of BIF objects read from NVM |
| 349 | * @object_list: List of BIF objects read from NVM |
| 350 | */ |
| 351 | struct bif_nvm_function { |
| 352 | u16 nvm_pointer; |
| 353 | u8 slave_control_channel; |
| 354 | u8 write_buffer_size; |
| 355 | u16 nvm_base_address; |
| 356 | u16 nvm_size; |
David Collins | 95738fe | 2013-09-18 17:17:08 -0700 | [diff] [blame] | 357 | u16 nvm_lock_offset; |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 358 | int object_count; |
| 359 | struct list_head object_list; |
| 360 | }; |
| 361 | |
| 362 | /** |
| 363 | * struct bif_ctrl - Opaque handle for a BIF controller to be used in bus |
| 364 | * oriented BIF function calls. |
| 365 | */ |
| 366 | struct bif_ctrl; |
| 367 | |
| 368 | /** |
| 369 | * struct bif_slave - Opaque handle for a BIF slave to be used in slave oriented |
| 370 | * BIF function calls. |
| 371 | */ |
| 372 | struct bif_slave; |
| 373 | |
| 374 | /** |
| 375 | * enum bif_bus_state - indicates the current or desired state of the BIF bus |
| 376 | * %BIF_BUS_STATE_MASTER_DISABLED: BIF host hardware is disabled |
| 377 | * %BIF_BUS_STATE_POWER_DOWN: BIF bus is in power down state and |
| 378 | * BCL is not being pulled high |
| 379 | * %BIF_BUS_STATE_STANDBY: BIF slaves are in standby state in which |
| 380 | * less power is drawn |
| 381 | * %BIF_BUS_STATE_ACTIVE: BIF slaves are ready for immediate |
| 382 | * communications |
| 383 | * %BIF_BUS_STATE_INTERRUPT: BIF bus is active, but no communication |
| 384 | * is possible. Instead, either one of the |
| 385 | * slaves or the master must transition to |
| 386 | * active state by pulling BCL low for 1 |
| 387 | * tau bif period. |
| 388 | */ |
| 389 | enum bif_bus_state { |
| 390 | BIF_BUS_STATE_MASTER_DISABLED, |
| 391 | BIF_BUS_STATE_POWER_DOWN, |
| 392 | BIF_BUS_STATE_STANDBY, |
| 393 | BIF_BUS_STATE_ACTIVE, |
| 394 | BIF_BUS_STATE_INTERRUPT, |
| 395 | }; |
| 396 | |
| 397 | /** |
| 398 | * enum bif_bus_event - events that the BIF framework may send to BIF consumers |
| 399 | * %BIF_BUS_EVENT_BATTERY_INSERTED: Indicates that a battery was just |
| 400 | * inserted physically or that the BIF |
| 401 | * host controller for the battery just |
| 402 | * probed and a battery was already |
| 403 | * present. |
| 404 | * %BIF_BUS_EVENT_BATTERY_REMOVED: Indicates that a battery was just |
| 405 | * removed and thus its slaves are no |
| 406 | * longer accessible. |
| 407 | */ |
| 408 | enum bif_bus_event { |
| 409 | BIF_BUS_EVENT_BATTERY_INSERTED, |
| 410 | BIF_BUS_EVENT_BATTERY_REMOVED, |
| 411 | }; |
| 412 | |
| 413 | /* Mask values to be ORed together for use in bif_match_criteria.match_mask. */ |
| 414 | #define BIF_MATCH_MANUFACTURER_ID BIT(0) |
| 415 | #define BIF_MATCH_PRODUCT_ID BIT(1) |
| 416 | #define BIF_MATCH_FUNCTION_TYPE BIT(2) |
| 417 | #define BIF_MATCH_FUNCTION_VERSION BIT(3) |
| 418 | #define BIF_MATCH_IGNORE_PRESENCE BIT(4) |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 419 | #define BIF_MATCH_OBJ_TYPE BIT(5) |
| 420 | #define BIF_MATCH_OBJ_VERSION BIT(6) |
| 421 | #define BIF_MATCH_OBJ_MANUFACTURER_ID BIT(7) |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 422 | |
| 423 | /** |
| 424 | * struct bif_match_criteria - specifies the matching criteria that a BIF |
| 425 | * consumer uses to find an appropriate BIF slave |
| 426 | * @match_mask: Mask value specifying which parameters to match upon. |
| 427 | * This value should be some ORed combination of |
| 428 | * BIF_MATCH_* specified above. |
| 429 | * @manufacturer_id: Manufacturer ID number allocated by MIPI |
| 430 | * @product_id: Manufacturer specified product ID number |
| 431 | * @function_type: Defines the type of the function. The type may be |
| 432 | * either MIPI or manufacturer defined. |
| 433 | * @function_version: Defines the version of the function. The version may |
| 434 | * be either MIPI or manufacturer defined. |
| 435 | * @ignore_presence: If true, then slaves that are currently not present |
| 436 | * will be successfully matched against. By default, only |
| 437 | * present slaves can be matched. |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 438 | * @obj_type: Defines the type of a BIF object found in the |
| 439 | * non-volatile memory of a slave. |
| 440 | * @obj_version: Defines the version of a BIF object found in the |
| 441 | * non-volatile memory of a slave. |
| 442 | * @obj_manufacturer_id: Manufacturer ID of a BIF object found in the |
| 443 | * non-volatile memory of a slave. |
| 444 | * |
| 445 | * If function_type and function_verion are both specified, then they must both |
| 446 | * match for a single BIF function. If obj_type and obj_version or |
| 447 | * obj_manufacturer_id are specified, then all must match for a single BIF |
| 448 | * object. |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 449 | */ |
| 450 | struct bif_match_criteria { |
| 451 | u32 match_mask; |
| 452 | u16 manufacturer_id; |
| 453 | u16 product_id; |
| 454 | u8 function_type; |
| 455 | u8 function_version; |
| 456 | bool ignore_presence; |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 457 | u8 obj_type; |
| 458 | u8 obj_version; |
| 459 | u16 obj_manufacturer_id; |
| 460 | }; |
| 461 | |
| 462 | /* Mask values to be ORed for use in bif_obj_match_criteria.match_mask. */ |
| 463 | #define BIF_OBJ_MATCH_TYPE BIT(0) |
| 464 | #define BIF_OBJ_MATCH_VERSION BIT(1) |
| 465 | #define BIF_OBJ_MATCH_MANUFACTURER_ID BIT(2) |
| 466 | |
| 467 | /** |
| 468 | * struct bif_obj_match_criteria - specifies the matching criteria that a BIF |
| 469 | * consumer uses to find an appropriate BIF data object |
| 470 | * within a slave |
| 471 | * @match_mask: Mask value specifying which parameters to match upon. |
| 472 | * This value should be some ORed combination of |
| 473 | * BIF_OBJ_MATCH_* specified above. |
| 474 | * @type: Defines the type of the object. The type may be either |
| 475 | * MIPI or manufacturer defined. |
| 476 | * @version: Defines the version of the object. The version may be |
| 477 | * either MIPI or manufacturer defined. |
| 478 | * @manufacturer_id: Manufacturer ID number allocated by MIPI. |
| 479 | */ |
| 480 | struct bif_obj_match_criteria { |
| 481 | u32 match_mask; |
| 482 | u8 type; |
| 483 | u8 version; |
| 484 | u16 manufacturer_id; |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 485 | }; |
| 486 | |
| 487 | /** |
| 488 | * bif_battery_rid_ranges - MIPI-BIF defined Rid battery pack resistance ranges |
| 489 | * %BIF_BATT_RID_SPECIAL1_MIN: Minimum Rid for special case 1 |
| 490 | * %BIF_BATT_RID_SPECIAL1_MAX: Maximum Rid for special case 1 |
| 491 | * %BIF_BATT_RID_SPECIAL2_MIN: Minimum Rid for special case 2 |
| 492 | * %BIF_BATT_RID_SPECIAL2_MAX: Maximum Rid for special case 2 |
| 493 | * %BIF_BATT_RID_SPECIAL3_MIN: Minimum Rid for special case 3 |
| 494 | * %BIF_BATT_RID_SPECIAL3_MAX: Maximum Rid for special case 3 |
| 495 | * %BIF_BATT_RID_LOW_COST_MIN: Minimum Rid for a low cost battery pack |
| 496 | * %BIF_BATT_RID_LOW_COST_MAX: Maximum Rid for a low cost battery pack |
| 497 | * %BIF_BATT_RID_SMART_MIN: Minimum Rid for a smart battery pack |
| 498 | * %BIF_BATT_RID_SMART_MAX: Maximum Rid for a smart battery pack |
| 499 | */ |
| 500 | enum bif_battery_rid_ranges { |
| 501 | BIF_BATT_RID_SPECIAL1_MIN = 0, |
| 502 | BIF_BATT_RID_SPECIAL1_MAX = 1, |
| 503 | BIF_BATT_RID_SPECIAL2_MIN = 7350, |
| 504 | BIF_BATT_RID_SPECIAL2_MAX = 7650, |
| 505 | BIF_BATT_RID_SPECIAL3_MIN = 12740, |
| 506 | BIF_BATT_RID_SPECIAL3_MAX = 13260, |
| 507 | BIF_BATT_RID_LOW_COST_MIN = 19600, |
| 508 | BIF_BATT_RID_LOW_COST_MAX = 140000, |
| 509 | BIF_BATT_RID_SMART_MIN = 240000, |
| 510 | BIF_BATT_RID_SMART_MAX = 450000, |
| 511 | }; |
| 512 | |
| 513 | #ifdef CONFIG_BIF |
| 514 | |
| 515 | int bif_request_irq(struct bif_slave *slave, unsigned int task, |
| 516 | struct notifier_block *nb); |
| 517 | int bif_free_irq(struct bif_slave *slave, unsigned int task, |
| 518 | struct notifier_block *nb); |
| 519 | |
| 520 | int bif_trigger_task(struct bif_slave *slave, unsigned int task); |
David Collins | bf6a635 | 2013-04-11 13:46:53 -0700 | [diff] [blame] | 521 | int bif_enable_auto_task(struct bif_slave *slave, unsigned int task); |
| 522 | int bif_disable_auto_task(struct bif_slave *slave, unsigned int task); |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 523 | int bif_task_is_busy(struct bif_slave *slave, unsigned int task); |
| 524 | |
| 525 | int bif_ctrl_count(void); |
| 526 | struct bif_ctrl *bif_ctrl_get_by_id(unsigned int id); |
| 527 | struct bif_ctrl *bif_ctrl_get(struct device *consumer_dev); |
| 528 | void bif_ctrl_put(struct bif_ctrl *ctrl); |
| 529 | |
| 530 | int bif_ctrl_signal_battery_changed(struct bif_ctrl *ctrl); |
| 531 | |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 532 | int bif_slave_match_count(struct bif_ctrl *ctrl, |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 533 | const struct bif_match_criteria *match_criteria); |
| 534 | |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 535 | struct bif_slave *bif_slave_match_get(struct bif_ctrl *ctrl, |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 536 | unsigned int id, const struct bif_match_criteria *match_criteria); |
| 537 | |
| 538 | void bif_slave_put(struct bif_slave *slave); |
| 539 | |
| 540 | int bif_ctrl_notifier_register(struct bif_ctrl *ctrl, |
| 541 | struct notifier_block *nb); |
| 542 | |
| 543 | int bif_ctrl_notifier_unregister(struct bif_ctrl *ctrl, |
| 544 | struct notifier_block *nb); |
| 545 | |
| 546 | struct bif_ctrl *bif_get_ctrl_handle(struct bif_slave *slave); |
| 547 | |
| 548 | int bif_slave_find_function(struct bif_slave *slave, u8 function, u8 *version, |
| 549 | u16 *function_pointer); |
| 550 | |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 551 | int bif_object_match_count(struct bif_slave *slave, |
| 552 | const struct bif_obj_match_criteria *match_criteria); |
| 553 | |
| 554 | struct bif_object *bif_object_match_get(struct bif_slave *slave, |
| 555 | unsigned int id, const struct bif_obj_match_criteria *match_criteria); |
| 556 | |
| 557 | void bif_object_put(struct bif_object *object); |
| 558 | |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 559 | int bif_slave_read(struct bif_slave *slave, u16 addr, u8 *buf, int len); |
| 560 | int bif_slave_write(struct bif_slave *slave, u16 addr, u8 *buf, int len); |
| 561 | |
David Collins | 95738fe | 2013-09-18 17:17:08 -0700 | [diff] [blame] | 562 | int bif_slave_nvm_raw_read(struct bif_slave *slave, u16 offset, u8 *buf, |
| 563 | int len); |
| 564 | int bif_slave_nvm_raw_write(struct bif_slave *slave, u16 offset, u8 *buf, |
| 565 | int len); |
| 566 | |
David Collins | 2cf302f | 2013-09-23 17:33:13 -0700 | [diff] [blame] | 567 | int bif_object_write(struct bif_slave *slave, u8 type, u8 version, u16 |
| 568 | manufacturer_id, const u8 *data, int data_len); |
| 569 | |
| 570 | int bif_object_overwrite(struct bif_slave *slave, |
| 571 | struct bif_object *object, u8 type, u8 version, |
| 572 | u16 manufacturer_id, const u8 *data, int data_len); |
| 573 | |
| 574 | int bif_object_delete(struct bif_slave *slave, const struct bif_object *object); |
| 575 | |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 576 | int bif_slave_is_present(struct bif_slave *slave); |
| 577 | |
| 578 | int bif_slave_is_selected(struct bif_slave *slave); |
| 579 | int bif_slave_select(struct bif_slave *slave); |
| 580 | |
| 581 | int bif_ctrl_raw_transaction(struct bif_ctrl *ctrl, int transaction, u8 data); |
| 582 | int bif_ctrl_raw_transaction_read(struct bif_ctrl *ctrl, int transaction, |
| 583 | u8 data, int *response); |
| 584 | int bif_ctrl_raw_transaction_query(struct bif_ctrl *ctrl, int transaction, |
| 585 | u8 data, bool *query_response); |
| 586 | |
| 587 | void bif_ctrl_bus_lock(struct bif_ctrl *ctrl); |
| 588 | void bif_ctrl_bus_unlock(struct bif_ctrl *ctrl); |
| 589 | |
| 590 | u16 bif_crc_ccitt(const u8 *buffer, unsigned int len); |
| 591 | |
| 592 | int bif_ctrl_measure_rid(struct bif_ctrl *ctrl); |
| 593 | int bif_ctrl_get_bus_period(struct bif_ctrl *ctrl); |
| 594 | int bif_ctrl_set_bus_period(struct bif_ctrl *ctrl, int period_ns); |
| 595 | int bif_ctrl_get_bus_state(struct bif_ctrl *ctrl); |
| 596 | int bif_ctrl_set_bus_state(struct bif_ctrl *ctrl, enum bif_bus_state state); |
| 597 | |
| 598 | #else |
| 599 | |
| 600 | static inline int bif_request_irq(struct bif_slave *slave, unsigned int task, |
| 601 | struct notifier_block *nb) { return -EPERM; } |
| 602 | static inline int bif_free_irq(struct bif_slave *slave, unsigned int task, |
| 603 | struct notifier_block *nb) { return -EPERM; } |
| 604 | |
| 605 | static inline int bif_trigger_task(struct bif_slave *slave, unsigned int task) |
| 606 | { return -EPERM; } |
David Collins | bf6a635 | 2013-04-11 13:46:53 -0700 | [diff] [blame] | 607 | static inline int bif_enable_auto_task(struct bif_slave *slave, |
| 608 | unsigned int task) |
| 609 | { return -EPERM; } |
| 610 | static inline int bif_disable_auto_task(struct bif_slave *slave, |
| 611 | unsigned int task) |
| 612 | { return -EPERM; } |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 613 | static inline int bif_task_is_busy(struct bif_slave *slave, unsigned int task) |
| 614 | { return -EPERM; } |
| 615 | |
| 616 | static inline int bif_ctrl_count(void) { return -EPERM; } |
| 617 | static inline struct bif_ctrl *bif_ctrl_get_by_id(unsigned int id) |
| 618 | { return ERR_PTR(-EPERM); } |
| 619 | struct bif_ctrl *bif_ctrl_get(struct device *consumer_dev) |
| 620 | { return ERR_PTR(-EPERM); } |
| 621 | static inline void bif_ctrl_put(struct bif_ctrl *ctrl) { return; } |
| 622 | |
David Collins | fcd82b3 | 2013-09-25 13:53:59 -0700 | [diff] [blame] | 623 | static inline int bif_ctrl_signal_battery_changed(struct bif_ctrl *ctrl) |
| 624 | { return -EPERM; } |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 625 | |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 626 | static inline int bif_slave_match_count(struct bif_ctrl *ctrl, |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 627 | const struct bif_match_criteria *match_criteria) |
| 628 | { return -EPERM; } |
| 629 | |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 630 | static inline struct bif_slave *bif_slave_match_get(struct bif_ctrl *ctrl, |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 631 | unsigned int id, const struct bif_match_criteria *match_criteria) |
| 632 | { return ERR_PTR(-EPERM); } |
| 633 | |
| 634 | static inline void bif_slave_put(struct bif_slave *slave) { return; } |
| 635 | |
| 636 | static inline int bif_ctrl_notifier_register(struct bif_ctrl *ctrl, |
| 637 | struct notifier_block *nb) |
| 638 | { return -EPERM; } |
| 639 | |
| 640 | static inline int bif_ctrl_notifier_unregister(struct bif_ctrl *ctrl, |
| 641 | struct notifier_block *nb) |
| 642 | { return -EPERM; } |
| 643 | |
| 644 | static inline struct bif_ctrl *bif_get_ctrl_handle(struct bif_slave *slave) |
| 645 | { return ERR_PTR(-EPERM); } |
| 646 | |
| 647 | static inline int bif_slave_find_function(struct bif_slave *slave, u8 function, |
| 648 | u8 *version, u16 *function_pointer) |
| 649 | { return -EPERM; } |
| 650 | |
David Collins | 387d5fb | 2013-09-23 11:51:16 -0700 | [diff] [blame] | 651 | static inline int bif_object_match_count(struct bif_slave *slave, |
| 652 | const struct bif_obj_match_criteria *match_criteria) |
| 653 | { return -EPERM; } |
| 654 | |
| 655 | static inline struct bif_object *bif_object_match_get(struct bif_slave *slave, |
| 656 | unsigned int id, const struct bif_obj_match_criteria *match_criteria) |
| 657 | { return ERR_PTR(-EPERM); } |
| 658 | |
| 659 | static inline void bif_object_put(struct bif_object *object) |
| 660 | {} |
| 661 | |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 662 | static inline int bif_slave_read(struct bif_slave *slave, u16 addr, u8 *buf, |
| 663 | int len) |
| 664 | { return -EPERM; } |
| 665 | static inline int bif_slave_write(struct bif_slave *slave, u16 addr, u8 *buf, |
| 666 | int len) |
| 667 | { return -EPERM; } |
| 668 | |
David Collins | 95738fe | 2013-09-18 17:17:08 -0700 | [diff] [blame] | 669 | static inline int bif_slave_nvm_raw_read(struct bif_slave *slave, u16 offset, |
| 670 | u8 *buf, int len) |
| 671 | { return -EPERM; } |
| 672 | static inline int bif_slave_nvm_raw_write(struct bif_slave *slave, u16 offset, |
| 673 | u8 *buf, int len) |
| 674 | { return -EPERM; } |
| 675 | |
David Collins | 2cf302f | 2013-09-23 17:33:13 -0700 | [diff] [blame] | 676 | static inline int bif_object_write(struct bif_slave *slave, u8 type, u8 version, |
| 677 | u16 manufacturer_id, const u8 *data, int data_len) |
| 678 | { return -EPERM; } |
| 679 | |
| 680 | static inline int bif_object_overwrite(struct bif_slave *slave, |
| 681 | struct bif_object *object, u8 type, u8 version, |
| 682 | u16 manufacturer_id, const u8 *data, int data_len) |
| 683 | { return -EPERM; } |
| 684 | |
| 685 | static inline int bif_object_delete(struct bif_slave *slave, |
| 686 | const struct bif_object *object) |
| 687 | { return -EPERM; } |
| 688 | |
David Collins | fcd82b3 | 2013-09-25 13:53:59 -0700 | [diff] [blame] | 689 | static inline int bif_slave_is_present(struct bif_slave *slave) |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 690 | { return -EPERM; } |
David Collins | fcd82b3 | 2013-09-25 13:53:59 -0700 | [diff] [blame] | 691 | |
| 692 | static inline int bif_slave_is_selected(struct bif_slave *slave) |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 693 | { return -EPERM; } |
David Collins | fcd82b3 | 2013-09-25 13:53:59 -0700 | [diff] [blame] | 694 | static inline int bif_slave_select(struct bif_slave *slave) |
| 695 | { return -EPERM; } |
| 696 | |
| 697 | static inline int bif_ctrl_raw_transaction(struct bif_ctrl *ctrl, |
| 698 | int transaction, u8 data) |
| 699 | { return -EPERM; } |
| 700 | static inline int bif_ctrl_raw_transaction_read(struct bif_ctrl *ctrl, |
| 701 | int transaction, u8 data, int *response) |
| 702 | { return -EPERM; } |
| 703 | static inline int bif_ctrl_raw_transaction_query(struct bif_ctrl *ctrl, |
| 704 | int transaction, u8 data, bool *query_response) |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 705 | { return -EPERM; } |
| 706 | |
| 707 | static inline void bif_ctrl_bus_lock(struct bif_ctrl *ctrl) |
| 708 | { return -EPERM; } |
| 709 | static inline void bif_ctrl_bus_unlock(struct bif_ctrl *ctrl) |
| 710 | { return -EPERM; } |
| 711 | |
| 712 | static inline u16 bif_crc_ccitt(const u8 *buffer, unsigned int len) |
| 713 | { return 0; } |
| 714 | |
| 715 | static inline int bif_ctrl_measure_rid(struct bif_ctrl *ctrl) { return -EPERM; } |
David Collins | fcd82b3 | 2013-09-25 13:53:59 -0700 | [diff] [blame] | 716 | static inline int bif_ctrl_get_bus_period(struct bif_ctrl *ctrl) |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 717 | { return -EPERM; } |
David Collins | fcd82b3 | 2013-09-25 13:53:59 -0700 | [diff] [blame] | 718 | static inline int bif_ctrl_set_bus_period(struct bif_ctrl *ctrl, int period_ns) |
| 719 | { return -EPERM; } |
| 720 | static inline int bif_ctrl_get_bus_state(struct bif_ctrl *ctrl) |
| 721 | { return -EPERM; } |
| 722 | static inline int bif_ctrl_set_bus_state(struct bif_ctrl *ctrl, |
| 723 | enum bif_bus_state state) |
David Collins | ed93049 | 2013-01-23 13:57:09 -0800 | [diff] [blame] | 724 | { return -EPERM; } |
| 725 | |
| 726 | #endif |
| 727 | |
| 728 | #endif |