Lines Matching +full:byte +full:- +full:len
2 i2c-stub.c - I2C/SMBus chip emulator
5 Copyright (C) 2007-2014 Jean Delvare <jdelvare@suse.de>
19 #define pr_fmt(fmt) "i2c-stub: " fmt
56 module_param_array(bank_reg, byte, NULL, S_IRUGO);
60 module_param_array(bank_mask, byte, NULL, S_IRUGO);
64 module_param_array(bank_start, byte, NULL, S_IRUGO);
68 module_param_array(bank_end, byte, NULL, S_IRUGO);
74 u8 len; member
80 u16 words[256]; /* Byte operations use the LSB as per SMBus
104 list_for_each_entry(b, &chip->smbus_blocks, node) { in stub_find_block()
105 if (b->command == command) { in stub_find_block()
114 rb->command = command; in stub_find_block()
115 list_add(&rb->node, &chip->smbus_blocks); in stub_find_block()
122 if (chip->bank_sel && in stub_get_wordp()
123 offset >= chip->bank_start && offset <= chip->bank_end) in stub_get_wordp()
124 return chip->bank_words + in stub_get_wordp()
125 (chip->bank_sel - 1) * chip->bank_size + in stub_get_wordp()
126 offset - chip->bank_start; in stub_get_wordp()
128 return chip->words + offset; in stub_get_wordp()
136 int i, len; in stub_xfer() local
149 return -ENODEV; in stub_xfer()
154 dev_dbg(&adap->dev, "smbus quick - addr 0x%02x\n", addr); in stub_xfer()
160 chip->pointer = command; in stub_xfer()
161 dev_dbg(&adap->dev, in stub_xfer()
162 "smbus byte - addr 0x%02x, wrote 0x%02x.\n", in stub_xfer()
165 wordp = stub_get_wordp(chip, chip->pointer++); in stub_xfer()
166 data->byte = *wordp & 0xff; in stub_xfer()
167 dev_dbg(&adap->dev, in stub_xfer()
168 "smbus byte - addr 0x%02x, read 0x%02x.\n", in stub_xfer()
169 addr, data->byte); in stub_xfer()
179 *wordp |= data->byte; in stub_xfer()
180 dev_dbg(&adap->dev, in stub_xfer()
181 "smbus byte data - addr 0x%02x, wrote 0x%02x at 0x%02x.\n", in stub_xfer()
182 addr, data->byte, command); in stub_xfer()
185 if (chip->bank_words && command == chip->bank_reg) { in stub_xfer()
186 chip->bank_sel = in stub_xfer()
187 (data->byte >> chip->bank_shift) in stub_xfer()
188 & chip->bank_mask; in stub_xfer()
189 dev_dbg(&adap->dev, in stub_xfer()
191 chip->bank_sel); in stub_xfer()
194 data->byte = *wordp & 0xff; in stub_xfer()
195 dev_dbg(&adap->dev, in stub_xfer()
196 "smbus byte data - addr 0x%02x, read 0x%02x at 0x%02x.\n", in stub_xfer()
197 addr, data->byte, command); in stub_xfer()
199 chip->pointer = command + 1; in stub_xfer()
207 *wordp = data->word; in stub_xfer()
208 dev_dbg(&adap->dev, in stub_xfer()
209 "smbus word data - addr 0x%02x, wrote 0x%04x at 0x%02x.\n", in stub_xfer()
210 addr, data->word, command); in stub_xfer()
212 data->word = *wordp; in stub_xfer()
213 dev_dbg(&adap->dev, in stub_xfer()
214 "smbus word data - addr 0x%02x, read 0x%04x at 0x%02x.\n", in stub_xfer()
215 addr, data->word, command); in stub_xfer()
226 if (data->block[0] > 256 - command) /* Avoid overrun */ in stub_xfer()
227 data->block[0] = 256 - command; in stub_xfer()
228 len = data->block[0]; in stub_xfer()
230 for (i = 0; i < len; i++) { in stub_xfer()
231 chip->words[command + i] &= 0xff00; in stub_xfer()
232 chip->words[command + i] |= data->block[1 + i]; in stub_xfer()
234 dev_dbg(&adap->dev, in stub_xfer()
235 "i2c block data - addr 0x%02x, wrote %d bytes at 0x%02x.\n", in stub_xfer()
236 addr, len, command); in stub_xfer()
238 for (i = 0; i < len; i++) { in stub_xfer()
239 data->block[1 + i] = in stub_xfer()
240 chip->words[command + i] & 0xff; in stub_xfer()
242 dev_dbg(&adap->dev, in stub_xfer()
243 "i2c block data - addr 0x%02x, read %d bytes at 0x%02x.\n", in stub_xfer()
244 addr, len, command); in stub_xfer()
255 b = stub_find_block(&adap->dev, chip, command, false); in stub_xfer()
257 len = data->block[0]; in stub_xfer()
258 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) { in stub_xfer()
259 ret = -EINVAL; in stub_xfer()
263 b = stub_find_block(&adap->dev, chip, command, in stub_xfer()
266 ret = -ENOMEM; in stub_xfer()
271 if (len > b->len) in stub_xfer()
272 b->len = len; in stub_xfer()
273 for (i = 0; i < len; i++) in stub_xfer()
274 b->block[i] = data->block[i + 1]; in stub_xfer()
275 /* update for byte and word commands */ in stub_xfer()
276 chip->words[command] = (b->block[0] << 8) | b->len; in stub_xfer()
277 dev_dbg(&adap->dev, in stub_xfer()
278 "smbus block data - addr 0x%02x, wrote %d bytes at 0x%02x.\n", in stub_xfer()
279 addr, len, command); in stub_xfer()
282 dev_dbg(&adap->dev, in stub_xfer()
284 ret = -EOPNOTSUPP; in stub_xfer()
287 len = b->len; in stub_xfer()
288 data->block[0] = len; in stub_xfer()
289 for (i = 0; i < len; i++) in stub_xfer()
290 data->block[i + 1] = b->block[i]; in stub_xfer()
291 dev_dbg(&adap->dev, in stub_xfer()
292 "smbus block data - addr 0x%02x, read %d bytes at 0x%02x.\n", in stub_xfer()
293 addr, len, command); in stub_xfer()
300 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); in stub_xfer()
301 ret = -EOPNOTSUPP; in stub_xfer()
329 chip->bank_reg = bank_reg[i]; in i2c_stub_allocate_banks()
330 chip->bank_start = bank_start[i]; in i2c_stub_allocate_banks()
331 chip->bank_end = bank_end[i]; in i2c_stub_allocate_banks()
332 chip->bank_size = bank_end[i] - bank_start[i] + 1; in i2c_stub_allocate_banks()
335 chip->bank_mask = bank_mask[i]; in i2c_stub_allocate_banks()
336 while (!(chip->bank_mask & 1)) { in i2c_stub_allocate_banks()
337 chip->bank_shift++; in i2c_stub_allocate_banks()
338 chip->bank_mask >>= 1; in i2c_stub_allocate_banks()
341 chip->bank_words = kcalloc(chip->bank_mask * chip->bank_size, in i2c_stub_allocate_banks()
344 if (!chip->bank_words) in i2c_stub_allocate_banks()
345 return -ENOMEM; in i2c_stub_allocate_banks()
348 chip->bank_mask, chip->bank_size, chip->bank_start, in i2c_stub_allocate_banks()
349 chip->bank_end); in i2c_stub_allocate_banks()
369 return -ENODEV; in i2c_stub_init()
376 return -EINVAL; in i2c_stub_init()
387 return -ENOMEM; in i2c_stub_init()