blob: 309703e9c42e16311c7e11266f6ee097065645d9 [file] [log] [blame]
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +09001/*
Tomoya MORINAGA7f2732c2011-10-28 09:33:14 +09002 * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +09003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/types.h>
21#include <linux/fs.h>
22#include <linux/uaccess.h>
23#include <linux/string.h>
24#include <linux/pci.h>
25#include <linux/io.h>
26#include <linux/delay.h>
27#include <linux/mutex.h>
28#include <linux/if_ether.h>
29#include <linux/ctype.h>
Denis Turischev6ae705b2011-03-10 15:14:00 +020030#include <linux/dmi.h>
Zubair Lutfullah Kakakhel549ce8f2016-08-12 12:48:52 +010031#include <linux/of.h>
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +090032
33#define PHUB_STATUS 0x00 /* Status Register offset */
34#define PHUB_CONTROL 0x04 /* Control Register offset */
35#define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */
36#define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */
37#define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */
Tomoya MORINAGA275640b2011-05-12 13:12:36 +090038#define PCH_PHUB_MAC_START_ADDR_EG20T 0x14 /* MAC data area start address
39 offset */
40#define PCH_PHUB_MAC_START_ADDR_ML7223 0x20C /* MAC data area start address
41 offset */
42#define PCH_PHUB_ROM_START_ADDR_EG20T 0x80 /* ROM data area start address offset
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +090043 (Intel EG20T PCH)*/
44#define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address
Tomoya MORINAGA7f2732c2011-10-28 09:33:14 +090045 offset(LAPIS Semicon ML7213)
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +090046 */
Tomoya MORINAGA275640b2011-05-12 13:12:36 +090047#define PCH_PHUB_ROM_START_ADDR_ML7223 0x400 /* ROM data area start address
Tomoya MORINAGA7f2732c2011-10-28 09:33:14 +090048 offset(LAPIS Semicon ML7223)
Tomoya MORINAGA275640b2011-05-12 13:12:36 +090049 */
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +090050
51/* MAX number of INT_REDUCE_CONTROL registers */
52#define MAX_NUM_INT_REDUCE_CONTROL_REG 128
53#define PCI_DEVICE_ID_PCH1_PHUB 0x8801
54#define PCH_MINOR_NOS 1
55#define CLKCFG_CAN_50MHZ 0x12000000
56#define CLKCFG_CANCLK_MASK 0xFF000000
Denis Turischev6ae705b2011-03-10 15:14:00 +020057#define CLKCFG_UART_MASK 0xFFFFFF
58
59/* CM-iTC */
60#define CLKCFG_UART_48MHZ (1 << 16)
Zubair Lutfullah Kakakhelbed3d7b2016-08-12 12:48:53 +010061#define CLKCFG_UART_25MHZ (2 << 16)
Denis Turischev6ae705b2011-03-10 15:14:00 +020062#define CLKCFG_BAUDDIV (2 << 20)
63#define CLKCFG_PLL2VCO (8 << 9)
64#define CLKCFG_UARTCLKSEL (1 << 18)
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +090065
Tomoya MORINAGA1a738dc2010-12-22 21:04:11 +090066/* Macros for ML7213 */
Tomoya MORINAGA1a738dc2010-12-22 21:04:11 +090067#define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +090068
Tomoya MORINAGA275640b2011-05-12 13:12:36 +090069/* Macros for ML7223 */
70#define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012 /* for Bus-m */
71#define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002 /* for Bus-n */
72
Tomoya MORINAGA584ad002011-10-28 09:33:13 +090073/* Macros for ML7831 */
74#define PCI_DEVICE_ID_ROHM_ML7831_PHUB 0x8801
75
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +090076/* SROM ACCESS Macro */
77#define PCH_WORD_ADDR_MASK (~((1 << 2) - 1))
78
79/* Registers address offset */
80#define PCH_PHUB_ID_REG 0x0000
81#define PCH_PHUB_QUEUE_PRI_VAL_REG 0x0004
82#define PCH_PHUB_RC_QUEUE_MAXSIZE_REG 0x0008
83#define PCH_PHUB_BRI_QUEUE_MAXSIZE_REG 0x000C
84#define PCH_PHUB_COMP_RESP_TIMEOUT_REG 0x0010
85#define PCH_PHUB_BUS_SLAVE_CONTROL_REG 0x0014
86#define PCH_PHUB_DEADLOCK_AVOID_TYPE_REG 0x0018
87#define PCH_PHUB_INTPIN_REG_WPERMIT_REG0 0x0020
88#define PCH_PHUB_INTPIN_REG_WPERMIT_REG1 0x0024
89#define PCH_PHUB_INTPIN_REG_WPERMIT_REG2 0x0028
90#define PCH_PHUB_INTPIN_REG_WPERMIT_REG3 0x002C
91#define PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE 0x0040
92#define CLKCFG_REG_OFFSET 0x500
Tomoya MORINAGAdd7d7fe2011-07-21 17:07:08 +090093#define FUNCSEL_REG_OFFSET 0x508
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +090094
95#define PCH_PHUB_OROM_SIZE 15360
96
97/**
98 * struct pch_phub_reg - PHUB register structure
99 * @phub_id_reg: PHUB_ID register val
100 * @q_pri_val_reg: QUEUE_PRI_VAL register val
101 * @rc_q_maxsize_reg: RC_QUEUE_MAXSIZE register val
102 * @bri_q_maxsize_reg: BRI_QUEUE_MAXSIZE register val
103 * @comp_resp_timeout_reg: COMP_RESP_TIMEOUT register val
104 * @bus_slave_control_reg: BUS_SLAVE_CONTROL_REG register val
105 * @deadlock_avoid_type_reg: DEADLOCK_AVOID_TYPE register val
106 * @intpin_reg_wpermit_reg0: INTPIN_REG_WPERMIT register 0 val
107 * @intpin_reg_wpermit_reg1: INTPIN_REG_WPERMIT register 1 val
108 * @intpin_reg_wpermit_reg2: INTPIN_REG_WPERMIT register 2 val
109 * @intpin_reg_wpermit_reg3: INTPIN_REG_WPERMIT register 3 val
110 * @int_reduce_control_reg: INT_REDUCE_CONTROL registers val
111 * @clkcfg_reg: CLK CFG register val
Tomoya MORINAGAdd7d7fe2011-07-21 17:07:08 +0900112 * @funcsel_reg: Function select register value
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900113 * @pch_phub_base_address: Register base address
114 * @pch_phub_extrom_base_address: external rom base address
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900115 * @pch_mac_start_address: MAC address area start address
116 * @pch_opt_rom_start_address: Option ROM start address
117 * @ioh_type: Save IOH type
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900118 * @pdev: pointer to pci device struct
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900119 */
120struct pch_phub_reg {
121 u32 phub_id_reg;
122 u32 q_pri_val_reg;
123 u32 rc_q_maxsize_reg;
124 u32 bri_q_maxsize_reg;
125 u32 comp_resp_timeout_reg;
126 u32 bus_slave_control_reg;
127 u32 deadlock_avoid_type_reg;
128 u32 intpin_reg_wpermit_reg0;
129 u32 intpin_reg_wpermit_reg1;
130 u32 intpin_reg_wpermit_reg2;
131 u32 intpin_reg_wpermit_reg3;
132 u32 int_reduce_control_reg[MAX_NUM_INT_REDUCE_CONTROL_REG];
133 u32 clkcfg_reg;
Tomoya MORINAGAdd7d7fe2011-07-21 17:07:08 +0900134 u32 funcsel_reg;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900135 void __iomem *pch_phub_base_address;
136 void __iomem *pch_phub_extrom_base_address;
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900137 u32 pch_mac_start_address;
138 u32 pch_opt_rom_start_address;
139 int ioh_type;
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900140 struct pci_dev *pdev;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900141};
142
143/* SROM SPEC for MAC address assignment offset */
144static const int pch_phub_mac_offset[ETH_ALEN] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa};
145
146static DEFINE_MUTEX(pch_phub_mutex);
147
148/**
149 * pch_phub_read_modify_write_reg() - Reading modifying and writing register
150 * @reg_addr_offset: Register offset address value.
151 * @data: Writing value.
152 * @mask: Mask value.
153 */
154static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip,
155 unsigned int reg_addr_offset,
156 unsigned int data, unsigned int mask)
157{
158 void __iomem *reg_addr = chip->pch_phub_base_address + reg_addr_offset;
159 iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr);
160}
161
Thierry Reding7750efd2014-10-02 09:26:16 +0200162#ifdef CONFIG_PM
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900163/* pch_phub_save_reg_conf - saves register configuration */
164static void pch_phub_save_reg_conf(struct pci_dev *pdev)
165{
166 unsigned int i;
167 struct pch_phub_reg *chip = pci_get_drvdata(pdev);
168
169 void __iomem *p = chip->pch_phub_base_address;
170
171 chip->phub_id_reg = ioread32(p + PCH_PHUB_ID_REG);
172 chip->q_pri_val_reg = ioread32(p + PCH_PHUB_QUEUE_PRI_VAL_REG);
173 chip->rc_q_maxsize_reg = ioread32(p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG);
174 chip->bri_q_maxsize_reg = ioread32(p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG);
175 chip->comp_resp_timeout_reg =
176 ioread32(p + PCH_PHUB_COMP_RESP_TIMEOUT_REG);
177 chip->bus_slave_control_reg =
178 ioread32(p + PCH_PHUB_BUS_SLAVE_CONTROL_REG);
179 chip->deadlock_avoid_type_reg =
180 ioread32(p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG);
181 chip->intpin_reg_wpermit_reg0 =
182 ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0);
183 chip->intpin_reg_wpermit_reg1 =
184 ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1);
185 chip->intpin_reg_wpermit_reg2 =
186 ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2);
187 chip->intpin_reg_wpermit_reg3 =
188 ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3);
189 dev_dbg(&pdev->dev, "%s : "
190 "chip->phub_id_reg=%x, "
191 "chip->q_pri_val_reg=%x, "
192 "chip->rc_q_maxsize_reg=%x, "
193 "chip->bri_q_maxsize_reg=%x, "
194 "chip->comp_resp_timeout_reg=%x, "
195 "chip->bus_slave_control_reg=%x, "
196 "chip->deadlock_avoid_type_reg=%x, "
197 "chip->intpin_reg_wpermit_reg0=%x, "
198 "chip->intpin_reg_wpermit_reg1=%x, "
199 "chip->intpin_reg_wpermit_reg2=%x, "
200 "chip->intpin_reg_wpermit_reg3=%x\n", __func__,
201 chip->phub_id_reg,
202 chip->q_pri_val_reg,
203 chip->rc_q_maxsize_reg,
204 chip->bri_q_maxsize_reg,
205 chip->comp_resp_timeout_reg,
206 chip->bus_slave_control_reg,
207 chip->deadlock_avoid_type_reg,
208 chip->intpin_reg_wpermit_reg0,
209 chip->intpin_reg_wpermit_reg1,
210 chip->intpin_reg_wpermit_reg2,
211 chip->intpin_reg_wpermit_reg3);
212 for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) {
213 chip->int_reduce_control_reg[i] =
214 ioread32(p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i);
215 dev_dbg(&pdev->dev, "%s : "
216 "chip->int_reduce_control_reg[%d]=%x\n",
217 __func__, i, chip->int_reduce_control_reg[i]);
218 }
219 chip->clkcfg_reg = ioread32(p + CLKCFG_REG_OFFSET);
Tomoya MORINAGAdd7d7fe2011-07-21 17:07:08 +0900220 if ((chip->ioh_type == 2) || (chip->ioh_type == 4))
221 chip->funcsel_reg = ioread32(p + FUNCSEL_REG_OFFSET);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900222}
223
224/* pch_phub_restore_reg_conf - restore register configuration */
225static void pch_phub_restore_reg_conf(struct pci_dev *pdev)
226{
227 unsigned int i;
228 struct pch_phub_reg *chip = pci_get_drvdata(pdev);
229 void __iomem *p;
230 p = chip->pch_phub_base_address;
231
232 iowrite32(chip->phub_id_reg, p + PCH_PHUB_ID_REG);
233 iowrite32(chip->q_pri_val_reg, p + PCH_PHUB_QUEUE_PRI_VAL_REG);
234 iowrite32(chip->rc_q_maxsize_reg, p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG);
235 iowrite32(chip->bri_q_maxsize_reg, p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG);
236 iowrite32(chip->comp_resp_timeout_reg,
237 p + PCH_PHUB_COMP_RESP_TIMEOUT_REG);
238 iowrite32(chip->bus_slave_control_reg,
239 p + PCH_PHUB_BUS_SLAVE_CONTROL_REG);
240 iowrite32(chip->deadlock_avoid_type_reg,
241 p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG);
242 iowrite32(chip->intpin_reg_wpermit_reg0,
243 p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0);
244 iowrite32(chip->intpin_reg_wpermit_reg1,
245 p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1);
246 iowrite32(chip->intpin_reg_wpermit_reg2,
247 p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2);
248 iowrite32(chip->intpin_reg_wpermit_reg3,
249 p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3);
250 dev_dbg(&pdev->dev, "%s : "
251 "chip->phub_id_reg=%x, "
252 "chip->q_pri_val_reg=%x, "
253 "chip->rc_q_maxsize_reg=%x, "
254 "chip->bri_q_maxsize_reg=%x, "
255 "chip->comp_resp_timeout_reg=%x, "
256 "chip->bus_slave_control_reg=%x, "
257 "chip->deadlock_avoid_type_reg=%x, "
258 "chip->intpin_reg_wpermit_reg0=%x, "
259 "chip->intpin_reg_wpermit_reg1=%x, "
260 "chip->intpin_reg_wpermit_reg2=%x, "
261 "chip->intpin_reg_wpermit_reg3=%x\n", __func__,
262 chip->phub_id_reg,
263 chip->q_pri_val_reg,
264 chip->rc_q_maxsize_reg,
265 chip->bri_q_maxsize_reg,
266 chip->comp_resp_timeout_reg,
267 chip->bus_slave_control_reg,
268 chip->deadlock_avoid_type_reg,
269 chip->intpin_reg_wpermit_reg0,
270 chip->intpin_reg_wpermit_reg1,
271 chip->intpin_reg_wpermit_reg2,
272 chip->intpin_reg_wpermit_reg3);
273 for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) {
274 iowrite32(chip->int_reduce_control_reg[i],
275 p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i);
276 dev_dbg(&pdev->dev, "%s : "
277 "chip->int_reduce_control_reg[%d]=%x\n",
278 __func__, i, chip->int_reduce_control_reg[i]);
279 }
280
281 iowrite32(chip->clkcfg_reg, p + CLKCFG_REG_OFFSET);
Tomoya MORINAGAdd7d7fe2011-07-21 17:07:08 +0900282 if ((chip->ioh_type == 2) || (chip->ioh_type == 4))
283 iowrite32(chip->funcsel_reg, p + FUNCSEL_REG_OFFSET);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900284}
Thierry Reding7750efd2014-10-02 09:26:16 +0200285#endif
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900286
287/**
288 * pch_phub_read_serial_rom() - Reading Serial ROM
289 * @offset_address: Serial ROM offset address to read.
290 * @data: Read buffer for specified Serial ROM value.
291 */
292static void pch_phub_read_serial_rom(struct pch_phub_reg *chip,
293 unsigned int offset_address, u8 *data)
294{
295 void __iomem *mem_addr = chip->pch_phub_extrom_base_address +
296 offset_address;
297
298 *data = ioread8(mem_addr);
299}
300
301/**
302 * pch_phub_write_serial_rom() - Writing Serial ROM
303 * @offset_address: Serial ROM offset address.
304 * @data: Serial ROM value to write.
305 */
306static int pch_phub_write_serial_rom(struct pch_phub_reg *chip,
307 unsigned int offset_address, u8 data)
308{
309 void __iomem *mem_addr = chip->pch_phub_extrom_base_address +
310 (offset_address & PCH_WORD_ADDR_MASK);
311 int i;
312 unsigned int word_data;
313 unsigned int pos;
314 unsigned int mask;
315 pos = (offset_address % 4) * 8;
316 mask = ~(0xFF << pos);
317
318 iowrite32(PCH_PHUB_ROM_WRITE_ENABLE,
319 chip->pch_phub_extrom_base_address + PHUB_CONTROL);
320
321 word_data = ioread32(mem_addr);
322 iowrite32((word_data & mask) | (u32)data << pos, mem_addr);
323
324 i = 0;
325 while (ioread8(chip->pch_phub_extrom_base_address +
326 PHUB_STATUS) != 0x00) {
327 msleep(1);
328 if (i == PHUB_TIMEOUT)
329 return -ETIMEDOUT;
330 i++;
331 }
332
333 iowrite32(PCH_PHUB_ROM_WRITE_DISABLE,
334 chip->pch_phub_extrom_base_address + PHUB_CONTROL);
335
336 return 0;
337}
338
339/**
340 * pch_phub_read_serial_rom_val() - Read Serial ROM value
341 * @offset_address: Serial ROM address offset value.
342 * @data: Serial ROM value to read.
343 */
344static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip,
345 unsigned int offset_address, u8 *data)
346{
347 unsigned int mem_addr;
348
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900349 mem_addr = chip->pch_mac_start_address +
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900350 pch_phub_mac_offset[offset_address];
351
352 pch_phub_read_serial_rom(chip, mem_addr, data);
353}
354
355/**
356 * pch_phub_write_serial_rom_val() - writing Serial ROM value
357 * @offset_address: Serial ROM address offset value.
358 * @data: Serial ROM value.
359 */
360static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip,
361 unsigned int offset_address, u8 data)
362{
363 int retval;
364 unsigned int mem_addr;
365
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900366 mem_addr = chip->pch_mac_start_address +
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900367 pch_phub_mac_offset[offset_address];
368
369 retval = pch_phub_write_serial_rom(chip, mem_addr, data);
370
371 return retval;
372}
373
374/* pch_phub_gbe_serial_rom_conf - makes Serial ROM header format configuration
375 * for Gigabit Ethernet MAC address
376 */
377static int pch_phub_gbe_serial_rom_conf(struct pch_phub_reg *chip)
378{
379 int retval;
380
381 retval = pch_phub_write_serial_rom(chip, 0x0b, 0xbc);
382 retval |= pch_phub_write_serial_rom(chip, 0x0a, 0x10);
383 retval |= pch_phub_write_serial_rom(chip, 0x09, 0x01);
384 retval |= pch_phub_write_serial_rom(chip, 0x08, 0x02);
385
386 retval |= pch_phub_write_serial_rom(chip, 0x0f, 0x00);
387 retval |= pch_phub_write_serial_rom(chip, 0x0e, 0x00);
388 retval |= pch_phub_write_serial_rom(chip, 0x0d, 0x00);
389 retval |= pch_phub_write_serial_rom(chip, 0x0c, 0x80);
390
391 retval |= pch_phub_write_serial_rom(chip, 0x13, 0xbc);
392 retval |= pch_phub_write_serial_rom(chip, 0x12, 0x10);
393 retval |= pch_phub_write_serial_rom(chip, 0x11, 0x01);
394 retval |= pch_phub_write_serial_rom(chip, 0x10, 0x18);
395
396 retval |= pch_phub_write_serial_rom(chip, 0x1b, 0xbc);
397 retval |= pch_phub_write_serial_rom(chip, 0x1a, 0x10);
398 retval |= pch_phub_write_serial_rom(chip, 0x19, 0x01);
399 retval |= pch_phub_write_serial_rom(chip, 0x18, 0x19);
400
401 retval |= pch_phub_write_serial_rom(chip, 0x23, 0xbc);
402 retval |= pch_phub_write_serial_rom(chip, 0x22, 0x10);
403 retval |= pch_phub_write_serial_rom(chip, 0x21, 0x01);
404 retval |= pch_phub_write_serial_rom(chip, 0x20, 0x3a);
405
406 retval |= pch_phub_write_serial_rom(chip, 0x27, 0x01);
407 retval |= pch_phub_write_serial_rom(chip, 0x26, 0x00);
408 retval |= pch_phub_write_serial_rom(chip, 0x25, 0x00);
409 retval |= pch_phub_write_serial_rom(chip, 0x24, 0x00);
410
411 return retval;
412}
413
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900414/* pch_phub_gbe_serial_rom_conf_mp - makes SerialROM header format configuration
415 * for Gigabit Ethernet MAC address
416 */
417static int pch_phub_gbe_serial_rom_conf_mp(struct pch_phub_reg *chip)
418{
419 int retval;
420 u32 offset_addr;
421
422 offset_addr = 0x200;
423 retval = pch_phub_write_serial_rom(chip, 0x03 + offset_addr, 0xbc);
424 retval |= pch_phub_write_serial_rom(chip, 0x02 + offset_addr, 0x00);
425 retval |= pch_phub_write_serial_rom(chip, 0x01 + offset_addr, 0x40);
426 retval |= pch_phub_write_serial_rom(chip, 0x00 + offset_addr, 0x02);
427
428 retval |= pch_phub_write_serial_rom(chip, 0x07 + offset_addr, 0x00);
429 retval |= pch_phub_write_serial_rom(chip, 0x06 + offset_addr, 0x00);
430 retval |= pch_phub_write_serial_rom(chip, 0x05 + offset_addr, 0x00);
431 retval |= pch_phub_write_serial_rom(chip, 0x04 + offset_addr, 0x80);
432
433 retval |= pch_phub_write_serial_rom(chip, 0x0b + offset_addr, 0xbc);
434 retval |= pch_phub_write_serial_rom(chip, 0x0a + offset_addr, 0x00);
435 retval |= pch_phub_write_serial_rom(chip, 0x09 + offset_addr, 0x40);
436 retval |= pch_phub_write_serial_rom(chip, 0x08 + offset_addr, 0x18);
437
438 retval |= pch_phub_write_serial_rom(chip, 0x13 + offset_addr, 0xbc);
439 retval |= pch_phub_write_serial_rom(chip, 0x12 + offset_addr, 0x00);
440 retval |= pch_phub_write_serial_rom(chip, 0x11 + offset_addr, 0x40);
441 retval |= pch_phub_write_serial_rom(chip, 0x10 + offset_addr, 0x19);
442
443 retval |= pch_phub_write_serial_rom(chip, 0x1b + offset_addr, 0xbc);
444 retval |= pch_phub_write_serial_rom(chip, 0x1a + offset_addr, 0x00);
445 retval |= pch_phub_write_serial_rom(chip, 0x19 + offset_addr, 0x40);
446 retval |= pch_phub_write_serial_rom(chip, 0x18 + offset_addr, 0x3a);
447
448 retval |= pch_phub_write_serial_rom(chip, 0x1f + offset_addr, 0x01);
449 retval |= pch_phub_write_serial_rom(chip, 0x1e + offset_addr, 0x00);
450 retval |= pch_phub_write_serial_rom(chip, 0x1d + offset_addr, 0x00);
451 retval |= pch_phub_write_serial_rom(chip, 0x1c + offset_addr, 0x00);
452
453 return retval;
454}
455
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900456/**
457 * pch_phub_read_gbe_mac_addr() - Read Gigabit Ethernet MAC address
458 * @offset_address: Gigabit Ethernet MAC address offset value.
459 * @data: Buffer of the Gigabit Ethernet MAC address value.
460 */
461static void pch_phub_read_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
462{
463 int i;
464 for (i = 0; i < ETH_ALEN; i++)
465 pch_phub_read_serial_rom_val(chip, i, &data[i]);
466}
467
468/**
469 * pch_phub_write_gbe_mac_addr() - Write MAC address
470 * @offset_address: Gigabit Ethernet MAC address offset value.
471 * @data: Gigabit Ethernet MAC address value.
472 */
473static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
474{
475 int retval;
476 int i;
477
Tomoya MORINAGA2a988792011-11-11 10:12:18 +0900478 if ((chip->ioh_type == 1) || (chip->ioh_type == 5)) /* EG20T or ML7831*/
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900479 retval = pch_phub_gbe_serial_rom_conf(chip);
480 else /* ML7223 */
481 retval = pch_phub_gbe_serial_rom_conf_mp(chip);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900482 if (retval)
483 return retval;
484
485 for (i = 0; i < ETH_ALEN; i++) {
486 retval = pch_phub_write_serial_rom_val(chip, i, data[i]);
487 if (retval)
488 return retval;
489 }
490
491 return retval;
492}
493
494static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj,
495 struct bin_attribute *attr, char *buf,
496 loff_t off, size_t count)
497{
498 unsigned int rom_signature;
499 unsigned char rom_length;
500 unsigned int tmp;
501 unsigned int addr_offset;
502 unsigned int orom_size;
503 int ret;
504 int err;
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900505 ssize_t rom_size;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900506
Geliang Tang85f4f392016-01-13 23:30:10 +0800507 struct pch_phub_reg *chip = dev_get_drvdata(kobj_to_dev(kobj));
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900508
509 ret = mutex_lock_interruptible(&pch_phub_mutex);
510 if (ret) {
511 err = -ERESTARTSYS;
512 goto return_err_nomutex;
513 }
514
515 /* Get Rom signature */
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900516 chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
Colin Ian Kinga75fa122016-02-27 14:52:22 +0000517 if (!chip->pch_phub_extrom_base_address) {
518 err = -ENODATA;
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900519 goto exrom_map_err;
Colin Ian Kinga75fa122016-02-27 14:52:22 +0000520 }
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900521
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900522 pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address,
523 (unsigned char *)&rom_signature);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900524 rom_signature &= 0xff;
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900525 pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address + 1,
526 (unsigned char *)&tmp);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900527 rom_signature |= (tmp & 0xff) << 8;
528 if (rom_signature == 0xAA55) {
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900529 pch_phub_read_serial_rom(chip,
530 chip->pch_opt_rom_start_address + 2,
531 &rom_length);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900532 orom_size = rom_length * 512;
533 if (orom_size < off) {
534 addr_offset = 0;
535 goto return_ok;
536 }
537 if (orom_size < count) {
538 addr_offset = 0;
539 goto return_ok;
540 }
541
542 for (addr_offset = 0; addr_offset < count; addr_offset++) {
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900543 pch_phub_read_serial_rom(chip,
544 chip->pch_opt_rom_start_address + addr_offset + off,
545 &buf[addr_offset]);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900546 }
547 } else {
548 err = -ENODATA;
549 goto return_err;
550 }
551return_ok:
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900552 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900553 mutex_unlock(&pch_phub_mutex);
554 return addr_offset;
555
556return_err:
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900557 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
558exrom_map_err:
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900559 mutex_unlock(&pch_phub_mutex);
560return_err_nomutex:
561 return err;
562}
563
564static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj,
565 struct bin_attribute *attr,
566 char *buf, loff_t off, size_t count)
567{
568 int err;
569 unsigned int addr_offset;
570 int ret;
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900571 ssize_t rom_size;
Geliang Tang85f4f392016-01-13 23:30:10 +0800572 struct pch_phub_reg *chip = dev_get_drvdata(kobj_to_dev(kobj));
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900573
574 ret = mutex_lock_interruptible(&pch_phub_mutex);
575 if (ret)
576 return -ERESTARTSYS;
577
578 if (off > PCH_PHUB_OROM_SIZE) {
579 addr_offset = 0;
580 goto return_ok;
581 }
582 if (count > PCH_PHUB_OROM_SIZE) {
583 addr_offset = 0;
584 goto return_ok;
585 }
586
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900587 chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
588 if (!chip->pch_phub_extrom_base_address) {
589 err = -ENOMEM;
590 goto exrom_map_err;
591 }
592
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900593 for (addr_offset = 0; addr_offset < count; addr_offset++) {
594 if (PCH_PHUB_OROM_SIZE < off + addr_offset)
595 goto return_ok;
596
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900597 ret = pch_phub_write_serial_rom(chip,
598 chip->pch_opt_rom_start_address + addr_offset + off,
599 buf[addr_offset]);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900600 if (ret) {
601 err = ret;
602 goto return_err;
603 }
604 }
605
606return_ok:
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900607 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900608 mutex_unlock(&pch_phub_mutex);
609 return addr_offset;
610
611return_err:
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900612 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
613
614exrom_map_err:
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900615 mutex_unlock(&pch_phub_mutex);
616 return err;
617}
618
619static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr,
620 char *buf)
621{
622 u8 mac[8];
623 struct pch_phub_reg *chip = dev_get_drvdata(dev);
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900624 ssize_t rom_size;
625
626 chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
627 if (!chip->pch_phub_extrom_base_address)
628 return -ENOMEM;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900629
630 pch_phub_read_gbe_mac_addr(chip, mac);
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900631 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900632
Andy Shevchenko25b8a882011-07-18 11:22:06 +0300633 return sprintf(buf, "%pM\n", mac);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900634}
635
636static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr,
637 const char *buf, size_t count)
638{
Andy Shevchenko143e9c72013-05-28 18:54:58 +0300639 u8 mac[ETH_ALEN];
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900640 ssize_t rom_size;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900641 struct pch_phub_reg *chip = dev_get_drvdata(dev);
Alexander Steina246b972014-03-05 10:44:57 +0100642 int ret;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900643
Andy Shevchenko143e9c72013-05-28 18:54:58 +0300644 if (!mac_pton(buf, mac))
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900645 return -EINVAL;
646
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900647 chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
648 if (!chip->pch_phub_extrom_base_address)
649 return -ENOMEM;
650
Alexander Steina246b972014-03-05 10:44:57 +0100651 ret = pch_phub_write_gbe_mac_addr(chip, mac);
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900652 pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
Alexander Steina246b972014-03-05 10:44:57 +0100653 if (ret)
654 return ret;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900655
656 return count;
657}
658
659static DEVICE_ATTR(pch_mac, S_IRUGO | S_IWUSR, show_pch_mac, store_pch_mac);
660
Bhumika Goyal57daedf2017-08-02 14:40:06 +0530661static const struct bin_attribute pch_bin_attr = {
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900662 .attr = {
663 .name = "pch_firmware",
664 .mode = S_IRUGO | S_IWUSR,
665 },
666 .size = PCH_PHUB_OROM_SIZE + 1,
667 .read = pch_phub_bin_read,
668 .write = pch_phub_bin_write,
669};
670
Bill Pemberton80c8ae22012-11-19 13:23:05 -0500671static int pch_phub_probe(struct pci_dev *pdev,
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900672 const struct pci_device_id *id)
673{
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900674 int ret;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900675 struct pch_phub_reg *chip;
676
677 chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL);
678 if (chip == NULL)
679 return -ENOMEM;
680
681 ret = pci_enable_device(pdev);
682 if (ret) {
683 dev_err(&pdev->dev,
684 "%s : pci_enable_device FAILED(ret=%d)", __func__, ret);
685 goto err_pci_enable_dev;
686 }
687 dev_dbg(&pdev->dev, "%s : pci_enable_device returns %d\n", __func__,
688 ret);
689
690 ret = pci_request_regions(pdev, KBUILD_MODNAME);
691 if (ret) {
692 dev_err(&pdev->dev,
693 "%s : pci_request_regions FAILED(ret=%d)", __func__, ret);
694 goto err_req_regions;
695 }
696 dev_dbg(&pdev->dev, "%s : "
697 "pci_request_regions returns %d\n", __func__, ret);
698
699 chip->pch_phub_base_address = pci_iomap(pdev, 1, 0);
700
701
Devendra Naga73ac0e92012-07-29 17:08:29 +0545702 if (chip->pch_phub_base_address == NULL) {
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900703 dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__);
704 ret = -ENOMEM;
705 goto err_pci_iomap;
706 }
707 dev_dbg(&pdev->dev, "%s : pci_iomap SUCCESS and value "
Greg Kroah-Hartmanda0d7f92010-09-01 18:06:09 -0700708 "in pch_phub_base_address variable is %p\n", __func__,
709 chip->pch_phub_base_address);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900710
Tomoya MORINAGA9914a0d2011-11-11 10:12:17 +0900711 chip->pdev = pdev; /* Save pci device struct */
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900712
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900713 if (id->driver_data == 1) { /* EG20T PCH */
Alexander Stein2b934c62011-07-25 17:11:54 -0700714 const char *board_name;
Zubair Lutfullah Kakakhel549ce8f2016-08-12 12:48:52 +0100715 unsigned int prefetch = 0x000affaa;
716
717 if (pdev->dev.of_node)
718 of_property_read_u32(pdev->dev.of_node,
719 "intel,eg20t-prefetch",
720 &prefetch);
Alexander Stein2b934c62011-07-25 17:11:54 -0700721
Wei Yongjun29ddae22013-06-04 22:44:27 +0800722 ret = sysfs_create_file(&pdev->dev.kobj,
723 &dev_attr_pch_mac.attr);
724 if (ret)
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +0900725 goto err_sysfs_create;
726
Wei Yongjun29ddae22013-06-04 22:44:27 +0800727 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
728 if (ret)
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +0900729 goto exit_bin_attr;
730
731 pch_phub_read_modify_write_reg(chip,
732 (unsigned int)CLKCFG_REG_OFFSET,
733 CLKCFG_CAN_50MHZ,
734 CLKCFG_CANCLK_MASK);
735
Denis Turischev6ae705b2011-03-10 15:14:00 +0200736 /* quirk for CM-iTC board */
Alexander Stein2b934c62011-07-25 17:11:54 -0700737 board_name = dmi_get_system_info(DMI_BOARD_NAME);
738 if (board_name && strstr(board_name, "CM-iTC"))
Denis Turischev6ae705b2011-03-10 15:14:00 +0200739 pch_phub_read_modify_write_reg(chip,
740 (unsigned int)CLKCFG_REG_OFFSET,
741 CLKCFG_UART_48MHZ | CLKCFG_BAUDDIV |
742 CLKCFG_PLL2VCO | CLKCFG_UARTCLKSEL,
743 CLKCFG_UART_MASK);
744
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +0900745 /* set the prefech value */
Zubair Lutfullah Kakakhel549ce8f2016-08-12 12:48:52 +0100746 iowrite32(prefetch, chip->pch_phub_base_address + 0x14);
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +0900747 /* set the interrupt delay value */
748 iowrite32(0x25, chip->pch_phub_base_address + 0x44);
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900749 chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T;
750 chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T;
Zubair Lutfullah Kakakhelbed3d7b2016-08-12 12:48:53 +0100751
752 /* quirk for MIPS Boston platform */
753 if (pdev->dev.of_node) {
754 if (of_machine_is_compatible("img,boston")) {
755 pch_phub_read_modify_write_reg(chip,
756 (unsigned int)CLKCFG_REG_OFFSET,
757 CLKCFG_UART_25MHZ,
758 CLKCFG_UART_MASK);
759 }
760 }
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900761 } else if (id->driver_data == 2) { /* ML7213 IOH */
Wei Yongjun29ddae22013-06-04 22:44:27 +0800762 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
763 if (ret)
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +0900764 goto err_sysfs_create;
765 /* set the prefech value
766 * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a
767 * Device4(SDIO #0,1,2):f
768 * Device6(SATA 2):f
769 * Device8(USB OHCI #0/ USB EHCI #0):a
770 */
771 iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14);
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900772 chip->pch_opt_rom_start_address =\
773 PCH_PHUB_ROM_START_ADDR_ML7213;
774 } else if (id->driver_data == 3) { /* ML7223 IOH Bus-m*/
775 /* set the prefech value
776 * Device8(GbE)
777 */
778 iowrite32(0x000a0000, chip->pch_phub_base_address + 0x14);
Tomoya MORINAGA20ae6d02011-06-17 10:13:26 +0900779 /* set the interrupt delay value */
780 iowrite32(0x25, chip->pch_phub_base_address + 0x140);
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900781 chip->pch_opt_rom_start_address =\
782 PCH_PHUB_ROM_START_ADDR_ML7223;
783 chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223;
784 } else if (id->driver_data == 4) { /* ML7223 IOH Bus-n*/
Wei Yongjun29ddae22013-06-04 22:44:27 +0800785 ret = sysfs_create_file(&pdev->dev.kobj,
786 &dev_attr_pch_mac.attr);
787 if (ret)
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900788 goto err_sysfs_create;
Wei Yongjun29ddae22013-06-04 22:44:27 +0800789 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
790 if (ret)
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900791 goto exit_bin_attr;
792 /* set the prefech value
793 * Device2(USB OHCI #0,1,2,3/ USB EHCI #0):a
794 * Device4(SDIO #0,1):f
795 * Device6(SATA 2):f
796 */
797 iowrite32(0x0000ffa0, chip->pch_phub_base_address + 0x14);
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900798 chip->pch_opt_rom_start_address =\
799 PCH_PHUB_ROM_START_ADDR_ML7223;
800 chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223;
Tomoya MORINAGA584ad002011-10-28 09:33:13 +0900801 } else if (id->driver_data == 5) { /* ML7831 */
Wei Yongjun29ddae22013-06-04 22:44:27 +0800802 ret = sysfs_create_file(&pdev->dev.kobj,
803 &dev_attr_pch_mac.attr);
804 if (ret)
Tomoya MORINAGA584ad002011-10-28 09:33:13 +0900805 goto err_sysfs_create;
806
Wei Yongjun29ddae22013-06-04 22:44:27 +0800807 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
808 if (ret)
Tomoya MORINAGA584ad002011-10-28 09:33:13 +0900809 goto exit_bin_attr;
810
811 /* set the prefech value */
812 iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14);
813 /* set the interrupt delay value */
814 iowrite32(0x25, chip->pch_phub_base_address + 0x44);
815 chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T;
816 chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T;
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +0900817 }
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900818
819 chip->ioh_type = id->driver_data;
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900820 pci_set_drvdata(pdev, chip);
821
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900822 return 0;
823exit_bin_attr:
824 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
825
826err_sysfs_create:
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900827 pci_iounmap(pdev, chip->pch_phub_base_address);
828err_pci_iomap:
829 pci_release_regions(pdev);
830err_req_regions:
831 pci_disable_device(pdev);
832err_pci_enable_dev:
833 kfree(chip);
834 dev_err(&pdev->dev, "%s returns %d\n", __func__, ret);
835 return ret;
836}
837
Bill Pemberton486a5c22012-11-19 13:26:02 -0500838static void pch_phub_remove(struct pci_dev *pdev)
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900839{
840 struct pch_phub_reg *chip = pci_get_drvdata(pdev);
841
842 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
843 sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900844 pci_iounmap(pdev, chip->pch_phub_base_address);
845 pci_release_regions(pdev);
846 pci_disable_device(pdev);
847 kfree(chip);
848}
849
850#ifdef CONFIG_PM
851
852static int pch_phub_suspend(struct pci_dev *pdev, pm_message_t state)
853{
854 int ret;
855
856 pch_phub_save_reg_conf(pdev);
857 ret = pci_save_state(pdev);
858 if (ret) {
859 dev_err(&pdev->dev,
860 " %s -pci_save_state returns %d\n", __func__, ret);
861 return ret;
862 }
863 pci_enable_wake(pdev, PCI_D3hot, 0);
864 pci_disable_device(pdev);
865 pci_set_power_state(pdev, pci_choose_state(pdev, state));
866
867 return 0;
868}
869
870static int pch_phub_resume(struct pci_dev *pdev)
871{
872 int ret;
873
874 pci_set_power_state(pdev, PCI_D0);
875 pci_restore_state(pdev);
876 ret = pci_enable_device(pdev);
877 if (ret) {
878 dev_err(&pdev->dev,
879 "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
880 return ret;
881 }
882
883 pci_enable_wake(pdev, PCI_D3hot, 0);
884 pch_phub_restore_reg_conf(pdev);
885
886 return 0;
887}
888#else
889#define pch_phub_suspend NULL
890#define pch_phub_resume NULL
891#endif /* CONFIG_PM */
892
Arvind Yadave3b9c5c2017-07-30 10:56:34 +0530893static const struct pci_device_id pch_phub_pcidev_id[] = {
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +0900894 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, },
895 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, },
Tomoya MORINAGA275640b2011-05-12 13:12:36 +0900896 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_mPHUB), 3, },
897 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_nPHUB), 4, },
Tomoya MORINAGA584ad002011-10-28 09:33:13 +0900898 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7831_PHUB), 5, },
Tomoya MORINAGAc47dda72010-12-22 21:04:11 +0900899 { }
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900900};
Axel Linb2595142011-03-22 16:34:02 -0700901MODULE_DEVICE_TABLE(pci, pch_phub_pcidev_id);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900902
903static struct pci_driver pch_phub_driver = {
904 .name = "pch_phub",
905 .id_table = pch_phub_pcidev_id,
906 .probe = pch_phub_probe,
Bill Pemberton2d6bed92012-11-19 13:21:23 -0500907 .remove = pch_phub_remove,
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900908 .suspend = pch_phub_suspend,
909 .resume = pch_phub_resume
910};
911
Devendra Nagacfeb2852012-07-29 17:08:30 +0545912module_pci_driver(pch_phub_driver);
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900913
Tomoya MORINAGA7f2732c2011-10-28 09:33:14 +0900914MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7223) PHUB");
Masayuki Ohtakcf4ece52010-09-01 21:16:30 +0900915MODULE_LICENSE("GPL");