@@ -1828,23 +1828,100 @@ static int idt_ntb_peer_msg_write(struct ntb_dev *ntb, int pidx, int midx,
1828
1828
*=============================================================================
1829
1829
*/
1830
1830
1831
+ /*
1832
+ * idt_get_deg() - convert millidegree Celsius value to just degree
1833
+ * @mdegC: IN - millidegree Celsius value
1834
+ *
1835
+ * Return: Degree corresponding to the passed millidegree value
1836
+ */
1837
+ static inline s8 idt_get_deg (long mdegC )
1838
+ {
1839
+ return mdegC / 1000 ;
1840
+ }
1841
+
1842
+ /*
1843
+ * idt_get_frac() - retrieve 0/0.5 fraction of the millidegree Celsius value
1844
+ * @mdegC: IN - millidegree Celsius value
1845
+ *
1846
+ * Return: 0/0.5 degree fraction of the passed millidegree value
1847
+ */
1848
+ static inline u8 idt_get_deg_frac (long mdegC )
1849
+ {
1850
+ return (mdegC % 1000 ) >= 500 ? 5 : 0 ;
1851
+ }
1852
+
1853
+ /*
1854
+ * idt_get_temp_fmt() - convert millidegree Celsius value to 0:7:1 format
1855
+ * @mdegC: IN - millidegree Celsius value
1856
+ *
1857
+ * Return: 0:7:1 format acceptable by the IDT temperature sensor
1858
+ */
1859
+ static inline u8 idt_temp_get_fmt (long mdegC )
1860
+ {
1861
+ return (idt_get_deg (mdegC ) << 1 ) | (idt_get_deg_frac (mdegC ) ? 1 : 0 );
1862
+ }
1863
+
1864
+ /*
1865
+ * idt_get_temp_sval() - convert temp sample to signed millidegree Celsius
1866
+ * @data: IN - shifted to LSB 8-bits temperature sample
1867
+ *
1868
+ * Return: signed millidegree Celsius
1869
+ */
1870
+ static inline long idt_get_temp_sval (u32 data )
1871
+ {
1872
+ return ((s8 )data / 2 ) * 1000 + (data & 0x1 ? 500 : 0 );
1873
+ }
1874
+
1875
+ /*
1876
+ * idt_get_temp_sval() - convert temp sample to unsigned millidegree Celsius
1877
+ * @data: IN - shifted to LSB 8-bits temperature sample
1878
+ *
1879
+ * Return: unsigned millidegree Celsius
1880
+ */
1881
+ static inline long idt_get_temp_uval (u32 data )
1882
+ {
1883
+ return (data / 2 ) * 1000 + (data & 0x1 ? 500 : 0 );
1884
+ }
1885
+
1831
1886
/*
1832
1887
* idt_read_temp() - read temperature from chip sensor
1833
1888
* @ntb: NTB device context.
1834
- * @val: OUT - integer value of temperature
1835
- * @frac : OUT - fraction
1889
+ * @type: IN - type of the temperature value to read
1890
+ * @val : OUT - integer value of temperature in millidegree Celsius
1836
1891
*/
1837
- static void idt_read_temp (struct idt_ntb_dev * ndev , unsigned char * val ,
1838
- unsigned char * frac )
1892
+ static void idt_read_temp (struct idt_ntb_dev * ndev ,
1893
+ const enum idt_temp_val type , long * val )
1839
1894
{
1840
1895
u32 data ;
1841
1896
1842
- /* Read the data from TEMP field of the TMPSTS register */
1843
- data = idt_sw_read (ndev , IDT_SW_TMPSTS );
1844
- data = GET_FIELD (TMPSTS_TEMP , data );
1845
- /* TEMP field has one fractional bit and seven integer bits */
1846
- * val = data >> 1 ;
1847
- * frac = ((data & 0x1 ) ? 5 : 0 );
1897
+ /* Alter the temperature field in accordance with the passed type */
1898
+ switch (type ) {
1899
+ case IDT_TEMP_CUR :
1900
+ data = GET_FIELD (TMPSTS_TEMP ,
1901
+ idt_sw_read (ndev , IDT_SW_TMPSTS ));
1902
+ break ;
1903
+ case IDT_TEMP_LOW :
1904
+ data = GET_FIELD (TMPSTS_LTEMP ,
1905
+ idt_sw_read (ndev , IDT_SW_TMPSTS ));
1906
+ break ;
1907
+ case IDT_TEMP_HIGH :
1908
+ data = GET_FIELD (TMPSTS_HTEMP ,
1909
+ idt_sw_read (ndev , IDT_SW_TMPSTS ));
1910
+ break ;
1911
+ case IDT_TEMP_OFFSET :
1912
+ /* This is the only field with signed 0:7:1 format */
1913
+ data = GET_FIELD (TMPADJ_OFFSET ,
1914
+ idt_sw_read (ndev , IDT_SW_TMPADJ ));
1915
+ * val = idt_get_temp_sval (data );
1916
+ return ;
1917
+ default :
1918
+ data = GET_FIELD (TMPSTS_TEMP ,
1919
+ idt_sw_read (ndev , IDT_SW_TMPSTS ));
1920
+ break ;
1921
+ }
1922
+
1923
+ /* The rest of the fields accept unsigned 0:7:1 format */
1924
+ * val = idt_get_temp_uval (data );
1848
1925
}
1849
1926
1850
1927
/*
@@ -1860,10 +1937,10 @@ static void idt_read_temp(struct idt_ntb_dev *ndev, unsigned char *val,
1860
1937
*/
1861
1938
static void idt_temp_isr (struct idt_ntb_dev * ndev , u32 ntint_sts )
1862
1939
{
1863
- unsigned char val , frac ;
1940
+ unsigned long mdeg ;
1864
1941
1865
1942
/* Read the current temperature value */
1866
- idt_read_temp (ndev , & val , & frac );
1943
+ idt_read_temp (ndev , IDT_TEMP_CUR , & mdeg );
1867
1944
1868
1945
/* Read the temperature alarm to clean the alarm status out */
1869
1946
/*(void)idt_sw_read(ndev, IDT_SW_TMPALARM);*/
@@ -1875,7 +1952,8 @@ static void idt_temp_isr(struct idt_ntb_dev *ndev, u32 ntint_sts)
1875
1952
"Temp sensor IRQ detected %#08x" , ntint_sts );
1876
1953
1877
1954
/* Print temperature value to log */
1878
- dev_warn (& ndev -> ntb .pdev -> dev , "Temperature %hhu.%hhu" , val , frac );
1955
+ dev_warn (& ndev -> ntb .pdev -> dev , "Temperature %hhd.%hhuC" ,
1956
+ idt_get_deg (mdeg ), idt_get_deg_frac (mdeg ));
1879
1957
}
1880
1958
1881
1959
/*=============================================================================
@@ -2123,9 +2201,9 @@ static ssize_t idt_dbgfs_info_read(struct file *filp, char __user *ubuf,
2123
2201
size_t count , loff_t * offp )
2124
2202
{
2125
2203
struct idt_ntb_dev * ndev = filp -> private_data ;
2126
- unsigned char temp , frac , idx , pidx , cnt ;
2204
+ unsigned char idx , pidx , cnt ;
2205
+ unsigned long irqflags , mdeg ;
2127
2206
ssize_t ret = 0 , off = 0 ;
2128
- unsigned long irqflags ;
2129
2207
enum ntb_speed speed ;
2130
2208
enum ntb_width width ;
2131
2209
char * strbuf ;
@@ -2274,9 +2352,10 @@ static ssize_t idt_dbgfs_info_read(struct file *filp, char __user *ubuf,
2274
2352
off += scnprintf (strbuf + off , size - off , "\n" );
2275
2353
2276
2354
/* Current temperature */
2277
- idt_read_temp (ndev , & temp , & frac );
2355
+ idt_read_temp (ndev , IDT_TEMP_CUR , & mdeg );
2278
2356
off += scnprintf (strbuf + off , size - off ,
2279
- "Switch temperature\t\t- %hhu.%hhuC\n" , temp , frac );
2357
+ "Switch temperature\t\t- %hhd.%hhuC\n" ,
2358
+ idt_get_deg (mdeg ), idt_get_deg_frac (mdeg ));
2280
2359
2281
2360
/* Copy the buffer to the User Space */
2282
2361
ret = simple_read_from_buffer (ubuf , count , offp , strbuf , off );
0 commit comments