pch_phub.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. /*
  2. * Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
  3. *
  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. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/types.h>
  20. #include <linux/fs.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/string.h>
  23. #include <linux/pci.h>
  24. #include <linux/io.h>
  25. #include <linux/delay.h>
  26. #include <linux/mutex.h>
  27. #include <linux/if_ether.h>
  28. #include <linux/ctype.h>
  29. #include <linux/dmi.h>
  30. #define PHUB_STATUS 0x00 /* Status Register offset */
  31. #define PHUB_CONTROL 0x04 /* Control Register offset */
  32. #define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */
  33. #define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */
  34. #define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */
  35. #define PCH_PHUB_MAC_START_ADDR_EG20T 0x14 /* MAC data area start address
  36. offset */
  37. #define PCH_PHUB_MAC_START_ADDR_ML7223 0x20C /* MAC data area start address
  38. offset */
  39. #define PCH_PHUB_ROM_START_ADDR_EG20T 0x80 /* ROM data area start address offset
  40. (Intel EG20T PCH)*/
  41. #define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address
  42. offset(LAPIS Semicon ML7213)
  43. */
  44. #define PCH_PHUB_ROM_START_ADDR_ML7223 0x400 /* ROM data area start address
  45. offset(LAPIS Semicon ML7223)
  46. */
  47. /* MAX number of INT_REDUCE_CONTROL registers */
  48. #define MAX_NUM_INT_REDUCE_CONTROL_REG 128
  49. #define PCI_DEVICE_ID_PCH1_PHUB 0x8801
  50. #define PCH_MINOR_NOS 1
  51. #define CLKCFG_CAN_50MHZ 0x12000000
  52. #define CLKCFG_CANCLK_MASK 0xFF000000
  53. #define CLKCFG_UART_MASK 0xFFFFFF
  54. /* CM-iTC */
  55. #define CLKCFG_UART_48MHZ (1 << 16)
  56. #define CLKCFG_BAUDDIV (2 << 20)
  57. #define CLKCFG_PLL2VCO (8 << 9)
  58. #define CLKCFG_UARTCLKSEL (1 << 18)
  59. /* Macros for ML7213 */
  60. #define PCI_VENDOR_ID_ROHM 0x10db
  61. #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A
  62. /* Macros for ML7223 */
  63. #define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012 /* for Bus-m */
  64. #define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002 /* for Bus-n */
  65. /* Macros for ML7831 */
  66. #define PCI_DEVICE_ID_ROHM_ML7831_PHUB 0x8801
  67. /* SROM ACCESS Macro */
  68. #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1))
  69. /* Registers address offset */
  70. #define PCH_PHUB_ID_REG 0x0000
  71. #define PCH_PHUB_QUEUE_PRI_VAL_REG 0x0004
  72. #define PCH_PHUB_RC_QUEUE_MAXSIZE_REG 0x0008
  73. #define PCH_PHUB_BRI_QUEUE_MAXSIZE_REG 0x000C
  74. #define PCH_PHUB_COMP_RESP_TIMEOUT_REG 0x0010
  75. #define PCH_PHUB_BUS_SLAVE_CONTROL_REG 0x0014
  76. #define PCH_PHUB_DEADLOCK_AVOID_TYPE_REG 0x0018
  77. #define PCH_PHUB_INTPIN_REG_WPERMIT_REG0 0x0020
  78. #define PCH_PHUB_INTPIN_REG_WPERMIT_REG1 0x0024
  79. #define PCH_PHUB_INTPIN_REG_WPERMIT_REG2 0x0028
  80. #define PCH_PHUB_INTPIN_REG_WPERMIT_REG3 0x002C
  81. #define PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE 0x0040
  82. #define CLKCFG_REG_OFFSET 0x500
  83. #define FUNCSEL_REG_OFFSET 0x508
  84. #define PCH_PHUB_OROM_SIZE 15360
  85. /**
  86. * struct pch_phub_reg - PHUB register structure
  87. * @phub_id_reg: PHUB_ID register val
  88. * @q_pri_val_reg: QUEUE_PRI_VAL register val
  89. * @rc_q_maxsize_reg: RC_QUEUE_MAXSIZE register val
  90. * @bri_q_maxsize_reg: BRI_QUEUE_MAXSIZE register val
  91. * @comp_resp_timeout_reg: COMP_RESP_TIMEOUT register val
  92. * @bus_slave_control_reg: BUS_SLAVE_CONTROL_REG register val
  93. * @deadlock_avoid_type_reg: DEADLOCK_AVOID_TYPE register val
  94. * @intpin_reg_wpermit_reg0: INTPIN_REG_WPERMIT register 0 val
  95. * @intpin_reg_wpermit_reg1: INTPIN_REG_WPERMIT register 1 val
  96. * @intpin_reg_wpermit_reg2: INTPIN_REG_WPERMIT register 2 val
  97. * @intpin_reg_wpermit_reg3: INTPIN_REG_WPERMIT register 3 val
  98. * @int_reduce_control_reg: INT_REDUCE_CONTROL registers val
  99. * @clkcfg_reg: CLK CFG register val
  100. * @funcsel_reg: Function select register value
  101. * @pch_phub_base_address: Register base address
  102. * @pch_phub_extrom_base_address: external rom base address
  103. * @pch_mac_start_address: MAC address area start address
  104. * @pch_opt_rom_start_address: Option ROM start address
  105. * @ioh_type: Save IOH type
  106. * @pdev: pointer to pci device struct
  107. */
  108. struct pch_phub_reg {
  109. u32 phub_id_reg;
  110. u32 q_pri_val_reg;
  111. u32 rc_q_maxsize_reg;
  112. u32 bri_q_maxsize_reg;
  113. u32 comp_resp_timeout_reg;
  114. u32 bus_slave_control_reg;
  115. u32 deadlock_avoid_type_reg;
  116. u32 intpin_reg_wpermit_reg0;
  117. u32 intpin_reg_wpermit_reg1;
  118. u32 intpin_reg_wpermit_reg2;
  119. u32 intpin_reg_wpermit_reg3;
  120. u32 int_reduce_control_reg[MAX_NUM_INT_REDUCE_CONTROL_REG];
  121. u32 clkcfg_reg;
  122. u32 funcsel_reg;
  123. void __iomem *pch_phub_base_address;
  124. void __iomem *pch_phub_extrom_base_address;
  125. u32 pch_mac_start_address;
  126. u32 pch_opt_rom_start_address;
  127. int ioh_type;
  128. struct pci_dev *pdev;
  129. };
  130. /* SROM SPEC for MAC address assignment offset */
  131. static const int pch_phub_mac_offset[ETH_ALEN] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa};
  132. static DEFINE_MUTEX(pch_phub_mutex);
  133. /**
  134. * pch_phub_read_modify_write_reg() - Reading modifying and writing register
  135. * @reg_addr_offset: Register offset address value.
  136. * @data: Writing value.
  137. * @mask: Mask value.
  138. */
  139. static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip,
  140. unsigned int reg_addr_offset,
  141. unsigned int data, unsigned int mask)
  142. {
  143. void __iomem *reg_addr = chip->pch_phub_base_address + reg_addr_offset;
  144. iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr);
  145. }
  146. #ifdef CONFIG_PM
  147. /* pch_phub_save_reg_conf - saves register configuration */
  148. static void pch_phub_save_reg_conf(struct pci_dev *pdev)
  149. {
  150. unsigned int i;
  151. struct pch_phub_reg *chip = pci_get_drvdata(pdev);
  152. void __iomem *p = chip->pch_phub_base_address;
  153. chip->phub_id_reg = ioread32(p + PCH_PHUB_ID_REG);
  154. chip->q_pri_val_reg = ioread32(p + PCH_PHUB_QUEUE_PRI_VAL_REG);
  155. chip->rc_q_maxsize_reg = ioread32(p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG);
  156. chip->bri_q_maxsize_reg = ioread32(p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG);
  157. chip->comp_resp_timeout_reg =
  158. ioread32(p + PCH_PHUB_COMP_RESP_TIMEOUT_REG);
  159. chip->bus_slave_control_reg =
  160. ioread32(p + PCH_PHUB_BUS_SLAVE_CONTROL_REG);
  161. chip->deadlock_avoid_type_reg =
  162. ioread32(p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG);
  163. chip->intpin_reg_wpermit_reg0 =
  164. ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0);
  165. chip->intpin_reg_wpermit_reg1 =
  166. ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1);
  167. chip->intpin_reg_wpermit_reg2 =
  168. ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2);
  169. chip->intpin_reg_wpermit_reg3 =
  170. ioread32(p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3);
  171. dev_dbg(&pdev->dev, "%s : "
  172. "chip->phub_id_reg=%x, "
  173. "chip->q_pri_val_reg=%x, "
  174. "chip->rc_q_maxsize_reg=%x, "
  175. "chip->bri_q_maxsize_reg=%x, "
  176. "chip->comp_resp_timeout_reg=%x, "
  177. "chip->bus_slave_control_reg=%x, "
  178. "chip->deadlock_avoid_type_reg=%x, "
  179. "chip->intpin_reg_wpermit_reg0=%x, "
  180. "chip->intpin_reg_wpermit_reg1=%x, "
  181. "chip->intpin_reg_wpermit_reg2=%x, "
  182. "chip->intpin_reg_wpermit_reg3=%x\n", __func__,
  183. chip->phub_id_reg,
  184. chip->q_pri_val_reg,
  185. chip->rc_q_maxsize_reg,
  186. chip->bri_q_maxsize_reg,
  187. chip->comp_resp_timeout_reg,
  188. chip->bus_slave_control_reg,
  189. chip->deadlock_avoid_type_reg,
  190. chip->intpin_reg_wpermit_reg0,
  191. chip->intpin_reg_wpermit_reg1,
  192. chip->intpin_reg_wpermit_reg2,
  193. chip->intpin_reg_wpermit_reg3);
  194. for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) {
  195. chip->int_reduce_control_reg[i] =
  196. ioread32(p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i);
  197. dev_dbg(&pdev->dev, "%s : "
  198. "chip->int_reduce_control_reg[%d]=%x\n",
  199. __func__, i, chip->int_reduce_control_reg[i]);
  200. }
  201. chip->clkcfg_reg = ioread32(p + CLKCFG_REG_OFFSET);
  202. if ((chip->ioh_type == 2) || (chip->ioh_type == 4))
  203. chip->funcsel_reg = ioread32(p + FUNCSEL_REG_OFFSET);
  204. }
  205. /* pch_phub_restore_reg_conf - restore register configuration */
  206. static void pch_phub_restore_reg_conf(struct pci_dev *pdev)
  207. {
  208. unsigned int i;
  209. struct pch_phub_reg *chip = pci_get_drvdata(pdev);
  210. void __iomem *p;
  211. p = chip->pch_phub_base_address;
  212. iowrite32(chip->phub_id_reg, p + PCH_PHUB_ID_REG);
  213. iowrite32(chip->q_pri_val_reg, p + PCH_PHUB_QUEUE_PRI_VAL_REG);
  214. iowrite32(chip->rc_q_maxsize_reg, p + PCH_PHUB_RC_QUEUE_MAXSIZE_REG);
  215. iowrite32(chip->bri_q_maxsize_reg, p + PCH_PHUB_BRI_QUEUE_MAXSIZE_REG);
  216. iowrite32(chip->comp_resp_timeout_reg,
  217. p + PCH_PHUB_COMP_RESP_TIMEOUT_REG);
  218. iowrite32(chip->bus_slave_control_reg,
  219. p + PCH_PHUB_BUS_SLAVE_CONTROL_REG);
  220. iowrite32(chip->deadlock_avoid_type_reg,
  221. p + PCH_PHUB_DEADLOCK_AVOID_TYPE_REG);
  222. iowrite32(chip->intpin_reg_wpermit_reg0,
  223. p + PCH_PHUB_INTPIN_REG_WPERMIT_REG0);
  224. iowrite32(chip->intpin_reg_wpermit_reg1,
  225. p + PCH_PHUB_INTPIN_REG_WPERMIT_REG1);
  226. iowrite32(chip->intpin_reg_wpermit_reg2,
  227. p + PCH_PHUB_INTPIN_REG_WPERMIT_REG2);
  228. iowrite32(chip->intpin_reg_wpermit_reg3,
  229. p + PCH_PHUB_INTPIN_REG_WPERMIT_REG3);
  230. dev_dbg(&pdev->dev, "%s : "
  231. "chip->phub_id_reg=%x, "
  232. "chip->q_pri_val_reg=%x, "
  233. "chip->rc_q_maxsize_reg=%x, "
  234. "chip->bri_q_maxsize_reg=%x, "
  235. "chip->comp_resp_timeout_reg=%x, "
  236. "chip->bus_slave_control_reg=%x, "
  237. "chip->deadlock_avoid_type_reg=%x, "
  238. "chip->intpin_reg_wpermit_reg0=%x, "
  239. "chip->intpin_reg_wpermit_reg1=%x, "
  240. "chip->intpin_reg_wpermit_reg2=%x, "
  241. "chip->intpin_reg_wpermit_reg3=%x\n", __func__,
  242. chip->phub_id_reg,
  243. chip->q_pri_val_reg,
  244. chip->rc_q_maxsize_reg,
  245. chip->bri_q_maxsize_reg,
  246. chip->comp_resp_timeout_reg,
  247. chip->bus_slave_control_reg,
  248. chip->deadlock_avoid_type_reg,
  249. chip->intpin_reg_wpermit_reg0,
  250. chip->intpin_reg_wpermit_reg1,
  251. chip->intpin_reg_wpermit_reg2,
  252. chip->intpin_reg_wpermit_reg3);
  253. for (i = 0; i < MAX_NUM_INT_REDUCE_CONTROL_REG; i++) {
  254. iowrite32(chip->int_reduce_control_reg[i],
  255. p + PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE + 4 * i);
  256. dev_dbg(&pdev->dev, "%s : "
  257. "chip->int_reduce_control_reg[%d]=%x\n",
  258. __func__, i, chip->int_reduce_control_reg[i]);
  259. }
  260. iowrite32(chip->clkcfg_reg, p + CLKCFG_REG_OFFSET);
  261. if ((chip->ioh_type == 2) || (chip->ioh_type == 4))
  262. iowrite32(chip->funcsel_reg, p + FUNCSEL_REG_OFFSET);
  263. }
  264. #endif
  265. /**
  266. * pch_phub_read_serial_rom() - Reading Serial ROM
  267. * @offset_address: Serial ROM offset address to read.
  268. * @data: Read buffer for specified Serial ROM value.
  269. */
  270. static void pch_phub_read_serial_rom(struct pch_phub_reg *chip,
  271. unsigned int offset_address, u8 *data)
  272. {
  273. void __iomem *mem_addr = chip->pch_phub_extrom_base_address +
  274. offset_address;
  275. *data = ioread8(mem_addr);
  276. }
  277. /**
  278. * pch_phub_write_serial_rom() - Writing Serial ROM
  279. * @offset_address: Serial ROM offset address.
  280. * @data: Serial ROM value to write.
  281. */
  282. static int pch_phub_write_serial_rom(struct pch_phub_reg *chip,
  283. unsigned int offset_address, u8 data)
  284. {
  285. void __iomem *mem_addr = chip->pch_phub_extrom_base_address +
  286. (offset_address & PCH_WORD_ADDR_MASK);
  287. int i;
  288. unsigned int word_data;
  289. unsigned int pos;
  290. unsigned int mask;
  291. pos = (offset_address % 4) * 8;
  292. mask = ~(0xFF << pos);
  293. iowrite32(PCH_PHUB_ROM_WRITE_ENABLE,
  294. chip->pch_phub_extrom_base_address + PHUB_CONTROL);
  295. word_data = ioread32(mem_addr);
  296. iowrite32((word_data & mask) | (u32)data << pos, mem_addr);
  297. i = 0;
  298. while (ioread8(chip->pch_phub_extrom_base_address +
  299. PHUB_STATUS) != 0x00) {
  300. msleep(1);
  301. if (i == PHUB_TIMEOUT)
  302. return -ETIMEDOUT;
  303. i++;
  304. }
  305. iowrite32(PCH_PHUB_ROM_WRITE_DISABLE,
  306. chip->pch_phub_extrom_base_address + PHUB_CONTROL);
  307. return 0;
  308. }
  309. /**
  310. * pch_phub_read_serial_rom_val() - Read Serial ROM value
  311. * @offset_address: Serial ROM address offset value.
  312. * @data: Serial ROM value to read.
  313. */
  314. static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip,
  315. unsigned int offset_address, u8 *data)
  316. {
  317. unsigned int mem_addr;
  318. mem_addr = chip->pch_mac_start_address +
  319. pch_phub_mac_offset[offset_address];
  320. pch_phub_read_serial_rom(chip, mem_addr, data);
  321. }
  322. /**
  323. * pch_phub_write_serial_rom_val() - writing Serial ROM value
  324. * @offset_address: Serial ROM address offset value.
  325. * @data: Serial ROM value.
  326. */
  327. static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip,
  328. unsigned int offset_address, u8 data)
  329. {
  330. int retval;
  331. unsigned int mem_addr;
  332. mem_addr = chip->pch_mac_start_address +
  333. pch_phub_mac_offset[offset_address];
  334. retval = pch_phub_write_serial_rom(chip, mem_addr, data);
  335. return retval;
  336. }
  337. /* pch_phub_gbe_serial_rom_conf - makes Serial ROM header format configuration
  338. * for Gigabit Ethernet MAC address
  339. */
  340. static int pch_phub_gbe_serial_rom_conf(struct pch_phub_reg *chip)
  341. {
  342. int retval;
  343. retval = pch_phub_write_serial_rom(chip, 0x0b, 0xbc);
  344. retval |= pch_phub_write_serial_rom(chip, 0x0a, 0x10);
  345. retval |= pch_phub_write_serial_rom(chip, 0x09, 0x01);
  346. retval |= pch_phub_write_serial_rom(chip, 0x08, 0x02);
  347. retval |= pch_phub_write_serial_rom(chip, 0x0f, 0x00);
  348. retval |= pch_phub_write_serial_rom(chip, 0x0e, 0x00);
  349. retval |= pch_phub_write_serial_rom(chip, 0x0d, 0x00);
  350. retval |= pch_phub_write_serial_rom(chip, 0x0c, 0x80);
  351. retval |= pch_phub_write_serial_rom(chip, 0x13, 0xbc);
  352. retval |= pch_phub_write_serial_rom(chip, 0x12, 0x10);
  353. retval |= pch_phub_write_serial_rom(chip, 0x11, 0x01);
  354. retval |= pch_phub_write_serial_rom(chip, 0x10, 0x18);
  355. retval |= pch_phub_write_serial_rom(chip, 0x1b, 0xbc);
  356. retval |= pch_phub_write_serial_rom(chip, 0x1a, 0x10);
  357. retval |= pch_phub_write_serial_rom(chip, 0x19, 0x01);
  358. retval |= pch_phub_write_serial_rom(chip, 0x18, 0x19);
  359. retval |= pch_phub_write_serial_rom(chip, 0x23, 0xbc);
  360. retval |= pch_phub_write_serial_rom(chip, 0x22, 0x10);
  361. retval |= pch_phub_write_serial_rom(chip, 0x21, 0x01);
  362. retval |= pch_phub_write_serial_rom(chip, 0x20, 0x3a);
  363. retval |= pch_phub_write_serial_rom(chip, 0x27, 0x01);
  364. retval |= pch_phub_write_serial_rom(chip, 0x26, 0x00);
  365. retval |= pch_phub_write_serial_rom(chip, 0x25, 0x00);
  366. retval |= pch_phub_write_serial_rom(chip, 0x24, 0x00);
  367. return retval;
  368. }
  369. /* pch_phub_gbe_serial_rom_conf_mp - makes SerialROM header format configuration
  370. * for Gigabit Ethernet MAC address
  371. */
  372. static int pch_phub_gbe_serial_rom_conf_mp(struct pch_phub_reg *chip)
  373. {
  374. int retval;
  375. u32 offset_addr;
  376. offset_addr = 0x200;
  377. retval = pch_phub_write_serial_rom(chip, 0x03 + offset_addr, 0xbc);
  378. retval |= pch_phub_write_serial_rom(chip, 0x02 + offset_addr, 0x00);
  379. retval |= pch_phub_write_serial_rom(chip, 0x01 + offset_addr, 0x40);
  380. retval |= pch_phub_write_serial_rom(chip, 0x00 + offset_addr, 0x02);
  381. retval |= pch_phub_write_serial_rom(chip, 0x07 + offset_addr, 0x00);
  382. retval |= pch_phub_write_serial_rom(chip, 0x06 + offset_addr, 0x00);
  383. retval |= pch_phub_write_serial_rom(chip, 0x05 + offset_addr, 0x00);
  384. retval |= pch_phub_write_serial_rom(chip, 0x04 + offset_addr, 0x80);
  385. retval |= pch_phub_write_serial_rom(chip, 0x0b + offset_addr, 0xbc);
  386. retval |= pch_phub_write_serial_rom(chip, 0x0a + offset_addr, 0x00);
  387. retval |= pch_phub_write_serial_rom(chip, 0x09 + offset_addr, 0x40);
  388. retval |= pch_phub_write_serial_rom(chip, 0x08 + offset_addr, 0x18);
  389. retval |= pch_phub_write_serial_rom(chip, 0x13 + offset_addr, 0xbc);
  390. retval |= pch_phub_write_serial_rom(chip, 0x12 + offset_addr, 0x00);
  391. retval |= pch_phub_write_serial_rom(chip, 0x11 + offset_addr, 0x40);
  392. retval |= pch_phub_write_serial_rom(chip, 0x10 + offset_addr, 0x19);
  393. retval |= pch_phub_write_serial_rom(chip, 0x1b + offset_addr, 0xbc);
  394. retval |= pch_phub_write_serial_rom(chip, 0x1a + offset_addr, 0x00);
  395. retval |= pch_phub_write_serial_rom(chip, 0x19 + offset_addr, 0x40);
  396. retval |= pch_phub_write_serial_rom(chip, 0x18 + offset_addr, 0x3a);
  397. retval |= pch_phub_write_serial_rom(chip, 0x1f + offset_addr, 0x01);
  398. retval |= pch_phub_write_serial_rom(chip, 0x1e + offset_addr, 0x00);
  399. retval |= pch_phub_write_serial_rom(chip, 0x1d + offset_addr, 0x00);
  400. retval |= pch_phub_write_serial_rom(chip, 0x1c + offset_addr, 0x00);
  401. return retval;
  402. }
  403. /**
  404. * pch_phub_read_gbe_mac_addr() - Read Gigabit Ethernet MAC address
  405. * @offset_address: Gigabit Ethernet MAC address offset value.
  406. * @data: Buffer of the Gigabit Ethernet MAC address value.
  407. */
  408. static void pch_phub_read_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
  409. {
  410. int i;
  411. for (i = 0; i < ETH_ALEN; i++)
  412. pch_phub_read_serial_rom_val(chip, i, &data[i]);
  413. }
  414. /**
  415. * pch_phub_write_gbe_mac_addr() - Write MAC address
  416. * @offset_address: Gigabit Ethernet MAC address offset value.
  417. * @data: Gigabit Ethernet MAC address value.
  418. */
  419. static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
  420. {
  421. int retval;
  422. int i;
  423. if ((chip->ioh_type == 1) || (chip->ioh_type == 5)) /* EG20T or ML7831*/
  424. retval = pch_phub_gbe_serial_rom_conf(chip);
  425. else /* ML7223 */
  426. retval = pch_phub_gbe_serial_rom_conf_mp(chip);
  427. if (retval)
  428. return retval;
  429. for (i = 0; i < ETH_ALEN; i++) {
  430. retval = pch_phub_write_serial_rom_val(chip, i, data[i]);
  431. if (retval)
  432. return retval;
  433. }
  434. return retval;
  435. }
  436. static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj,
  437. struct bin_attribute *attr, char *buf,
  438. loff_t off, size_t count)
  439. {
  440. unsigned int rom_signature;
  441. unsigned char rom_length;
  442. unsigned int tmp;
  443. unsigned int addr_offset;
  444. unsigned int orom_size;
  445. int ret;
  446. int err;
  447. ssize_t rom_size;
  448. struct pch_phub_reg *chip =
  449. dev_get_drvdata(container_of(kobj, struct device, kobj));
  450. ret = mutex_lock_interruptible(&pch_phub_mutex);
  451. if (ret) {
  452. err = -ERESTARTSYS;
  453. goto return_err_nomutex;
  454. }
  455. /* Get Rom signature */
  456. chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
  457. if (!chip->pch_phub_extrom_base_address)
  458. goto exrom_map_err;
  459. pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address,
  460. (unsigned char *)&rom_signature);
  461. rom_signature &= 0xff;
  462. pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address + 1,
  463. (unsigned char *)&tmp);
  464. rom_signature |= (tmp & 0xff) << 8;
  465. if (rom_signature == 0xAA55) {
  466. pch_phub_read_serial_rom(chip,
  467. chip->pch_opt_rom_start_address + 2,
  468. &rom_length);
  469. orom_size = rom_length * 512;
  470. if (orom_size < off) {
  471. addr_offset = 0;
  472. goto return_ok;
  473. }
  474. if (orom_size < count) {
  475. addr_offset = 0;
  476. goto return_ok;
  477. }
  478. for (addr_offset = 0; addr_offset < count; addr_offset++) {
  479. pch_phub_read_serial_rom(chip,
  480. chip->pch_opt_rom_start_address + addr_offset + off,
  481. &buf[addr_offset]);
  482. }
  483. } else {
  484. err = -ENODATA;
  485. goto return_err;
  486. }
  487. return_ok:
  488. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  489. mutex_unlock(&pch_phub_mutex);
  490. return addr_offset;
  491. return_err:
  492. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  493. exrom_map_err:
  494. mutex_unlock(&pch_phub_mutex);
  495. return_err_nomutex:
  496. return err;
  497. }
  498. static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj,
  499. struct bin_attribute *attr,
  500. char *buf, loff_t off, size_t count)
  501. {
  502. int err;
  503. unsigned int addr_offset;
  504. int ret;
  505. ssize_t rom_size;
  506. struct pch_phub_reg *chip =
  507. dev_get_drvdata(container_of(kobj, struct device, kobj));
  508. ret = mutex_lock_interruptible(&pch_phub_mutex);
  509. if (ret)
  510. return -ERESTARTSYS;
  511. if (off > PCH_PHUB_OROM_SIZE) {
  512. addr_offset = 0;
  513. goto return_ok;
  514. }
  515. if (count > PCH_PHUB_OROM_SIZE) {
  516. addr_offset = 0;
  517. goto return_ok;
  518. }
  519. chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
  520. if (!chip->pch_phub_extrom_base_address) {
  521. err = -ENOMEM;
  522. goto exrom_map_err;
  523. }
  524. for (addr_offset = 0; addr_offset < count; addr_offset++) {
  525. if (PCH_PHUB_OROM_SIZE < off + addr_offset)
  526. goto return_ok;
  527. ret = pch_phub_write_serial_rom(chip,
  528. chip->pch_opt_rom_start_address + addr_offset + off,
  529. buf[addr_offset]);
  530. if (ret) {
  531. err = ret;
  532. goto return_err;
  533. }
  534. }
  535. return_ok:
  536. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  537. mutex_unlock(&pch_phub_mutex);
  538. return addr_offset;
  539. return_err:
  540. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  541. exrom_map_err:
  542. mutex_unlock(&pch_phub_mutex);
  543. return err;
  544. }
  545. static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr,
  546. char *buf)
  547. {
  548. u8 mac[8];
  549. struct pch_phub_reg *chip = dev_get_drvdata(dev);
  550. ssize_t rom_size;
  551. chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
  552. if (!chip->pch_phub_extrom_base_address)
  553. return -ENOMEM;
  554. pch_phub_read_gbe_mac_addr(chip, mac);
  555. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  556. return sprintf(buf, "%pM\n", mac);
  557. }
  558. static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr,
  559. const char *buf, size_t count)
  560. {
  561. u8 mac[ETH_ALEN];
  562. ssize_t rom_size;
  563. struct pch_phub_reg *chip = dev_get_drvdata(dev);
  564. int ret;
  565. if (!mac_pton(buf, mac))
  566. return -EINVAL;
  567. chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
  568. if (!chip->pch_phub_extrom_base_address)
  569. return -ENOMEM;
  570. ret = pch_phub_write_gbe_mac_addr(chip, mac);
  571. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  572. if (ret)
  573. return ret;
  574. return count;
  575. }
  576. static DEVICE_ATTR(pch_mac, S_IRUGO | S_IWUSR, show_pch_mac, store_pch_mac);
  577. static struct bin_attribute pch_bin_attr = {
  578. .attr = {
  579. .name = "pch_firmware",
  580. .mode = S_IRUGO | S_IWUSR,
  581. },
  582. .size = PCH_PHUB_OROM_SIZE + 1,
  583. .read = pch_phub_bin_read,
  584. .write = pch_phub_bin_write,
  585. };
  586. static int pch_phub_probe(struct pci_dev *pdev,
  587. const struct pci_device_id *id)
  588. {
  589. int ret;
  590. struct pch_phub_reg *chip;
  591. chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL);
  592. if (chip == NULL)
  593. return -ENOMEM;
  594. ret = pci_enable_device(pdev);
  595. if (ret) {
  596. dev_err(&pdev->dev,
  597. "%s : pci_enable_device FAILED(ret=%d)", __func__, ret);
  598. goto err_pci_enable_dev;
  599. }
  600. dev_dbg(&pdev->dev, "%s : pci_enable_device returns %d\n", __func__,
  601. ret);
  602. ret = pci_request_regions(pdev, KBUILD_MODNAME);
  603. if (ret) {
  604. dev_err(&pdev->dev,
  605. "%s : pci_request_regions FAILED(ret=%d)", __func__, ret);
  606. goto err_req_regions;
  607. }
  608. dev_dbg(&pdev->dev, "%s : "
  609. "pci_request_regions returns %d\n", __func__, ret);
  610. chip->pch_phub_base_address = pci_iomap(pdev, 1, 0);
  611. if (chip->pch_phub_base_address == NULL) {
  612. dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__);
  613. ret = -ENOMEM;
  614. goto err_pci_iomap;
  615. }
  616. dev_dbg(&pdev->dev, "%s : pci_iomap SUCCESS and value "
  617. "in pch_phub_base_address variable is %p\n", __func__,
  618. chip->pch_phub_base_address);
  619. chip->pdev = pdev; /* Save pci device struct */
  620. if (id->driver_data == 1) { /* EG20T PCH */
  621. const char *board_name;
  622. ret = sysfs_create_file(&pdev->dev.kobj,
  623. &dev_attr_pch_mac.attr);
  624. if (ret)
  625. goto err_sysfs_create;
  626. ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  627. if (ret)
  628. goto exit_bin_attr;
  629. pch_phub_read_modify_write_reg(chip,
  630. (unsigned int)CLKCFG_REG_OFFSET,
  631. CLKCFG_CAN_50MHZ,
  632. CLKCFG_CANCLK_MASK);
  633. /* quirk for CM-iTC board */
  634. board_name = dmi_get_system_info(DMI_BOARD_NAME);
  635. if (board_name && strstr(board_name, "CM-iTC"))
  636. pch_phub_read_modify_write_reg(chip,
  637. (unsigned int)CLKCFG_REG_OFFSET,
  638. CLKCFG_UART_48MHZ | CLKCFG_BAUDDIV |
  639. CLKCFG_PLL2VCO | CLKCFG_UARTCLKSEL,
  640. CLKCFG_UART_MASK);
  641. /* set the prefech value */
  642. iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14);
  643. /* set the interrupt delay value */
  644. iowrite32(0x25, chip->pch_phub_base_address + 0x44);
  645. chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T;
  646. chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T;
  647. } else if (id->driver_data == 2) { /* ML7213 IOH */
  648. ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  649. if (ret)
  650. goto err_sysfs_create;
  651. /* set the prefech value
  652. * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a
  653. * Device4(SDIO #0,1,2):f
  654. * Device6(SATA 2):f
  655. * Device8(USB OHCI #0/ USB EHCI #0):a
  656. */
  657. iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14);
  658. chip->pch_opt_rom_start_address =\
  659. PCH_PHUB_ROM_START_ADDR_ML7213;
  660. } else if (id->driver_data == 3) { /* ML7223 IOH Bus-m*/
  661. /* set the prefech value
  662. * Device8(GbE)
  663. */
  664. iowrite32(0x000a0000, chip->pch_phub_base_address + 0x14);
  665. /* set the interrupt delay value */
  666. iowrite32(0x25, chip->pch_phub_base_address + 0x140);
  667. chip->pch_opt_rom_start_address =\
  668. PCH_PHUB_ROM_START_ADDR_ML7223;
  669. chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223;
  670. } else if (id->driver_data == 4) { /* ML7223 IOH Bus-n*/
  671. ret = sysfs_create_file(&pdev->dev.kobj,
  672. &dev_attr_pch_mac.attr);
  673. if (ret)
  674. goto err_sysfs_create;
  675. ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  676. if (ret)
  677. goto exit_bin_attr;
  678. /* set the prefech value
  679. * Device2(USB OHCI #0,1,2,3/ USB EHCI #0):a
  680. * Device4(SDIO #0,1):f
  681. * Device6(SATA 2):f
  682. */
  683. iowrite32(0x0000ffa0, chip->pch_phub_base_address + 0x14);
  684. chip->pch_opt_rom_start_address =\
  685. PCH_PHUB_ROM_START_ADDR_ML7223;
  686. chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223;
  687. } else if (id->driver_data == 5) { /* ML7831 */
  688. ret = sysfs_create_file(&pdev->dev.kobj,
  689. &dev_attr_pch_mac.attr);
  690. if (ret)
  691. goto err_sysfs_create;
  692. ret = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  693. if (ret)
  694. goto exit_bin_attr;
  695. /* set the prefech value */
  696. iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14);
  697. /* set the interrupt delay value */
  698. iowrite32(0x25, chip->pch_phub_base_address + 0x44);
  699. chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T;
  700. chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T;
  701. }
  702. chip->ioh_type = id->driver_data;
  703. pci_set_drvdata(pdev, chip);
  704. return 0;
  705. exit_bin_attr:
  706. sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
  707. err_sysfs_create:
  708. pci_iounmap(pdev, chip->pch_phub_base_address);
  709. err_pci_iomap:
  710. pci_release_regions(pdev);
  711. err_req_regions:
  712. pci_disable_device(pdev);
  713. err_pci_enable_dev:
  714. kfree(chip);
  715. dev_err(&pdev->dev, "%s returns %d\n", __func__, ret);
  716. return ret;
  717. }
  718. static void pch_phub_remove(struct pci_dev *pdev)
  719. {
  720. struct pch_phub_reg *chip = pci_get_drvdata(pdev);
  721. sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
  722. sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  723. pci_iounmap(pdev, chip->pch_phub_base_address);
  724. pci_release_regions(pdev);
  725. pci_disable_device(pdev);
  726. kfree(chip);
  727. }
  728. #ifdef CONFIG_PM
  729. static int pch_phub_suspend(struct pci_dev *pdev, pm_message_t state)
  730. {
  731. int ret;
  732. pch_phub_save_reg_conf(pdev);
  733. ret = pci_save_state(pdev);
  734. if (ret) {
  735. dev_err(&pdev->dev,
  736. " %s -pci_save_state returns %d\n", __func__, ret);
  737. return ret;
  738. }
  739. pci_enable_wake(pdev, PCI_D3hot, 0);
  740. pci_disable_device(pdev);
  741. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  742. return 0;
  743. }
  744. static int pch_phub_resume(struct pci_dev *pdev)
  745. {
  746. int ret;
  747. pci_set_power_state(pdev, PCI_D0);
  748. pci_restore_state(pdev);
  749. ret = pci_enable_device(pdev);
  750. if (ret) {
  751. dev_err(&pdev->dev,
  752. "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
  753. return ret;
  754. }
  755. pci_enable_wake(pdev, PCI_D3hot, 0);
  756. pch_phub_restore_reg_conf(pdev);
  757. return 0;
  758. }
  759. #else
  760. #define pch_phub_suspend NULL
  761. #define pch_phub_resume NULL
  762. #endif /* CONFIG_PM */
  763. static struct pci_device_id pch_phub_pcidev_id[] = {
  764. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, },
  765. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, },
  766. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_mPHUB), 3, },
  767. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_nPHUB), 4, },
  768. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7831_PHUB), 5, },
  769. { }
  770. };
  771. MODULE_DEVICE_TABLE(pci, pch_phub_pcidev_id);
  772. static struct pci_driver pch_phub_driver = {
  773. .name = "pch_phub",
  774. .id_table = pch_phub_pcidev_id,
  775. .probe = pch_phub_probe,
  776. .remove = pch_phub_remove,
  777. .suspend = pch_phub_suspend,
  778. .resume = pch_phub_resume
  779. };
  780. module_pci_driver(pch_phub_driver);
  781. MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semiconductor IOH(ML7213/ML7223) PHUB");
  782. MODULE_LICENSE("GPL");