@@ -51,7 +51,8 @@ static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data);
5151
5252static const char * pisnd_spi_get_serial (void );
5353static const char * pisnd_spi_get_id (void );
54- static const char * pisnd_spi_get_version (void );
54+ static const char * pisnd_spi_get_fw_version (void );
55+ static const char * pisnd_spi_get_hw_version (void );
5556
5657static int pisnd_midi_init (struct snd_card * card );
5758static void pisnd_midi_uninit (void );
@@ -222,7 +223,9 @@ static pisnd_spi_recv_cb g_recvCallback;
222223
223224static char g_serial_num [11 ];
224225static char g_id [25 ];
225- static char g_version [5 ];
226+ enum { MAX_VERSION_STR_LEN = 6 };
227+ static char g_fw_version [MAX_VERSION_STR_LEN ];
228+ static char g_hw_version [MAX_VERSION_STR_LEN ];
226229
227230static uint8_t g_ledFlashDuration ;
228231static bool g_ledFlashDurationChanged ;
@@ -553,7 +556,8 @@ static int spi_read_info(void)
553556 char * p ;
554557
555558 memset (g_serial_num , 0 , sizeof (g_serial_num ));
556- memset (g_version , 0 , sizeof (g_version ));
559+ memset (g_fw_version , 0 , sizeof (g_fw_version ));
560+ strcpy (g_hw_version , "1.0" ); // Assume 1.0 hw version.
557561 memset (g_id , 0 , sizeof (g_id ));
558562
559563 tmp = spi_transfer16 (0 );
@@ -576,12 +580,28 @@ static int spi_read_info(void)
576580 return - EINVAL ;
577581
578582 snprintf (
579- g_version ,
580- sizeof ( g_version ) ,
583+ g_fw_version ,
584+ MAX_VERSION_STR_LEN ,
581585 "%x.%02x" ,
582586 buffer [0 ],
583587 buffer [1 ]
584588 );
589+
590+ g_fw_version [MAX_VERSION_STR_LEN - 1 ] = '\0' ;
591+ break ;
592+ case 3 :
593+ if (n != 2 )
594+ return - EINVAL ;
595+
596+ snprintf (
597+ g_hw_version ,
598+ MAX_VERSION_STR_LEN ,
599+ "%x.%x" ,
600+ buffer [0 ],
601+ buffer [1 ]
602+ );
603+
604+ g_hw_version [MAX_VERSION_STR_LEN - 1 ] = '\0' ;
585605 break ;
586606 case 1 :
587607 if (n >= sizeof (g_serial_num ))
@@ -591,12 +611,14 @@ static int spi_read_info(void)
591611 break ;
592612 case 2 :
593613 {
594- if (n >= sizeof (g_id ))
614+ if (n * 2 >= sizeof (g_id ))
595615 return - EINVAL ;
596616
597617 p = g_id ;
598618 for (j = 0 ; j < n ; ++ j )
599619 p += sprintf (p , "%02x" , buffer [j ]);
620+
621+ * p = '\0' ;
600622 }
601623 break ;
602624 default :
@@ -614,7 +636,8 @@ static int pisnd_spi_init(struct device *dev)
614636
615637 memset (g_serial_num , 0 , sizeof (g_serial_num ));
616638 memset (g_id , 0 , sizeof (g_id ));
617- memset (g_version , 0 , sizeof (g_version ));
639+ memset (g_fw_version , 0 , sizeof (g_fw_version ));
640+ memset (g_hw_version , 0 , sizeof (g_hw_version ));
618641
619642 spi = pisnd_spi_find_device ();
620643
@@ -724,26 +747,22 @@ static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data)
724747
725748static const char * pisnd_spi_get_serial (void )
726749{
727- if (strlen (g_serial_num ))
728- return g_serial_num ;
729-
730- return "" ;
750+ return g_serial_num ;
731751}
732752
733753static const char * pisnd_spi_get_id (void )
734754{
735- if (strlen (g_id ))
736- return g_id ;
737-
738- return "" ;
755+ return g_id ;
739756}
740757
741- static const char * pisnd_spi_get_version (void )
758+ static const char * pisnd_spi_get_fw_version (void )
742759{
743- if ( strlen ( g_version ))
744- return g_version ;
760+ return g_fw_version ;
761+ }
745762
746- return "" ;
763+ static const char * pisnd_spi_get_hw_version (void )
764+ {
765+ return g_hw_version ;
747766}
748767
749768static const struct of_device_id pisound_of_match [] = {
@@ -1049,13 +1068,22 @@ static ssize_t pisnd_id_show(
10491068 return sprintf (buf , "%s\n" , pisnd_spi_get_id ());
10501069}
10511070
1052- static ssize_t pisnd_version_show (
1071+ static ssize_t pisnd_fw_version_show (
10531072 struct kobject * kobj ,
10541073 struct kobj_attribute * attr ,
10551074 char * buf
10561075 )
10571076{
1058- return sprintf (buf , "%s\n" , pisnd_spi_get_version ());
1077+ return sprintf (buf , "%s\n" , pisnd_spi_get_fw_version ());
1078+ }
1079+
1080+ static ssize_t pisnd_hw_version_show (
1081+ struct kobject * kobj ,
1082+ struct kobj_attribute * attr ,
1083+ char * buf
1084+ )
1085+ {
1086+ return sprintf (buf , "%s\n" , pisnd_spi_get_hw_version ());
10591087}
10601088
10611089static ssize_t pisnd_led_store (
@@ -1080,15 +1108,18 @@ static struct kobj_attribute pisnd_serial_attribute =
10801108 __ATTR (serial , 0444 , pisnd_serial_show , NULL );
10811109static struct kobj_attribute pisnd_id_attribute =
10821110 __ATTR (id , 0444 , pisnd_id_show , NULL );
1083- static struct kobj_attribute pisnd_version_attribute =
1084- __ATTR (version , 0444 , pisnd_version_show , NULL );
1111+ static struct kobj_attribute pisnd_fw_version_attribute =
1112+ __ATTR (version , 0444 , pisnd_fw_version_show , NULL );
1113+ static struct kobj_attribute pisnd_hw_version_attribute =
1114+ __ATTR (hw_version , 0444 , pisnd_hw_version_show , NULL );
10851115static struct kobj_attribute pisnd_led_attribute =
10861116 __ATTR (led , 0644 , NULL , pisnd_led_store );
10871117
10881118static struct attribute * attrs [] = {
10891119 & pisnd_serial_attribute .attr ,
10901120 & pisnd_id_attribute .attr ,
1091- & pisnd_version_attribute .attr ,
1121+ & pisnd_fw_version_attribute .attr ,
1122+ & pisnd_hw_version_attribute .attr ,
10921123 & pisnd_led_attribute .attr ,
10931124 NULL
10941125};
@@ -1107,9 +1138,10 @@ static int pisnd_probe(struct platform_device *pdev)
11071138 }
11081139
11091140 printi ("Detected Pisound card:\n" );
1110- printi ("\tSerial: %s\n" , pisnd_spi_get_serial ());
1111- printi ("\tVersion: %s\n" , pisnd_spi_get_version ());
1112- printi ("\tId: %s\n" , pisnd_spi_get_id ());
1141+ printi ("\tSerial: %s\n" , pisnd_spi_get_serial ());
1142+ printi ("\tFirmware Version: %s\n" , pisnd_spi_get_fw_version ());
1143+ printi ("\tHardware Version: %s\n" , pisnd_spi_get_hw_version ());
1144+ printi ("\tId: %s\n" , pisnd_spi_get_id ());
11131145
11141146 pisnd_kobj = kobject_create_and_add ("pisound" , kernel_kobj );
11151147 if (!pisnd_kobj ) {
0 commit comments