Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: panel, convert struct to bitmap

There is an anonymous struct which is actually used as a bitmap. So
convert the struct to a bitmap and change code accordingly where
needed.

This also allows for a cleanup of set_data_bits and set_ctrl_bits as
they can use a common helper now. The helper can also be converted to
a for loop instead of doing bit OR. And given it is a for loop now,
bit masking (using BIT_MSK) is moved from the callers there too.

Signed-off-by: Daniel Chromik <daniel.chromik@seznam.cz>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
Acked-by: Willy Tarreau <willy@haproxy.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Daniel Chromik and committed by
Greg Kroah-Hartman
bea7433b 8c79c49c

+40 -47
+40 -47
drivers/misc/panel.c
··· 648 648 649 649 static const char (*keypad_profile)[4][9] = old_keypad_profile; 650 650 651 - /* FIXME: this should be converted to a bit array containing signals states */ 652 - static struct { 653 - unsigned char e; /* parallel LCD E (data latch on falling edge) */ 654 - unsigned char rs; /* parallel LCD RS (0 = cmd, 1 = data) */ 655 - unsigned char rw; /* parallel LCD R/W (0 = W, 1 = R) */ 656 - unsigned char bl; /* parallel LCD backlight (0 = off, 1 = on) */ 657 - unsigned char cl; /* serial LCD clock (latch on rising edge) */ 658 - unsigned char da; /* serial LCD data */ 659 - } bits; 651 + static DECLARE_BITMAP(bits, LCD_BITS); 652 + 653 + static void lcd_get_bits(unsigned int port, int *val) 654 + { 655 + unsigned int bit, state; 656 + 657 + for (bit = 0; bit < LCD_BITS; bit++) { 658 + state = test_bit(bit, bits) ? BIT_SET : BIT_CLR; 659 + *val &= lcd_bits[port][bit][BIT_MSK]; 660 + *val |= lcd_bits[port][bit][state]; 661 + } 662 + } 660 663 661 664 static void init_scan_timer(void); 662 665 663 666 /* sets data port bits according to current signals values */ 664 667 static int set_data_bits(void) 665 668 { 666 - int val, bit; 669 + int val; 667 670 668 671 val = r_dtr(pprt); 669 - for (bit = 0; bit < LCD_BITS; bit++) 670 - val &= lcd_bits[LCD_PORT_D][bit][BIT_MSK]; 671 - 672 - val |= lcd_bits[LCD_PORT_D][LCD_BIT_E][bits.e] 673 - | lcd_bits[LCD_PORT_D][LCD_BIT_RS][bits.rs] 674 - | lcd_bits[LCD_PORT_D][LCD_BIT_RW][bits.rw] 675 - | lcd_bits[LCD_PORT_D][LCD_BIT_BL][bits.bl] 676 - | lcd_bits[LCD_PORT_D][LCD_BIT_CL][bits.cl] 677 - | lcd_bits[LCD_PORT_D][LCD_BIT_DA][bits.da]; 678 - 672 + lcd_get_bits(LCD_PORT_D, &val); 679 673 w_dtr(pprt, val); 680 674 return val; 681 675 } ··· 677 683 /* sets ctrl port bits according to current signals values */ 678 684 static int set_ctrl_bits(void) 679 685 { 680 - int val, bit; 686 + int val; 681 687 682 688 val = r_ctr(pprt); 683 - for (bit = 0; bit < LCD_BITS; bit++) 684 - val &= lcd_bits[LCD_PORT_C][bit][BIT_MSK]; 685 - 686 - val |= lcd_bits[LCD_PORT_C][LCD_BIT_E][bits.e] 687 - | lcd_bits[LCD_PORT_C][LCD_BIT_RS][bits.rs] 688 - | lcd_bits[LCD_PORT_C][LCD_BIT_RW][bits.rw] 689 - | lcd_bits[LCD_PORT_C][LCD_BIT_BL][bits.bl] 690 - | lcd_bits[LCD_PORT_C][LCD_BIT_CL][bits.cl] 691 - | lcd_bits[LCD_PORT_C][LCD_BIT_DA][bits.da]; 692 - 689 + lcd_get_bits(LCD_PORT_C, &val); 693 690 w_ctr(pprt, val); 694 691 return val; 695 692 } ··· 776 791 * LCD reads D0 on STROBE's rising edge. 777 792 */ 778 793 for (bit = 0; bit < 8; bit++) { 779 - bits.cl = BIT_CLR; /* CLK low */ 794 + clear_bit(LCD_BIT_CL, bits); /* CLK low */ 780 795 panel_set_bits(); 781 - bits.da = byte & 1; 796 + if (byte & 1) { 797 + set_bit(LCD_BIT_DA, bits); 798 + } else { 799 + clear_bit(LCD_BIT_DA, bits); 800 + } 801 + 782 802 panel_set_bits(); 783 803 udelay(2); /* maintain the data during 2 us before CLK up */ 784 - bits.cl = BIT_SET; /* CLK high */ 804 + set_bit(LCD_BIT_CL, bits); /* CLK high */ 785 805 panel_set_bits(); 786 806 udelay(1); /* maintain the strobe during 1 us */ 787 807 byte >>= 1; ··· 801 811 802 812 /* The backlight is activated by setting the AUTOFEED line to +5V */ 803 813 spin_lock_irq(&pprt_lock); 804 - bits.bl = on; 814 + if (on) 815 + set_bit(LCD_BIT_BL, bits); 816 + else 817 + clear_bit(LCD_BIT_BL, bits); 805 818 panel_set_bits(); 806 819 spin_unlock_irq(&pprt_lock); 807 820 } ··· 839 846 w_dtr(pprt, cmd); 840 847 udelay(20); /* maintain the data during 20 us before the strobe */ 841 848 842 - bits.e = BIT_SET; 843 - bits.rs = BIT_CLR; 844 - bits.rw = BIT_CLR; 849 + set_bit(LCD_BIT_E, bits); 850 + clear_bit(LCD_BIT_RS, bits); 851 + clear_bit(LCD_BIT_RW, bits); 845 852 set_ctrl_bits(); 846 853 847 854 udelay(40); /* maintain the strobe during 40 us */ 848 855 849 - bits.e = BIT_CLR; 856 + clear_bit(LCD_BIT_E, bits); 850 857 set_ctrl_bits(); 851 858 852 859 udelay(120); /* the shortest command takes at least 120 us */ ··· 861 868 w_dtr(pprt, data); 862 869 udelay(20); /* maintain the data during 20 us before the strobe */ 863 870 864 - bits.e = BIT_SET; 865 - bits.rs = BIT_SET; 866 - bits.rw = BIT_CLR; 871 + set_bit(LCD_BIT_E, bits); 872 + set_bit(LCD_BIT_RS, bits); 873 + clear_bit(LCD_BIT_RW, bits); 867 874 set_ctrl_bits(); 868 875 869 876 udelay(40); /* maintain the strobe during 40 us */ 870 877 871 - bits.e = BIT_CLR; 878 + clear_bit(LCD_BIT_E, bits); 872 879 set_ctrl_bits(); 873 880 874 881 udelay(45); /* the shortest data takes at least 45 us */ ··· 961 968 /* maintain the data during 20 us before the strobe */ 962 969 udelay(20); 963 970 964 - bits.e = BIT_SET; 965 - bits.rs = BIT_SET; 966 - bits.rw = BIT_CLR; 971 + set_bit(LCD_BIT_E, bits); 972 + set_bit(LCD_BIT_RS, bits); 973 + clear_bit(LCD_BIT_RW, bits); 967 974 set_ctrl_bits(); 968 975 969 976 /* maintain the strobe during 40 us */ 970 977 udelay(40); 971 978 972 - bits.e = BIT_CLR; 979 + clear_bit(LCD_BIT_E, bits); 973 980 set_ctrl_bits(); 974 981 975 982 /* the shortest data takes at least 45 us */