1919
2020#include "c_can.h"
2121
22+ #define PCI_DEVICE_ID_PCH_CAN 0x8818
23+ #define PCH_PCI_SOFT_RESET 0x01fc
24+
2225enum c_can_pci_reg_align {
2326 C_CAN_REG_ALIGN_16 ,
2427 C_CAN_REG_ALIGN_32 ,
28+ C_CAN_REG_32 ,
2529};
2630
2731struct c_can_pci_data {
@@ -31,6 +35,10 @@ struct c_can_pci_data {
3135 enum c_can_pci_reg_align reg_align ;
3236 /* Set the frequency */
3337 unsigned int freq ;
38+ /* PCI bar number */
39+ int bar ;
40+ /* Callback for reset */
41+ void (* init )(const struct c_can_priv * priv , bool enable );
3442};
3543
3644/*
@@ -63,6 +71,29 @@ static void c_can_pci_write_reg_aligned_to_32bit(struct c_can_priv *priv,
6371 writew (val , priv -> base + 2 * priv -> regs [index ]);
6472}
6573
74+ static u16 c_can_pci_read_reg_32bit (struct c_can_priv * priv ,
75+ enum reg index )
76+ {
77+ return (u16 )ioread32 (priv -> base + 2 * priv -> regs [index ]);
78+ }
79+
80+ static void c_can_pci_write_reg_32bit (struct c_can_priv * priv ,
81+ enum reg index , u16 val )
82+ {
83+ iowrite32 ((u32 )val , priv -> base + 2 * priv -> regs [index ]);
84+ }
85+
86+ static void c_can_pci_reset_pch (const struct c_can_priv * priv , bool enable )
87+ {
88+ if (enable ) {
89+ u32 __iomem * addr = priv -> base + PCH_PCI_SOFT_RESET ;
90+
91+ /* write to sw reset register */
92+ iowrite32 (1 , addr );
93+ iowrite32 (0 , addr );
94+ }
95+ }
96+
6697static int c_can_pci_probe (struct pci_dev * pdev ,
6798 const struct pci_device_id * ent )
6899{
@@ -87,7 +118,8 @@ static int c_can_pci_probe(struct pci_dev *pdev,
87118 pci_set_master (pdev );
88119 pci_enable_msi (pdev );
89120
90- addr = pci_iomap (pdev , 0 , pci_resource_len (pdev , 0 ));
121+ addr = pci_iomap (pdev , c_can_pci_data -> bar ,
122+ pci_resource_len (pdev , c_can_pci_data -> bar ));
91123 if (!addr ) {
92124 dev_err (& pdev -> dev ,
93125 "device has no PCI memory resources, "
@@ -142,11 +174,17 @@ static int c_can_pci_probe(struct pci_dev *pdev,
142174 priv -> read_reg = c_can_pci_read_reg_aligned_to_16bit ;
143175 priv -> write_reg = c_can_pci_write_reg_aligned_to_16bit ;
144176 break ;
177+ case C_CAN_REG_32 :
178+ priv -> read_reg = c_can_pci_read_reg_32bit ;
179+ priv -> write_reg = c_can_pci_write_reg_32bit ;
180+ break ;
145181 default :
146182 ret = - EINVAL ;
147183 goto out_free_c_can ;
148184 }
149185
186+ priv -> raminit = c_can_pci_data -> init ;
187+
150188 ret = register_c_can_dev (dev );
151189 if (ret ) {
152190 dev_err (& pdev -> dev , "registering %s failed (err=%d)\n" ,
@@ -193,6 +231,15 @@ static struct c_can_pci_data c_can_sta2x11= {
193231 .type = BOSCH_C_CAN ,
194232 .reg_align = C_CAN_REG_ALIGN_32 ,
195233 .freq = 52000000 , /* 52 Mhz */
234+ .bar = 0 ,
235+ };
236+
237+ static struct c_can_pci_data c_can_pch = {
238+ .type = BOSCH_C_CAN ,
239+ .reg_align = C_CAN_REG_32 ,
240+ .freq = 50000000 , /* 50 MHz */
241+ .init = c_can_pci_reset_pch ,
242+ .bar = 1 ,
196243};
197244
198245#define C_CAN_ID (_vend , _dev , _driverdata ) { \
@@ -202,6 +249,8 @@ static struct c_can_pci_data c_can_sta2x11= {
202249static DEFINE_PCI_DEVICE_TABLE (c_can_pci_tbl ) = {
203250 C_CAN_ID (PCI_VENDOR_ID_STMICRO , PCI_DEVICE_ID_STMICRO_CAN ,
204251 c_can_sta2x11 ),
252+ C_CAN_ID (PCI_VENDOR_ID_INTEL , PCI_DEVICE_ID_PCH_CAN ,
253+ c_can_pch ),
205254 {},
206255};
207256static struct pci_driver c_can_pci_driver = {
0 commit comments