pch_phub.c 28 KB

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