pch_phub.c 27 KB

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