@@ -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 ;
@@ -558,7 +561,8 @@ static int spi_read_info(void)
558561 char * p ;
559562
560563 memset (g_serial_num , 0 , sizeof (g_serial_num ));
561- memset (g_version , 0 , sizeof (g_version ));
564+ memset (g_fw_version , 0 , sizeof (g_fw_version ));
565+ strcpy (g_hw_version , "1.0" ); // Assume 1.0 hw version.
562566 memset (g_id , 0 , sizeof (g_id ));
563567
564568 tmp = spi_transfer16 (0 );
@@ -581,12 +585,28 @@ static int spi_read_info(void)
581585 return - EINVAL ;
582586
583587 snprintf (
584- g_version ,
585- sizeof ( g_version ) ,
588+ g_fw_version ,
589+ MAX_VERSION_STR_LEN ,
586590 "%x.%02x" ,
587591 buffer [0 ],
588592 buffer [1 ]
589593 );
594+
595+ g_fw_version [MAX_VERSION_STR_LEN - 1 ] = '\0' ;
596+ break ;
597+ case 3 :
598+ if (n != 2 )
599+ return - EINVAL ;
600+
601+ snprintf (
602+ g_hw_version ,
603+ MAX_VERSION_STR_LEN ,
604+ "%x.%x" ,
605+ buffer [0 ],
606+ buffer [1 ]
607+ );
608+
609+ g_hw_version [MAX_VERSION_STR_LEN - 1 ] = '\0' ;
590610 break ;
591611 case 1 :
592612 if (n >= sizeof (g_serial_num ))
@@ -596,12 +616,14 @@ static int spi_read_info(void)
596616 break ;
597617 case 2 :
598618 {
599- if (n >= sizeof (g_id ))
619+ if (n * 2 >= sizeof (g_id ))
600620 return - EINVAL ;
601621
602622 p = g_id ;
603623 for (j = 0 ; j < n ; ++ j )
604624 p += sprintf (p , "%02x" , buffer [j ]);
625+
626+ * p = '\0' ;
605627 }
606628 break ;
607629 default :
@@ -619,7 +641,8 @@ static int pisnd_spi_init(struct device *dev)
619641
620642 memset (g_serial_num , 0 , sizeof (g_serial_num ));
621643 memset (g_id , 0 , sizeof (g_id ));
622- memset (g_version , 0 , sizeof (g_version ));
644+ memset (g_fw_version , 0 , sizeof (g_fw_version ));
645+ memset (g_hw_version , 0 , sizeof (g_hw_version ));
623646
624647 spi = pisnd_spi_find_device ();
625648
@@ -729,26 +752,22 @@ static void pisnd_spi_set_callback(pisnd_spi_recv_cb cb, void *data)
729752
730753static const char * pisnd_spi_get_serial (void )
731754{
732- if (strlen (g_serial_num ))
733- return g_serial_num ;
734-
735- return "" ;
755+ return g_serial_num ;
736756}
737757
738758static const char * pisnd_spi_get_id (void )
739759{
740- if (strlen (g_id ))
741- return g_id ;
742-
743- return "" ;
760+ return g_id ;
744761}
745762
746- static const char * pisnd_spi_get_version (void )
763+ static const char * pisnd_spi_get_fw_version (void )
747764{
748- if ( strlen ( g_version ))
749- return g_version ;
765+ return g_fw_version ;
766+ }
750767
751- return "" ;
768+ static const char * pisnd_spi_get_hw_version (void )
769+ {
770+ return g_hw_version ;
752771}
753772
754773static const struct of_device_id pisound_of_match [] = {
@@ -1056,13 +1075,22 @@ static ssize_t pisnd_id_show(
10561075 return sprintf (buf , "%s\n" , pisnd_spi_get_id ());
10571076}
10581077
1059- static ssize_t pisnd_version_show (
1078+ static ssize_t pisnd_fw_version_show (
10601079 struct kobject * kobj ,
10611080 struct kobj_attribute * attr ,
10621081 char * buf
10631082 )
10641083{
1065- return sprintf (buf , "%s\n" , pisnd_spi_get_version ());
1084+ return sprintf (buf , "%s\n" , pisnd_spi_get_fw_version ());
1085+ }
1086+
1087+ static ssize_t pisnd_hw_version_show (
1088+ struct kobject * kobj ,
1089+ struct kobj_attribute * attr ,
1090+ char * buf
1091+ )
1092+ {
1093+ return sprintf (buf , "%s\n" , pisnd_spi_get_hw_version ());
10661094}
10671095
10681096static ssize_t pisnd_led_store (
@@ -1087,15 +1115,18 @@ static struct kobj_attribute pisnd_serial_attribute =
10871115 __ATTR (serial , 0444 , pisnd_serial_show , NULL );
10881116static struct kobj_attribute pisnd_id_attribute =
10891117 __ATTR (id , 0444 , pisnd_id_show , NULL );
1090- static struct kobj_attribute pisnd_version_attribute =
1091- __ATTR (version , 0444 , pisnd_version_show , NULL );
1118+ static struct kobj_attribute pisnd_fw_version_attribute =
1119+ __ATTR (version , 0444 , pisnd_fw_version_show , NULL );
1120+ static struct kobj_attribute pisnd_hw_version_attribute =
1121+ __ATTR (hw_version , 0444 , pisnd_hw_version_show , NULL );
10921122static struct kobj_attribute pisnd_led_attribute =
10931123 __ATTR (led , 0644 , NULL , pisnd_led_store );
10941124
10951125static struct attribute * attrs [] = {
10961126 & pisnd_serial_attribute .attr ,
10971127 & pisnd_id_attribute .attr ,
1098- & pisnd_version_attribute .attr ,
1128+ & pisnd_fw_version_attribute .attr ,
1129+ & pisnd_hw_version_attribute .attr ,
10991130 & pisnd_led_attribute .attr ,
11001131 NULL
11011132};
@@ -1114,9 +1145,10 @@ static int pisnd_probe(struct platform_device *pdev)
11141145 }
11151146
11161147 printi ("Detected Pisound card:\n" );
1117- printi ("\tSerial: %s\n" , pisnd_spi_get_serial ());
1118- printi ("\tVersion: %s\n" , pisnd_spi_get_version ());
1119- printi ("\tId: %s\n" , pisnd_spi_get_id ());
1148+ printi ("\tSerial: %s\n" , pisnd_spi_get_serial ());
1149+ printi ("\tFirmware Version: %s\n" , pisnd_spi_get_fw_version ());
1150+ printi ("\tHardware Version: %s\n" , pisnd_spi_get_hw_version ());
1151+ printi ("\tId: %s\n" , pisnd_spi_get_id ());
11201152
11211153 pisnd_kobj = kobject_create_and_add ("pisound" , kernel_kobj );
11221154 if (!pisnd_kobj ) {
0 commit comments