pch_phub.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /*
  2. * Copyright (C) 2010 OKI 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(OKI SEMICONDUCTOR ML7213)
  43. */
  44. #define PCH_PHUB_ROM_START_ADDR_ML7223 0x400 /* ROM data area start address
  45. offset(OKI SEMICONDUCTOR 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 ML7213 */
  63. #define PCI_VENDOR_ID_ROHM 0x10db
  64. #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A
  65. /* Macros for ML7223 */
  66. #define PCI_DEVICE_ID_ROHM_ML7223_mPHUB 0x8012 /* for Bus-m */
  67. #define PCI_DEVICE_ID_ROHM_ML7223_nPHUB 0x8002 /* for Bus-n */
  68. /* Macros for ML7831 */
  69. #define PCI_DEVICE_ID_ROHM_ML7831_PHUB 0x8801
  70. /* SROM ACCESS Macro */
  71. #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1))
  72. /* Registers address offset */
  73. #define PCH_PHUB_ID_REG 0x0000
  74. #define PCH_PHUB_QUEUE_PRI_VAL_REG 0x0004
  75. #define PCH_PHUB_RC_QUEUE_MAXSIZE_REG 0x0008
  76. #define PCH_PHUB_BRI_QUEUE_MAXSIZE_REG 0x000C
  77. #define PCH_PHUB_COMP_RESP_TIMEOUT_REG 0x0010
  78. #define PCH_PHUB_BUS_SLAVE_CONTROL_REG 0x0014
  79. #define PCH_PHUB_DEADLOCK_AVOID_TYPE_REG 0x0018
  80. #define PCH_PHUB_INTPIN_REG_WPERMIT_REG0 0x0020
  81. #define PCH_PHUB_INTPIN_REG_WPERMIT_REG1 0x0024
  82. #define PCH_PHUB_INTPIN_REG_WPERMIT_REG2 0x0028
  83. #define PCH_PHUB_INTPIN_REG_WPERMIT_REG3 0x002C
  84. #define PCH_PHUB_INT_REDUCE_CONTROL_REG_BASE 0x0040
  85. #define CLKCFG_REG_OFFSET 0x500
  86. #define FUNCSEL_REG_OFFSET 0x508
  87. #define PCH_PHUB_OROM_SIZE 15360
  88. /**
  89. * struct pch_phub_reg - PHUB register structure
  90. * @phub_id_reg: PHUB_ID register val
  91. * @q_pri_val_reg: QUEUE_PRI_VAL register val
  92. * @rc_q_maxsize_reg: RC_QUEUE_MAXSIZE register val
  93. * @bri_q_maxsize_reg: BRI_QUEUE_MAXSIZE register val
  94. * @comp_resp_timeout_reg: COMP_RESP_TIMEOUT register val
  95. * @bus_slave_control_reg: BUS_SLAVE_CONTROL_REG register val
  96. * @deadlock_avoid_type_reg: DEADLOCK_AVOID_TYPE register val
  97. * @intpin_reg_wpermit_reg0: INTPIN_REG_WPERMIT register 0 val
  98. * @intpin_reg_wpermit_reg1: INTPIN_REG_WPERMIT register 1 val
  99. * @intpin_reg_wpermit_reg2: INTPIN_REG_WPERMIT register 2 val
  100. * @intpin_reg_wpermit_reg3: INTPIN_REG_WPERMIT register 3 val
  101. * @int_reduce_control_reg: INT_REDUCE_CONTROL registers val
  102. * @clkcfg_reg: CLK CFG register val
  103. * @funcsel_reg: Function select register value
  104. * @pch_phub_base_address: Register base address
  105. * @pch_phub_extrom_base_address: external rom base address
  106. * @pch_mac_start_address: MAC address area start address
  107. * @pch_opt_rom_start_address: Option ROM start address
  108. * @ioh_type: Save IOH type
  109. * @pdev: pointer to pci device struct
  110. */
  111. struct pch_phub_reg {
  112. u32 phub_id_reg;
  113. u32 q_pri_val_reg;
  114. u32 rc_q_maxsize_reg;
  115. u32 bri_q_maxsize_reg;
  116. u32 comp_resp_timeout_reg;
  117. u32 bus_slave_control_reg;
  118. u32 deadlock_avoid_type_reg;
  119. u32 intpin_reg_wpermit_reg0;
  120. u32 intpin_reg_wpermit_reg1;
  121. u32 intpin_reg_wpermit_reg2;
  122. u32 intpin_reg_wpermit_reg3;
  123. u32 int_reduce_control_reg[MAX_NUM_INT_REDUCE_CONTROL_REG];
  124. u32 clkcfg_reg;
  125. u32 funcsel_reg;
  126. void __iomem *pch_phub_base_address;
  127. void __iomem *pch_phub_extrom_base_address;
  128. u32 pch_mac_start_address;
  129. u32 pch_opt_rom_start_address;
  130. int ioh_type;
  131. struct pci_dev *pdev;
  132. };
  133. /* SROM SPEC for MAC address assignment offset */
  134. static const int pch_phub_mac_offset[ETH_ALEN] = {0x3, 0x2, 0x1, 0x0, 0xb, 0xa};
  135. static DEFINE_MUTEX(pch_phub_mutex);
  136. /**
  137. * pch_phub_read_modify_write_reg() - Reading modifying and writing register
  138. * @reg_addr_offset: Register offset address value.
  139. * @data: Writing value.
  140. * @mask: Mask value.
  141. */
  142. static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip,
  143. unsigned int reg_addr_offset,
  144. unsigned int data, unsigned int mask)
  145. {
  146. void __iomem *reg_addr = chip->pch_phub_base_address + reg_addr_offset;
  147. iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr);
  148. }
  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. /**
  267. * pch_phub_read_serial_rom() - Reading Serial ROM
  268. * @offset_address: Serial ROM offset address to read.
  269. * @data: Read buffer for specified Serial ROM value.
  270. */
  271. static void pch_phub_read_serial_rom(struct pch_phub_reg *chip,
  272. unsigned int offset_address, u8 *data)
  273. {
  274. void __iomem *mem_addr = chip->pch_phub_extrom_base_address +
  275. offset_address;
  276. *data = ioread8(mem_addr);
  277. }
  278. /**
  279. * pch_phub_write_serial_rom() - Writing Serial ROM
  280. * @offset_address: Serial ROM offset address.
  281. * @data: Serial ROM value to write.
  282. */
  283. static int pch_phub_write_serial_rom(struct pch_phub_reg *chip,
  284. unsigned int offset_address, u8 data)
  285. {
  286. void __iomem *mem_addr = chip->pch_phub_extrom_base_address +
  287. (offset_address & PCH_WORD_ADDR_MASK);
  288. int i;
  289. unsigned int word_data;
  290. unsigned int pos;
  291. unsigned int mask;
  292. pos = (offset_address % 4) * 8;
  293. mask = ~(0xFF << pos);
  294. iowrite32(PCH_PHUB_ROM_WRITE_ENABLE,
  295. chip->pch_phub_extrom_base_address + PHUB_CONTROL);
  296. word_data = ioread32(mem_addr);
  297. iowrite32((word_data & mask) | (u32)data << pos, mem_addr);
  298. i = 0;
  299. while (ioread8(chip->pch_phub_extrom_base_address +
  300. PHUB_STATUS) != 0x00) {
  301. msleep(1);
  302. if (i == PHUB_TIMEOUT)
  303. return -ETIMEDOUT;
  304. i++;
  305. }
  306. iowrite32(PCH_PHUB_ROM_WRITE_DISABLE,
  307. chip->pch_phub_extrom_base_address + PHUB_CONTROL);
  308. return 0;
  309. }
  310. /**
  311. * pch_phub_read_serial_rom_val() - Read Serial ROM value
  312. * @offset_address: Serial ROM address offset value.
  313. * @data: Serial ROM value to read.
  314. */
  315. static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip,
  316. unsigned int offset_address, u8 *data)
  317. {
  318. unsigned int mem_addr;
  319. mem_addr = chip->pch_mac_start_address +
  320. pch_phub_mac_offset[offset_address];
  321. pch_phub_read_serial_rom(chip, mem_addr, data);
  322. }
  323. /**
  324. * pch_phub_write_serial_rom_val() - writing Serial ROM value
  325. * @offset_address: Serial ROM address offset value.
  326. * @data: Serial ROM value.
  327. */
  328. static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip,
  329. unsigned int offset_address, u8 data)
  330. {
  331. int retval;
  332. unsigned int mem_addr;
  333. mem_addr = chip->pch_mac_start_address +
  334. pch_phub_mac_offset[offset_address];
  335. retval = pch_phub_write_serial_rom(chip, mem_addr, data);
  336. return retval;
  337. }
  338. /* pch_phub_gbe_serial_rom_conf - makes Serial ROM header format configuration
  339. * for Gigabit Ethernet MAC address
  340. */
  341. static int pch_phub_gbe_serial_rom_conf(struct pch_phub_reg *chip)
  342. {
  343. int retval;
  344. retval = pch_phub_write_serial_rom(chip, 0x0b, 0xbc);
  345. retval |= pch_phub_write_serial_rom(chip, 0x0a, 0x10);
  346. retval |= pch_phub_write_serial_rom(chip, 0x09, 0x01);
  347. retval |= pch_phub_write_serial_rom(chip, 0x08, 0x02);
  348. retval |= pch_phub_write_serial_rom(chip, 0x0f, 0x00);
  349. retval |= pch_phub_write_serial_rom(chip, 0x0e, 0x00);
  350. retval |= pch_phub_write_serial_rom(chip, 0x0d, 0x00);
  351. retval |= pch_phub_write_serial_rom(chip, 0x0c, 0x80);
  352. retval |= pch_phub_write_serial_rom(chip, 0x13, 0xbc);
  353. retval |= pch_phub_write_serial_rom(chip, 0x12, 0x10);
  354. retval |= pch_phub_write_serial_rom(chip, 0x11, 0x01);
  355. retval |= pch_phub_write_serial_rom(chip, 0x10, 0x18);
  356. retval |= pch_phub_write_serial_rom(chip, 0x1b, 0xbc);
  357. retval |= pch_phub_write_serial_rom(chip, 0x1a, 0x10);
  358. retval |= pch_phub_write_serial_rom(chip, 0x19, 0x01);
  359. retval |= pch_phub_write_serial_rom(chip, 0x18, 0x19);
  360. retval |= pch_phub_write_serial_rom(chip, 0x23, 0xbc);
  361. retval |= pch_phub_write_serial_rom(chip, 0x22, 0x10);
  362. retval |= pch_phub_write_serial_rom(chip, 0x21, 0x01);
  363. retval |= pch_phub_write_serial_rom(chip, 0x20, 0x3a);
  364. retval |= pch_phub_write_serial_rom(chip, 0x27, 0x01);
  365. retval |= pch_phub_write_serial_rom(chip, 0x26, 0x00);
  366. retval |= pch_phub_write_serial_rom(chip, 0x25, 0x00);
  367. retval |= pch_phub_write_serial_rom(chip, 0x24, 0x00);
  368. return retval;
  369. }
  370. /* pch_phub_gbe_serial_rom_conf_mp - makes SerialROM header format configuration
  371. * for Gigabit Ethernet MAC address
  372. */
  373. static int pch_phub_gbe_serial_rom_conf_mp(struct pch_phub_reg *chip)
  374. {
  375. int retval;
  376. u32 offset_addr;
  377. offset_addr = 0x200;
  378. retval = pch_phub_write_serial_rom(chip, 0x03 + offset_addr, 0xbc);
  379. retval |= pch_phub_write_serial_rom(chip, 0x02 + offset_addr, 0x00);
  380. retval |= pch_phub_write_serial_rom(chip, 0x01 + offset_addr, 0x40);
  381. retval |= pch_phub_write_serial_rom(chip, 0x00 + offset_addr, 0x02);
  382. retval |= pch_phub_write_serial_rom(chip, 0x07 + offset_addr, 0x00);
  383. retval |= pch_phub_write_serial_rom(chip, 0x06 + offset_addr, 0x00);
  384. retval |= pch_phub_write_serial_rom(chip, 0x05 + offset_addr, 0x00);
  385. retval |= pch_phub_write_serial_rom(chip, 0x04 + offset_addr, 0x80);
  386. retval |= pch_phub_write_serial_rom(chip, 0x0b + offset_addr, 0xbc);
  387. retval |= pch_phub_write_serial_rom(chip, 0x0a + offset_addr, 0x00);
  388. retval |= pch_phub_write_serial_rom(chip, 0x09 + offset_addr, 0x40);
  389. retval |= pch_phub_write_serial_rom(chip, 0x08 + offset_addr, 0x18);
  390. retval |= pch_phub_write_serial_rom(chip, 0x13 + offset_addr, 0xbc);
  391. retval |= pch_phub_write_serial_rom(chip, 0x12 + offset_addr, 0x00);
  392. retval |= pch_phub_write_serial_rom(chip, 0x11 + offset_addr, 0x40);
  393. retval |= pch_phub_write_serial_rom(chip, 0x10 + offset_addr, 0x19);
  394. retval |= pch_phub_write_serial_rom(chip, 0x1b + offset_addr, 0xbc);
  395. retval |= pch_phub_write_serial_rom(chip, 0x1a + offset_addr, 0x00);
  396. retval |= pch_phub_write_serial_rom(chip, 0x19 + offset_addr, 0x40);
  397. retval |= pch_phub_write_serial_rom(chip, 0x18 + offset_addr, 0x3a);
  398. retval |= pch_phub_write_serial_rom(chip, 0x1f + offset_addr, 0x01);
  399. retval |= pch_phub_write_serial_rom(chip, 0x1e + offset_addr, 0x00);
  400. retval |= pch_phub_write_serial_rom(chip, 0x1d + offset_addr, 0x00);
  401. retval |= pch_phub_write_serial_rom(chip, 0x1c + offset_addr, 0x00);
  402. return retval;
  403. }
  404. /**
  405. * pch_phub_read_gbe_mac_addr() - Read Gigabit Ethernet MAC address
  406. * @offset_address: Gigabit Ethernet MAC address offset value.
  407. * @data: Buffer of the Gigabit Ethernet MAC address value.
  408. */
  409. static void pch_phub_read_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
  410. {
  411. int i;
  412. for (i = 0; i < ETH_ALEN; i++)
  413. pch_phub_read_serial_rom_val(chip, i, &data[i]);
  414. }
  415. /**
  416. * pch_phub_write_gbe_mac_addr() - Write MAC address
  417. * @offset_address: Gigabit Ethernet MAC address offset value.
  418. * @data: Gigabit Ethernet MAC address value.
  419. */
  420. static int pch_phub_write_gbe_mac_addr(struct pch_phub_reg *chip, u8 *data)
  421. {
  422. int retval;
  423. int i;
  424. if ((chip->ioh_type == 1) || (chip->ioh_type == 5)) /* EG20T or ML7831*/
  425. retval = pch_phub_gbe_serial_rom_conf(chip);
  426. else /* ML7223 */
  427. retval = pch_phub_gbe_serial_rom_conf_mp(chip);
  428. if (retval)
  429. return retval;
  430. for (i = 0; i < ETH_ALEN; i++) {
  431. retval = pch_phub_write_serial_rom_val(chip, i, data[i]);
  432. if (retval)
  433. return retval;
  434. }
  435. return retval;
  436. }
  437. static ssize_t pch_phub_bin_read(struct file *filp, struct kobject *kobj,
  438. struct bin_attribute *attr, char *buf,
  439. loff_t off, size_t count)
  440. {
  441. unsigned int rom_signature;
  442. unsigned char rom_length;
  443. unsigned int tmp;
  444. unsigned int addr_offset;
  445. unsigned int orom_size;
  446. int ret;
  447. int err;
  448. ssize_t rom_size;
  449. struct pch_phub_reg *chip =
  450. dev_get_drvdata(container_of(kobj, struct device, 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. goto exrom_map_err;
  460. pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address,
  461. (unsigned char *)&rom_signature);
  462. rom_signature &= 0xff;
  463. pch_phub_read_serial_rom(chip, chip->pch_opt_rom_start_address + 1,
  464. (unsigned char *)&tmp);
  465. rom_signature |= (tmp & 0xff) << 8;
  466. if (rom_signature == 0xAA55) {
  467. pch_phub_read_serial_rom(chip,
  468. chip->pch_opt_rom_start_address + 2,
  469. &rom_length);
  470. orom_size = rom_length * 512;
  471. if (orom_size < off) {
  472. addr_offset = 0;
  473. goto return_ok;
  474. }
  475. if (orom_size < count) {
  476. addr_offset = 0;
  477. goto return_ok;
  478. }
  479. for (addr_offset = 0; addr_offset < count; addr_offset++) {
  480. pch_phub_read_serial_rom(chip,
  481. chip->pch_opt_rom_start_address + addr_offset + off,
  482. &buf[addr_offset]);
  483. }
  484. } else {
  485. err = -ENODATA;
  486. goto return_err;
  487. }
  488. return_ok:
  489. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  490. mutex_unlock(&pch_phub_mutex);
  491. return addr_offset;
  492. return_err:
  493. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  494. exrom_map_err:
  495. mutex_unlock(&pch_phub_mutex);
  496. return_err_nomutex:
  497. return err;
  498. }
  499. static ssize_t pch_phub_bin_write(struct file *filp, struct kobject *kobj,
  500. struct bin_attribute *attr,
  501. char *buf, loff_t off, size_t count)
  502. {
  503. int err;
  504. unsigned int addr_offset;
  505. int ret;
  506. ssize_t rom_size;
  507. struct pch_phub_reg *chip =
  508. dev_get_drvdata(container_of(kobj, struct device, kobj));
  509. ret = mutex_lock_interruptible(&pch_phub_mutex);
  510. if (ret)
  511. return -ERESTARTSYS;
  512. if (off > PCH_PHUB_OROM_SIZE) {
  513. addr_offset = 0;
  514. goto return_ok;
  515. }
  516. if (count > PCH_PHUB_OROM_SIZE) {
  517. addr_offset = 0;
  518. goto return_ok;
  519. }
  520. chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
  521. if (!chip->pch_phub_extrom_base_address) {
  522. err = -ENOMEM;
  523. goto exrom_map_err;
  524. }
  525. for (addr_offset = 0; addr_offset < count; addr_offset++) {
  526. if (PCH_PHUB_OROM_SIZE < off + addr_offset)
  527. goto return_ok;
  528. ret = pch_phub_write_serial_rom(chip,
  529. chip->pch_opt_rom_start_address + addr_offset + off,
  530. buf[addr_offset]);
  531. if (ret) {
  532. err = ret;
  533. goto return_err;
  534. }
  535. }
  536. return_ok:
  537. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  538. mutex_unlock(&pch_phub_mutex);
  539. return addr_offset;
  540. return_err:
  541. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  542. exrom_map_err:
  543. mutex_unlock(&pch_phub_mutex);
  544. return err;
  545. }
  546. static ssize_t show_pch_mac(struct device *dev, struct device_attribute *attr,
  547. char *buf)
  548. {
  549. u8 mac[8];
  550. struct pch_phub_reg *chip = dev_get_drvdata(dev);
  551. ssize_t rom_size;
  552. chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
  553. if (!chip->pch_phub_extrom_base_address)
  554. return -ENOMEM;
  555. pch_phub_read_gbe_mac_addr(chip, mac);
  556. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  557. return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  558. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  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[6];
  564. ssize_t rom_size;
  565. struct pch_phub_reg *chip = dev_get_drvdata(dev);
  566. if (count != 18)
  567. return -EINVAL;
  568. sscanf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  569. (u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], (u32 *)&mac[3],
  570. (u32 *)&mac[4], (u32 *)&mac[5]);
  571. chip->pch_phub_extrom_base_address = pci_map_rom(chip->pdev, &rom_size);
  572. if (!chip->pch_phub_extrom_base_address)
  573. return -ENOMEM;
  574. pch_phub_write_gbe_mac_addr(chip, mac);
  575. pci_unmap_rom(chip->pdev, chip->pch_phub_extrom_base_address);
  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 __devinit pch_phub_probe(struct pci_dev *pdev,
  589. const struct pci_device_id *id)
  590. {
  591. int retval;
  592. int ret;
  593. struct pch_phub_reg *chip;
  594. chip = kzalloc(sizeof(struct pch_phub_reg), GFP_KERNEL);
  595. if (chip == NULL)
  596. return -ENOMEM;
  597. ret = pci_enable_device(pdev);
  598. if (ret) {
  599. dev_err(&pdev->dev,
  600. "%s : pci_enable_device FAILED(ret=%d)", __func__, ret);
  601. goto err_pci_enable_dev;
  602. }
  603. dev_dbg(&pdev->dev, "%s : pci_enable_device returns %d\n", __func__,
  604. ret);
  605. ret = pci_request_regions(pdev, KBUILD_MODNAME);
  606. if (ret) {
  607. dev_err(&pdev->dev,
  608. "%s : pci_request_regions FAILED(ret=%d)", __func__, ret);
  609. goto err_req_regions;
  610. }
  611. dev_dbg(&pdev->dev, "%s : "
  612. "pci_request_regions returns %d\n", __func__, ret);
  613. chip->pch_phub_base_address = pci_iomap(pdev, 1, 0);
  614. if (chip->pch_phub_base_address == 0) {
  615. dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__);
  616. ret = -ENOMEM;
  617. goto err_pci_iomap;
  618. }
  619. dev_dbg(&pdev->dev, "%s : pci_iomap SUCCESS and value "
  620. "in pch_phub_base_address variable is %p\n", __func__,
  621. chip->pch_phub_base_address);
  622. chip->pdev = pdev; /* Save pci device struct */
  623. if (id->driver_data == 1) { /* EG20T PCH */
  624. retval = sysfs_create_file(&pdev->dev.kobj,
  625. &dev_attr_pch_mac.attr);
  626. if (retval)
  627. goto err_sysfs_create;
  628. retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  629. if (retval)
  630. goto exit_bin_attr;
  631. pch_phub_read_modify_write_reg(chip,
  632. (unsigned int)CLKCFG_REG_OFFSET,
  633. CLKCFG_CAN_50MHZ,
  634. CLKCFG_CANCLK_MASK);
  635. /* quirk for CM-iTC board */
  636. if (strstr(dmi_get_system_info(DMI_BOARD_NAME), "CM-iTC"))
  637. pch_phub_read_modify_write_reg(chip,
  638. (unsigned int)CLKCFG_REG_OFFSET,
  639. CLKCFG_UART_48MHZ | CLKCFG_BAUDDIV |
  640. CLKCFG_PLL2VCO | CLKCFG_UARTCLKSEL,
  641. CLKCFG_UART_MASK);
  642. /* set the prefech value */
  643. iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14);
  644. /* set the interrupt delay value */
  645. iowrite32(0x25, chip->pch_phub_base_address + 0x44);
  646. chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T;
  647. chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T;
  648. } else if (id->driver_data == 2) { /* ML7213 IOH */
  649. retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  650. if (retval)
  651. goto err_sysfs_create;
  652. /* set the prefech value
  653. * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a
  654. * Device4(SDIO #0,1,2):f
  655. * Device6(SATA 2):f
  656. * Device8(USB OHCI #0/ USB EHCI #0):a
  657. */
  658. iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14);
  659. chip->pch_opt_rom_start_address =\
  660. PCH_PHUB_ROM_START_ADDR_ML7213;
  661. } else if (id->driver_data == 3) { /* ML7223 IOH Bus-m*/
  662. /* set the prefech value
  663. * Device8(GbE)
  664. */
  665. iowrite32(0x000a0000, chip->pch_phub_base_address + 0x14);
  666. /* set the interrupt delay value */
  667. iowrite32(0x25, chip->pch_phub_base_address + 0x140);
  668. chip->pch_opt_rom_start_address =\
  669. PCH_PHUB_ROM_START_ADDR_ML7223;
  670. chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223;
  671. } else if (id->driver_data == 4) { /* ML7223 IOH Bus-n*/
  672. retval = sysfs_create_file(&pdev->dev.kobj,
  673. &dev_attr_pch_mac.attr);
  674. if (retval)
  675. goto err_sysfs_create;
  676. retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  677. if (retval)
  678. goto exit_bin_attr;
  679. /* set the prefech value
  680. * Device2(USB OHCI #0,1,2,3/ USB EHCI #0):a
  681. * Device4(SDIO #0,1):f
  682. * Device6(SATA 2):f
  683. */
  684. iowrite32(0x0000ffa0, chip->pch_phub_base_address + 0x14);
  685. chip->pch_opt_rom_start_address =\
  686. PCH_PHUB_ROM_START_ADDR_ML7223;
  687. chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_ML7223;
  688. } else if (id->driver_data == 5) { /* ML7831 */
  689. retval = sysfs_create_file(&pdev->dev.kobj,
  690. &dev_attr_pch_mac.attr);
  691. if (retval)
  692. goto err_sysfs_create;
  693. retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  694. if (retval)
  695. goto exit_bin_attr;
  696. /* set the prefech value */
  697. iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14);
  698. /* set the interrupt delay value */
  699. iowrite32(0x25, chip->pch_phub_base_address + 0x44);
  700. chip->pch_opt_rom_start_address = PCH_PHUB_ROM_START_ADDR_EG20T;
  701. chip->pch_mac_start_address = PCH_PHUB_MAC_START_ADDR_EG20T;
  702. }
  703. chip->ioh_type = id->driver_data;
  704. pci_set_drvdata(pdev, chip);
  705. return 0;
  706. exit_bin_attr:
  707. sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
  708. err_sysfs_create:
  709. pci_iounmap(pdev, chip->pch_phub_base_address);
  710. err_pci_iomap:
  711. pci_release_regions(pdev);
  712. err_req_regions:
  713. pci_disable_device(pdev);
  714. err_pci_enable_dev:
  715. kfree(chip);
  716. dev_err(&pdev->dev, "%s returns %d\n", __func__, ret);
  717. return ret;
  718. }
  719. static void __devexit pch_phub_remove(struct pci_dev *pdev)
  720. {
  721. struct pch_phub_reg *chip = pci_get_drvdata(pdev);
  722. sysfs_remove_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr);
  723. sysfs_remove_bin_file(&pdev->dev.kobj, &pch_bin_attr);
  724. pci_iounmap(pdev, chip->pch_phub_base_address);
  725. pci_release_regions(pdev);
  726. pci_disable_device(pdev);
  727. kfree(chip);
  728. }
  729. #ifdef CONFIG_PM
  730. static int pch_phub_suspend(struct pci_dev *pdev, pm_message_t state)
  731. {
  732. int ret;
  733. pch_phub_save_reg_conf(pdev);
  734. ret = pci_save_state(pdev);
  735. if (ret) {
  736. dev_err(&pdev->dev,
  737. " %s -pci_save_state returns %d\n", __func__, ret);
  738. return ret;
  739. }
  740. pci_enable_wake(pdev, PCI_D3hot, 0);
  741. pci_disable_device(pdev);
  742. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  743. return 0;
  744. }
  745. static int pch_phub_resume(struct pci_dev *pdev)
  746. {
  747. int ret;
  748. pci_set_power_state(pdev, PCI_D0);
  749. pci_restore_state(pdev);
  750. ret = pci_enable_device(pdev);
  751. if (ret) {
  752. dev_err(&pdev->dev,
  753. "%s-pci_enable_device failed(ret=%d) ", __func__, ret);
  754. return ret;
  755. }
  756. pci_enable_wake(pdev, PCI_D3hot, 0);
  757. pch_phub_restore_reg_conf(pdev);
  758. return 0;
  759. }
  760. #else
  761. #define pch_phub_suspend NULL
  762. #define pch_phub_resume NULL
  763. #endif /* CONFIG_PM */
  764. static struct pci_device_id pch_phub_pcidev_id[] = {
  765. { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, },
  766. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, },
  767. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_mPHUB), 3, },
  768. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7223_nPHUB), 4, },
  769. { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7831_PHUB), 5, },
  770. { }
  771. };
  772. MODULE_DEVICE_TABLE(pci, pch_phub_pcidev_id);
  773. static struct pci_driver pch_phub_driver = {
  774. .name = "pch_phub",
  775. .id_table = pch_phub_pcidev_id,
  776. .probe = pch_phub_probe,
  777. .remove = __devexit_p(pch_phub_remove),
  778. .suspend = pch_phub_suspend,
  779. .resume = pch_phub_resume
  780. };
  781. static int __init pch_phub_pci_init(void)
  782. {
  783. return pci_register_driver(&pch_phub_driver);
  784. }
  785. static void __exit pch_phub_pci_exit(void)
  786. {
  787. pci_unregister_driver(&pch_phub_driver);
  788. }
  789. module_init(pch_phub_pci_init);
  790. module_exit(pch_phub_pci_exit);
  791. MODULE_DESCRIPTION("Intel EG20T PCH/OKI SEMICONDUCTOR IOH(ML7213/ML7223) PHUB");
  792. MODULE_LICENSE("GPL");