.. | .. |
---|
4 | 4 | * |
---|
5 | 5 | * Copyright (C) 2016 Wolf-Entwicklungen |
---|
6 | 6 | * Marcus Wolf <linux@wolf-entwicklungen.de> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License as published by |
---|
10 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
11 | | - * (at your option) any later version. |
---|
12 | | - * |
---|
13 | | - * This program is distributed in the hope that it will be useful, |
---|
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | | - * GNU General Public License for more details. |
---|
17 | 7 | */ |
---|
18 | 8 | |
---|
19 | 9 | /* enable prosa debug info */ |
---|
.. | .. |
---|
359 | 349 | |
---|
360 | 350 | int rf69_set_output_power_level(struct spi_device *spi, u8 power_level) |
---|
361 | 351 | { |
---|
362 | | - // TODO: Dependency to PA0,1,2 setting |
---|
363 | | - power_level += 18; |
---|
| 352 | + u8 pa_level, ocp, test_pa1, test_pa2; |
---|
| 353 | + bool pa0, pa1, pa2, high_power; |
---|
| 354 | + u8 min_power_level; |
---|
| 355 | + |
---|
| 356 | + // check register pa_level |
---|
| 357 | + pa_level = rf69_read_reg(spi, REG_PALEVEL); |
---|
| 358 | + pa0 = pa_level & MASK_PALEVEL_PA0; |
---|
| 359 | + pa1 = pa_level & MASK_PALEVEL_PA1; |
---|
| 360 | + pa2 = pa_level & MASK_PALEVEL_PA2; |
---|
| 361 | + |
---|
| 362 | + // check high power mode |
---|
| 363 | + ocp = rf69_read_reg(spi, REG_OCP); |
---|
| 364 | + test_pa1 = rf69_read_reg(spi, REG_TESTPA1); |
---|
| 365 | + test_pa2 = rf69_read_reg(spi, REG_TESTPA2); |
---|
| 366 | + high_power = (ocp == 0x0f) && (test_pa1 == 0x5d) && (test_pa2 == 0x7c); |
---|
| 367 | + |
---|
| 368 | + if (pa0 && !pa1 && !pa2) { |
---|
| 369 | + power_level += 18; |
---|
| 370 | + min_power_level = 0; |
---|
| 371 | + } else if (!pa0 && pa1 && !pa2) { |
---|
| 372 | + power_level += 18; |
---|
| 373 | + min_power_level = 16; |
---|
| 374 | + } else if (!pa0 && pa1 && pa2) { |
---|
| 375 | + if (high_power) |
---|
| 376 | + power_level += 11; |
---|
| 377 | + else |
---|
| 378 | + power_level += 14; |
---|
| 379 | + min_power_level = 16; |
---|
| 380 | + } else { |
---|
| 381 | + goto failed; |
---|
| 382 | + } |
---|
364 | 383 | |
---|
365 | 384 | // check input value |
---|
366 | | - if (power_level > 0x1f) { |
---|
367 | | - dev_dbg(&spi->dev, "set: illegal input param"); |
---|
368 | | - return -EINVAL; |
---|
369 | | - } |
---|
| 385 | + if (power_level > 0x1f) |
---|
| 386 | + goto failed; |
---|
| 387 | + |
---|
| 388 | + if (power_level < min_power_level) |
---|
| 389 | + goto failed; |
---|
370 | 390 | |
---|
371 | 391 | // write value |
---|
372 | 392 | return rf69_read_mod_write(spi, REG_PALEVEL, MASK_PALEVEL_OUTPUT_POWER, |
---|
373 | 393 | power_level); |
---|
| 394 | +failed: |
---|
| 395 | + dev_dbg(&spi->dev, "set: illegal input param"); |
---|
| 396 | + return -EINVAL; |
---|
374 | 397 | } |
---|
375 | 398 | |
---|
376 | 399 | int rf69_set_pa_ramp(struct spi_device *spi, enum pa_ramp pa_ramp) |
---|
.. | .. |
---|
634 | 657 | retval = rf69_write_reg(spi, REG_PREAMBLE_MSB, msb); |
---|
635 | 658 | if (retval) |
---|
636 | 659 | return retval; |
---|
637 | | - retval = rf69_write_reg(spi, REG_PREAMBLE_LSB, lsb); |
---|
638 | | - |
---|
639 | | - return retval; |
---|
| 660 | + return rf69_write_reg(spi, REG_PREAMBLE_LSB, lsb); |
---|
640 | 661 | } |
---|
641 | 662 | |
---|
642 | 663 | int rf69_enable_sync(struct spi_device *spi) |
---|
.. | .. |
---|
701 | 722 | switch (packet_format) { |
---|
702 | 723 | case packet_length_var: |
---|
703 | 724 | return rf69_set_bit(spi, REG_PACKETCONFIG1, |
---|
704 | | - MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE); |
---|
| 725 | + MASK_PACKETCONFIG1_PACKET_FORMAT_VARIABLE); |
---|
705 | 726 | case packet_length_fix: |
---|
706 | 727 | return rf69_clear_bit(spi, REG_PACKETCONFIG1, |
---|
707 | | - MASK_PACKETCONFIG1_PAKET_FORMAT_VARIABLE); |
---|
| 728 | + MASK_PACKETCONFIG1_PACKET_FORMAT_VARIABLE); |
---|
708 | 729 | default: |
---|
709 | 730 | dev_dbg(&spi->dev, "set: illegal input param"); |
---|
710 | 731 | return -EINVAL; |
---|
.. | .. |
---|
853 | 874 | #ifdef DEBUG_FIFO_ACCESS |
---|
854 | 875 | int i; |
---|
855 | 876 | #endif |
---|
856 | | - char spi_address = REG_FIFO | WRITE_BIT; |
---|
857 | 877 | u8 local_buffer[FIFO_SIZE + 1]; |
---|
858 | 878 | |
---|
859 | 879 | if (size > FIFO_SIZE) { |
---|
.. | .. |
---|
862 | 882 | return -EMSGSIZE; |
---|
863 | 883 | } |
---|
864 | 884 | |
---|
865 | | - local_buffer[0] = spi_address; |
---|
| 885 | + local_buffer[0] = REG_FIFO | WRITE_BIT; |
---|
866 | 886 | memcpy(&local_buffer[1], buffer, size); |
---|
867 | 887 | |
---|
868 | 888 | #ifdef DEBUG_FIFO_ACCESS |
---|