pch_phub.c 28 KB

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