@@ -706,10 +706,10 @@ static void drv_HD_PP_stop(void)
706
706
707
707
*/
708
708
709
- static void drv_HD_I2C_nibble (unsigned char controller , unsigned char nibble )
709
+ static void drv_HD_I2C (unsigned char controller , unsigned char byte , int rs , int rw )
710
710
{
711
711
unsigned char enable ;
712
- unsigned char command ; /* this is actually the first data byte on the PCF8574 */
712
+ unsigned char command = 0 ; /* this is actually the first data byte on the PCF8574 */
713
713
unsigned char data_block [2 ];
714
714
/* enable signal: 'controller' is a bitmask */
715
715
/* bit n .. send to controller #n */
@@ -738,28 +738,51 @@ static void drv_HD_I2C_nibble(unsigned char controller, unsigned char nibble)
738
738
The main advantage we see is that we do 2 less IOCTL's from our driver.
739
739
*/
740
740
741
- command = nibble ;
742
- data_block [0 ] = nibble | enable ;
743
- data_block [1 ] = nibble ;
741
+ if (Bits == 4 ) {
742
+ if (rw )
743
+ byte |= SIGNAL_RW ;
744
+ if (rs )
745
+ byte |= SIGNAL_RS ;
746
+ command = byte ;
747
+ data_block [0 ] = byte | enable ;
748
+ data_block [1 ] = byte ;
749
+
750
+ } else if (Bits == 8 ) {
751
+ if (rw )
752
+ command |= SIGNAL_RW ;
753
+ if (rs )
754
+ command |= SIGNAL_RS ;
755
+
756
+ data_block [0 ] = byte ;
757
+ data_block [1 ] = enable ;
758
+ }
744
759
745
- drv_generic_i2c_command (command , data_block , 2 );
760
+ drv_generic_i2c_command (command , data_block , 2 , Bits );
746
761
}
747
762
748
763
749
764
static void drv_HD_I2C_byte (const unsigned char controller , const unsigned char data )
750
765
{
751
766
/* send data with RS enabled */
752
- drv_HD_I2C_nibble (controller , ((data >> 4 ) & 0x0f ) | SIGNAL_RS );
753
- drv_HD_I2C_nibble (controller , (data & 0x0f ) | SIGNAL_RS );
767
+ if (Bits == 4 ) {
768
+ drv_HD_I2C (controller , ((data >> 4 ) & 0x0f ), 1 , 0 );
769
+ drv_HD_I2C (controller , (data & 0x0f ), 1 , 0 );
770
+ } else if (Bits == 8 ) {
771
+ drv_HD_I2C (controller , data , 1 , 0 );
772
+ }
754
773
}
755
774
756
775
757
776
static void drv_HD_I2C_command (const unsigned char controller , const unsigned char cmd , __attribute__ ((unused ))
758
777
const unsigned long delay )
759
778
{
760
- /* send data with RS disabled */
761
- drv_HD_I2C_nibble (controller , ((cmd >> 4 ) & 0x0f ));
762
- drv_HD_I2C_nibble (controller , ((cmd ) & 0x0f ));
779
+ /* send command data with RS disabled */
780
+ if (Bits == 4 ) {
781
+ drv_HD_I2C (controller , ((cmd >> 4 ) & 0x0f ), 0 , 0 );
782
+ drv_HD_I2C (controller , ((cmd ) & 0x0f ), 0 , 0 );
783
+ } else if (Bits == 8 ) {
784
+ drv_HD_I2C (controller , cmd , 0 , 0 );
785
+ }
763
786
}
764
787
765
788
static void drv_HD_I2C_data (const unsigned char controller , const char * string , const int len , __attribute__ ((unused ))
@@ -781,13 +804,14 @@ static int drv_HD_I2C_load(const char *section)
781
804
{
782
805
if (cfg_number (section , "Bits" , 8 , 4 , 8 , & Bits ) < 0 )
783
806
return -1 ;
784
- if (Bits != 4 ) {
785
- error ("%s: bad %s.Bits '%d' from %s, should be '4'" , Name , section , Bits , cfg_source ());
786
- return -1 ;
787
- }
788
807
789
808
info ("%s: using %d bit mode" , Name , Bits );
790
809
810
+ if (Bits != 4 && Bits != 8 ) {
811
+ error ("%s: bad %s.Bits '%d' from %s, should be '4' or '8'" , Name , section , Bits , cfg_source ());
812
+ return -1 ;
813
+ }
814
+
791
815
if (drv_generic_i2c_open (section , Name ) != 0 ) {
792
816
error ("%s: could not initialize i2c attached device!" , Name );
793
817
return -1 ;
@@ -804,16 +828,24 @@ static int drv_HD_I2C_load(const char *section)
804
828
if ((SIGNAL_GPO = drv_generic_i2c_wire ("GPO" , "GND" )) == 0xff )
805
829
return -1 ;
806
830
807
- /* initialize display */
808
- drv_HD_I2C_nibble (allControllers , 0x03 );
809
- udelay (T_INIT1 ); /* 4 Bit mode, wait 4.1 ms */
810
- drv_HD_I2C_nibble (allControllers , 0x03 );
811
- udelay (T_INIT2 ); /* 4 Bit mode, wait 100 us */
812
- drv_HD_I2C_nibble (allControllers , 0x03 );
813
- udelay (T_INIT1 ); /* 4 Bit mode, wait 4.1 ms */
814
- drv_HD_I2C_nibble (allControllers , 0x02 );
815
- udelay (T_INIT2 ); /* 4 Bit mode, wait 100 us */
816
- drv_HD_I2C_command (allControllers , 0x28 , T_EXEC ); /* 4 Bit mode, 1/16 duty cycle, 5x8 font */
831
+ if (Bits == 4 ) {
832
+ /* initialize display */
833
+ drv_HD_I2C (allControllers , 0x02 , 0 , 0 );
834
+ udelay (T_INIT1 ); /* 4 Bit mode, wait 4.1 ms */
835
+ drv_HD_I2C (allControllers , 0x03 , 0 , 0 );
836
+ udelay (T_INIT2 ); /* 4 Bit mode, wait 100 us */
837
+ drv_HD_I2C (allControllers , 0x03 , 0 , 0 );
838
+ udelay (T_INIT1 ); /* 4 Bit mode, wait 4.1 ms */
839
+ drv_HD_I2C (allControllers , 0x02 , 0 , 0 );
840
+ udelay (T_INIT2 ); /* 4 Bit mode, wait 100 us */
841
+ drv_HD_I2C_command (allControllers , 0x28 , T_EXEC ); /* 4 Bit mode, 1/16 duty cycle, 5x8 font */
842
+ } else if (Bits == 8 ) {
843
+ drv_HD_I2C (allControllers , 0x30 , 0 , 0 ); /* 8 Bit mode, wait 4.1 ms */
844
+ udelay (T_INIT1 ); /* 8 Bit mode, wait 4.1 ms */
845
+ drv_HD_I2C (allControllers , 0x30 , 0 , 0 ); /* 8 Bit mode, wait 100 us */
846
+ udelay (T_INIT2 ); /* 8 Bit mode, wait 4.1 ms */
847
+ drv_HD_I2C_command (allControllers , 0x38 , T_EXEC ); /* 8 Bit mode, 1/16 duty cycle, 5x8 font */
848
+ }
817
849
818
850
info ("%s: I2C initialization done" , Name );
819
851
0 commit comments