@@ -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 [] = {
@@ -1054,13 +1073,22 @@ static ssize_t pisnd_id_show(
10541073 return sprintf (buf , "%s\n" , pisnd_spi_get_id ());
10551074}
10561075
1057- static ssize_t pisnd_version_show (
1076+ static ssize_t pisnd_fw_version_show (
10581077 struct kobject * kobj ,
10591078 struct kobj_attribute * attr ,
10601079 char * buf
10611080 )
10621081{
1063- return sprintf (buf , "%s\n" , pisnd_spi_get_version ());
1082+ return sprintf (buf , "%s\n" , pisnd_spi_get_fw_version ());
1083+ }
1084+
1085+ static ssize_t pisnd_hw_version_show (
1086+ struct kobject * kobj ,
1087+ struct kobj_attribute * attr ,
1088+ char * buf
1089+ )
1090+ {
1091+ return sprintf (buf , "%s\n" , pisnd_spi_get_hw_version ());
10641092}
10651093
10661094static ssize_t pisnd_led_store (
@@ -1085,15 +1113,18 @@ static struct kobj_attribute pisnd_serial_attribute =
10851113 __ATTR (serial , 0444 , pisnd_serial_show , NULL );
10861114static struct kobj_attribute pisnd_id_attribute =
10871115 __ATTR (id , 0444 , pisnd_id_show , NULL );
1088- static struct kobj_attribute pisnd_version_attribute =
1089- __ATTR (version , 0444 , pisnd_version_show , NULL );
1116+ static struct kobj_attribute pisnd_fw_version_attribute =
1117+ __ATTR (version , 0444 , pisnd_fw_version_show , NULL );
1118+ static struct kobj_attribute pisnd_hw_version_attribute =
1119+ __ATTR (hw_version , 0444 , pisnd_hw_version_show , NULL );
10901120static struct kobj_attribute pisnd_led_attribute =
10911121 __ATTR (led , 0644 , NULL , pisnd_led_store );
10921122
10931123static struct attribute * attrs [] = {
10941124 & pisnd_serial_attribute .attr ,
10951125 & pisnd_id_attribute .attr ,
1096- & pisnd_version_attribute .attr ,
1126+ & pisnd_fw_version_attribute .attr ,
1127+ & pisnd_hw_version_attribute .attr ,
10971128 & pisnd_led_attribute .attr ,
10981129 NULL
10991130};
@@ -1112,9 +1143,10 @@ static int pisnd_probe(struct platform_device *pdev)
11121143 }
11131144
11141145 printi ("Detected Pisound card:\n" );
1115- printi ("\tSerial: %s\n" , pisnd_spi_get_serial ());
1116- printi ("\tVersion: %s\n" , pisnd_spi_get_version ());
1117- printi ("\tId: %s\n" , pisnd_spi_get_id ());
1146+ printi ("\tSerial: %s\n" , pisnd_spi_get_serial ());
1147+ printi ("\tFirmware Version: %s\n" , pisnd_spi_get_fw_version ());
1148+ printi ("\tHardware Version: %s\n" , pisnd_spi_get_hw_version ());
1149+ printi ("\tId: %s\n" , pisnd_spi_get_id ());
11181150
11191151 pisnd_kobj = kobject_create_and_add ("pisound" , kernel_kobj );
11201152 if (!pisnd_kobj ) {
0 commit comments