hal_msm.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * Copyright (C) ST-Ericsson AP Pte Ltd 2010
  3. *
  4. * ISP1763 Linux HCD Controller driver : hal
  5. *
  6. * This program is free software; you can redistribute it and/or modify it under the terms of
  7. * the GNU General Public License as published by the Free Software Foundation; version
  8. * 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. *
  19. * This is the main hardware abstraction layer file. Hardware initialization, interupt
  20. * processing and read/write routines are handled here.
  21. *
  22. * Author : wired support <wired.support@stericsson.com>
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/device.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/kernel.h>
  29. #include <linux/delay.h>
  30. #include <linux/ioport.h>
  31. #include <linux/sched.h>
  32. #include <linux/completion.h>
  33. #include <linux/slab.h>
  34. #include <linux/smp_lock.h>
  35. #include <linux/errno.h>
  36. #include <linux/init.h>
  37. #include <linux/timer.h>
  38. #include <linux/list.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/usb.h>
  41. #include <linux/gpio.h>
  42. #include <mach/board.h>
  43. #include <linux/poll.h>
  44. #include <asm/io.h>
  45. #include <asm/irq.h>
  46. #include <asm/system.h>
  47. #include <asm/unaligned.h>
  48. /*--------------------------------------------------------------*
  49. * linux system include files
  50. *--------------------------------------------------------------*/
  51. #include "hal_msm.h"
  52. #include "../hal/hal_intf.h"
  53. #include "../hal/isp1763.h"
  54. /*--------------------------------------------------------------*
  55. * Local variable Definitions
  56. *--------------------------------------------------------------*/
  57. struct isp1763_dev isp1763_loc_dev[ISP1763_LAST_DEV];
  58. /*--------------------------------------------------------------*
  59. * Local # Definitions
  60. *--------------------------------------------------------------*/
  61. #define PCI_ACCESS_RETRY_COUNT 20
  62. #define ISP1763_DRIVER_NAME "isp1763_usb"
  63. /*--------------------------------------------------------------*
  64. * Local Function
  65. *--------------------------------------------------------------*/
  66. static int __devexit isp1763_remove(struct platform_device *pdev);
  67. static int __devinit isp1763_probe(struct platform_device *pdev);
  68. /*--------------------------------------------------------------*
  69. * Platform Driver Interface Functions
  70. *--------------------------------------------------------------*/
  71. static struct platform_driver isp1763_usb_driver = {
  72. .remove = __exit_p(isp1763_remove),
  73. .driver = {
  74. .name = ISP1763_DRIVER_NAME,
  75. .owner = THIS_MODULE,
  76. },
  77. };
  78. /*--------------------------------------------------------------*
  79. * ISP1763 Read write routine
  80. *--------------------------------------------------------------*/
  81. /*
  82. * EBI2 on 8660 ignores the first bit and shifts the address by
  83. * one bit to the right.
  84. * Hence, shift left all the register addresses before accessing
  85. * them over EBI2.
  86. * This logic applies only for the register read/writes, for
  87. * read/write from ISP memory this conversion is not needed
  88. * as the ISP obtains the memory address from 'memory' register
  89. */
  90. /* Write a 32 bit Register of isp1763 */
  91. void
  92. isp1763_reg_write32(struct isp1763_dev *dev, u16 reg, u32 data)
  93. {
  94. /* Write the 32bit to the register address given to us */
  95. reg <<= 1;
  96. #ifdef DATABUS_WIDTH_16
  97. writew((u16) data, dev->baseaddress + ((reg)));
  98. writew((u16) (data >> 16), dev->baseaddress + (((reg + 4))));
  99. #else
  100. writeb((u8) data, dev->baseaddress + (reg));
  101. writeb((u8) (data >> 8), dev->baseaddress + ((reg + 1)));
  102. writeb((u8) (data >> 16), dev->baseaddress + ((reg + 2)));
  103. writeb((u8) (data >> 24), dev->baseaddress + ((reg + 3)));
  104. #endif
  105. }
  106. EXPORT_SYMBOL(isp1763_reg_write32);
  107. /* Read a 32 bit Register of isp1763 */
  108. u32
  109. isp1763_reg_read32(struct isp1763_dev *dev, u16 reg, u32 data)
  110. {
  111. #ifdef DATABUS_WIDTH_16
  112. u16 wvalue1, wvalue2;
  113. #else
  114. u8 bval1, bval2, bval3, bval4;
  115. #endif
  116. data = 0;
  117. reg <<= 1;
  118. #ifdef DATABUS_WIDTH_16
  119. wvalue1 = readw(dev->baseaddress + ((reg)));
  120. wvalue2 = readw(dev->baseaddress + (((reg + 4))));
  121. data |= wvalue2;
  122. data <<= 16;
  123. data |= wvalue1;
  124. #else
  125. bval1 = readb(dev->baseaddress + (reg));
  126. bval2 = readb(dev->baseaddress + (reg + 1));
  127. bval3 = readb(dev->baseaddress + (reg + 2));
  128. bval4 = readb(dev->baseaddress + (reg + 3));
  129. data = 0;
  130. data |= bval4;
  131. data <<= 8;
  132. data |= bval3;
  133. data <<= 8;
  134. data |= bval2;
  135. data <<= 8;
  136. data |= bval1;
  137. #endif
  138. return data;
  139. }
  140. EXPORT_SYMBOL(isp1763_reg_read32);
  141. /* Read a 16 bit Register of isp1763 */
  142. u16
  143. isp1763_reg_read16(struct isp1763_dev * dev, u16 reg, u16 data)
  144. {
  145. reg <<= 1;
  146. #ifdef DATABUS_WIDTH_16
  147. data = readw(dev->baseaddress + ((reg)));
  148. #else
  149. u8 bval1, bval2;
  150. bval1 = readb(dev->baseaddress + (reg));
  151. if (reg == HC_DATA_REG){
  152. bval2 = readb(dev->baseaddress + (reg));
  153. } else {
  154. bval2 = readb(dev->baseaddress + ((reg + 1)));
  155. }
  156. data = 0;
  157. data |= bval2;
  158. data <<= 8;
  159. data |= bval1;
  160. #endif
  161. return data;
  162. }
  163. EXPORT_SYMBOL(isp1763_reg_read16);
  164. /* Write a 16 bit Register of isp1763 */
  165. void
  166. isp1763_reg_write16(struct isp1763_dev *dev, u16 reg, u16 data)
  167. {
  168. reg <<= 1;
  169. #ifdef DATABUS_WIDTH_16
  170. writew(data, dev->baseaddress + ((reg)));
  171. #else
  172. writeb((u8) data, dev->baseaddress + (reg));
  173. if (reg == HC_DATA_REG){
  174. writeb((u8) (data >> 8), dev->baseaddress + (reg));
  175. }else{
  176. writeb((u8) (data >> 8), dev->baseaddress + ((reg + 1)));
  177. }
  178. #endif
  179. }
  180. EXPORT_SYMBOL(isp1763_reg_write16);
  181. /* Read a 8 bit Register of isp1763 */
  182. u8
  183. isp1763_reg_read8(struct isp1763_dev *dev, u16 reg, u8 data)
  184. {
  185. reg <<= 1;
  186. data = readb((dev->baseaddress + (reg)));
  187. return data;
  188. }
  189. EXPORT_SYMBOL(isp1763_reg_read8);
  190. /* Write a 8 bit Register of isp1763 */
  191. void
  192. isp1763_reg_write8(struct isp1763_dev *dev, u16 reg, u8 data)
  193. {
  194. reg <<= 1;
  195. writeb(data, (dev->baseaddress + (reg)));
  196. }
  197. EXPORT_SYMBOL(isp1763_reg_write8);
  198. /*--------------------------------------------------------------*
  199. *
  200. * Module dtatils: isp1763_mem_read
  201. *
  202. * Memory read using PIO method.
  203. *
  204. * Input: struct isp1763_driver *drv --> Driver structure.
  205. * u32 start_add --> Starting address of memory
  206. * u32 end_add ---> End address
  207. *
  208. * u32 * buffer --> Buffer pointer.
  209. * u32 length ---> Length
  210. * u16 dir ---> Direction ( Inc or Dec)
  211. *
  212. * Output int Length ----> Number of bytes read
  213. *
  214. * Called by: system function
  215. *
  216. *
  217. *--------------------------------------------------------------*/
  218. /* Memory read function PIO */
  219. int
  220. isp1763_mem_read(struct isp1763_dev *dev, u32 start_add,
  221. u32 end_add, u32 * buffer, u32 length, u16 dir)
  222. {
  223. u8 *one = (u8 *) buffer;
  224. u16 *two = (u16 *) buffer;
  225. u32 a = (u32) length;
  226. u32 w;
  227. u32 w2;
  228. if (buffer == 0) {
  229. printk("Buffer address zero\n");
  230. return 0;
  231. }
  232. isp1763_reg_write16(dev, HC_MEM_READ_REG, start_add);
  233. /* This delay requirement comes from the ISP1763A programming guide */
  234. ndelay(100);
  235. last:
  236. w = isp1763_reg_read16(dev, HC_DATA_REG, w);
  237. w2 = isp1763_reg_read16(dev, HC_DATA_REG, w);
  238. w2 <<= 16;
  239. w = w | w2;
  240. if (a == 1) {
  241. *one = (u8) w;
  242. return 0;
  243. }
  244. if (a == 2) {
  245. *two = (u16) w;
  246. return 0;
  247. }
  248. if (a == 3) {
  249. *two = (u16) w;
  250. two += 1;
  251. w >>= 16;
  252. *two = (u8) (w);
  253. return 0;
  254. }
  255. while (a > 0) {
  256. *buffer = w;
  257. a -= 4;
  258. if (a <= 0) {
  259. break;
  260. }
  261. if (a < 4) {
  262. buffer += 1;
  263. one = (u8 *) buffer;
  264. two = (u16 *) buffer;
  265. goto last;
  266. }
  267. buffer += 1;
  268. w = isp1763_reg_read16(dev, HC_DATA_REG, w);
  269. w2 = isp1763_reg_read16(dev, HC_DATA_REG, w);
  270. w2 <<= 16;
  271. w = w | w2;
  272. }
  273. return ((a < 0) || (a == 0)) ? 0 : (-1);
  274. }
  275. EXPORT_SYMBOL(isp1763_mem_read);
  276. /*--------------------------------------------------------------*
  277. *
  278. * Module dtatils: isp1763_mem_write
  279. *
  280. * Memory write using PIO method.
  281. *
  282. * Input: struct isp1763_driver *drv --> Driver structure.
  283. * u32 start_add --> Starting address of memory
  284. * u32 end_add ---> End address
  285. *
  286. * u32 * buffer --> Buffer pointer.
  287. * u32 length ---> Length
  288. * u16 dir ---> Direction ( Inc or Dec)
  289. *
  290. * Output int Length ----> Number of bytes read
  291. *
  292. * Called by: system function
  293. *
  294. *
  295. *--------------------------------------------------------------*/
  296. /* Memory read function IO */
  297. int
  298. isp1763_mem_write(struct isp1763_dev *dev,
  299. u32 start_add, u32 end_add, u32 * buffer, u32 length, u16 dir)
  300. {
  301. int a = length;
  302. u8 one = (u8) (*buffer);
  303. u16 two = (u16) (*buffer);
  304. isp1763_reg_write16(dev, HC_MEM_READ_REG, start_add);
  305. /* This delay requirement comes from the ISP1763A programming guide */
  306. ndelay(100);
  307. if (a == 1) {
  308. isp1763_reg_write16(dev, HC_DATA_REG, one);
  309. return 0;
  310. }
  311. if (a == 2) {
  312. isp1763_reg_write16(dev, HC_DATA_REG, two);
  313. return 0;
  314. }
  315. while (a > 0) {
  316. isp1763_reg_write16(dev, HC_DATA_REG, (u16) (*buffer));
  317. if (a >= 3)
  318. isp1763_reg_write16(dev, HC_DATA_REG,
  319. (u16) ((*buffer) >> 16));
  320. start_add += 4;
  321. a -= 4;
  322. if (a <= 0)
  323. break;
  324. buffer += 1;
  325. }
  326. return ((a < 0) || (a == 0)) ? 0 : (-1);
  327. }
  328. EXPORT_SYMBOL(isp1763_mem_write);
  329. /*--------------------------------------------------------------*
  330. *
  331. * Module dtatils: isp1763_register_driver
  332. *
  333. * This function is used by top driver (OTG, HCD, DCD) to register
  334. * their communication functions (probe, remove, suspend, resume) using
  335. * the drv data structure.
  336. * This function will call the probe function of the driver if the ISP1763
  337. * corresponding to the driver is enabled
  338. *
  339. * Input: struct isp1763_driver *drv --> Driver structure.
  340. * Output result
  341. * 0= complete
  342. * 1= error.
  343. *
  344. * Called by: system function module_init
  345. *
  346. *
  347. *--------------------------------------------------------------*/
  348. int
  349. isp1763_register_driver(struct isp1763_driver *drv)
  350. {
  351. struct isp1763_dev *dev;
  352. int result = -EINVAL;
  353. hal_entry("%s: Entered\n", __FUNCTION__);
  354. info("isp1763_register_driver(drv=%pK)\n", drv);
  355. if (!drv) {
  356. return -EINVAL;
  357. }
  358. dev = &isp1763_loc_dev[drv->index];
  359. if (!dev->baseaddress)
  360. return -EINVAL;
  361. dev->active = 1; /* set the driver as active*/
  362. if (drv->probe) {
  363. result = drv->probe(dev, drv->id);
  364. } else {
  365. printk("%s no probe function for indes %d \n", __FUNCTION__,
  366. (int)drv->index);
  367. }
  368. if (result >= 0) {
  369. pr_debug(KERN_INFO __FILE__ ": Registered Driver %s\n",
  370. drv->name);
  371. dev->driver = drv;
  372. }
  373. hal_entry("%s: Exit\n", __FUNCTION__);
  374. return result;
  375. } /* End of isp1763_register_driver */
  376. EXPORT_SYMBOL(isp1763_register_driver);
  377. /*--------------------------------------------------------------*
  378. *
  379. * Module dtatils: isp1763_unregister_driver
  380. *
  381. * This function is used by top driver (OTG, HCD, DCD) to de-register
  382. * their communication functions (probe, remove, suspend, resume) using
  383. * the drv data structure.
  384. * This function will check whether the driver is registered or not and
  385. * call the remove function of the driver if registered
  386. *
  387. * Input: struct isp1763_driver *drv --> Driver structure.
  388. * Output result
  389. * 0= complete
  390. * 1= error.
  391. *
  392. * Called by: system function module_init
  393. *
  394. *
  395. *--------------------------------------------------------------*/
  396. void
  397. isp1763_unregister_driver(struct isp1763_driver *drv)
  398. {
  399. struct isp1763_dev *dev;
  400. hal_entry("%s: Entered\n", __FUNCTION__);
  401. info("isp1763_unregister_driver(drv=%pK)\n", drv);
  402. dev = &isp1763_loc_dev[drv->index];
  403. if (dev->driver == drv) {
  404. /* driver registered is same as the requestig driver */
  405. drv->remove(dev);
  406. dev->driver = NULL;
  407. info(": De-registered Driver %s\n", drv->name);
  408. return;
  409. }
  410. hal_entry("%s: Exit\n", __FUNCTION__);
  411. } /* End of isp1763_unregister_driver */
  412. EXPORT_SYMBOL(isp1763_unregister_driver);
  413. /*--------------------------------------------------------------*
  414. * ISP1763 Platform driver interface routine.
  415. *--------------------------------------------------------------*/
  416. /*--------------------------------------------------------------*
  417. *
  418. * Module dtatils: isp1763_module_init
  419. *
  420. * This is the module initialization function. It registers to
  421. * driver for a isp1763 platform device. And also resets the
  422. * internal data structures.
  423. *
  424. * Input: void
  425. * Output result
  426. * 0= complete
  427. * 1= error.
  428. *
  429. * Called by: system function module_init
  430. *
  431. *
  432. *
  433. -------------------------------------------------------------------*/
  434. static int __init
  435. isp1763_module_init(void)
  436. {
  437. int result = 0;
  438. hal_entry("%s: Entered\n", __FUNCTION__);
  439. pr_debug(KERN_NOTICE "+isp1763_module_init\n");
  440. memset(isp1763_loc_dev, 0, sizeof(isp1763_loc_dev));
  441. result = platform_driver_probe(&isp1763_usb_driver, isp1763_probe);
  442. pr_debug(KERN_NOTICE "-isp1763_module_init\n");
  443. hal_entry("%s: Exit\n", __FUNCTION__);
  444. return result;
  445. }
  446. /*--------------------------------------------------------------*
  447. *
  448. * Module dtatils: isp1763_module_cleanup
  449. *
  450. * This is the module cleanup function. It de-registers the
  451. * Platform driver and resets the internal data structures.
  452. *
  453. * Input: void
  454. * Output void
  455. *
  456. * Called by: system function module_cleanup
  457. *
  458. *
  459. *
  460. --------------------------------------------------------------*/
  461. static void __exit
  462. isp1763_module_cleanup(void)
  463. {
  464. pr_debug("Hal Module Cleanup\n");
  465. platform_driver_unregister(&isp1763_usb_driver);
  466. memset(isp1763_loc_dev, 0, sizeof(isp1763_loc_dev));
  467. }
  468. void dummy_mem_read(struct isp1763_dev *dev)
  469. {
  470. u32 w = 0;
  471. isp1763_reg_write16(dev, HC_MEM_READ_REG, 0x0400);
  472. w = isp1763_reg_read16(dev, HC_DATA_REG, w);
  473. pr_debug("dummy_read DONE: %x\n", w);
  474. msleep(10);
  475. }
  476. /*--------------------------------------------------------------*
  477. *
  478. * Module dtatils: isp1763_probe
  479. *
  480. * probe function of ISP1763
  481. * This function is called from module_init if the corresponding platform
  482. * device is present. This function initializes the information
  483. * for the Host Controller with the assigned resources and tests the register
  484. * access to the controller and do a software reset and makes it ready
  485. * for the driver to play with. It also calls setup_gpio passed from pdata
  486. * to setup GPIOs (e.g. used for IRQ and RST lines).
  487. *
  488. * Input:
  489. * struct platform_device *dev ----> Platform Device structure
  490. * Output void
  491. *
  492. * Called by: system function module_cleanup
  493. *
  494. *
  495. *
  496. --------------------------------------------------------------**/
  497. static int __devinit
  498. isp1763_probe(struct platform_device *pdev)
  499. {
  500. u32 reg_data = 0;
  501. struct isp1763_dev *loc_dev;
  502. int status = 1;
  503. u32 hwmodectrl = 0;
  504. u16 us_reset_hc = 0;
  505. u32 chipid = 0;
  506. struct isp1763_platform_data *pdata = pdev->dev.platform_data;
  507. hal_entry("%s: Entered\n", __FUNCTION__);
  508. hal_init(("isp1763_probe(dev=%pK)\n", dev));
  509. loc_dev = &(isp1763_loc_dev[ISP1763_HC]);
  510. loc_dev->dev = pdev;
  511. /* Get the Host Controller IO and INT resources */
  512. loc_dev->mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  513. if (!loc_dev->mem_res) {
  514. pr_err("%s: failed to get platform resource mem\n", __func__);
  515. return -ENODEV;
  516. }
  517. loc_dev->baseaddress = ioremap_nocache(loc_dev->mem_res->start,
  518. resource_size(loc_dev->mem_res));
  519. if (!loc_dev->baseaddress) {
  520. pr_err("%s: ioremap failed\n", __func__);
  521. status = -ENOMEM;
  522. goto put_mem_res;
  523. }
  524. pr_info("%s: ioremap done at: %x\n", __func__,
  525. (int)loc_dev->baseaddress);
  526. loc_dev->irq = platform_get_irq(pdev, 0);
  527. if (!loc_dev->irq) {
  528. pr_err("%s: platform_get_irq failed\n", __func__);
  529. status = -ENODEV;
  530. goto free_regs;
  531. }
  532. loc_dev->index = ISP1763_HC; /*zero */
  533. loc_dev->length = resource_size(loc_dev->mem_res);
  534. hal_init(("isp1763 HC MEM Base= %pK irq = %d\n",
  535. loc_dev->baseaddress, loc_dev->irq));
  536. /* Setup GPIOs and isssue RESET_N to Controller */
  537. if (pdata->setup_gpio)
  538. if (pdata->setup_gpio(1))
  539. pr_err("%s: Failed to setup GPIOs for isp1763\n",
  540. __func__);
  541. if (pdata->reset_gpio) {
  542. gpio_set_value(pdata->reset_gpio, 0);
  543. msleep(10);
  544. gpio_set_value(pdata->reset_gpio, 1);
  545. } else {
  546. pr_err("%s: Failed to issue RESET_N to isp1763\n", __func__);
  547. }
  548. dummy_mem_read(loc_dev);
  549. chipid = isp1763_reg_read32(loc_dev, DC_CHIPID, chipid);
  550. pr_info("START: chip id:%x\n", chipid);
  551. /*reset the host controller */
  552. pr_debug("RESETTING\n");
  553. us_reset_hc |= 0x1;
  554. isp1763_reg_write16(loc_dev, 0xB8, us_reset_hc);
  555. msleep(20);
  556. us_reset_hc = 0;
  557. us_reset_hc |= 0x2;
  558. isp1763_reg_write16(loc_dev, 0xB8, us_reset_hc);
  559. chipid = isp1763_reg_read32(loc_dev, DC_CHIPID, chipid);
  560. pr_info("after HC reset, chipid:%x\n", chipid);
  561. msleep(20);
  562. hwmodectrl = isp1763_reg_read16(loc_dev, HC_HWMODECTRL_REG, hwmodectrl);
  563. pr_debug("Mode Ctrl Value b4 setting buswidth: %x\n", hwmodectrl);
  564. #ifdef DATABUS_WIDTH_16
  565. hwmodectrl &= 0xFFEF; /*enable the 16 bit bus */
  566. #else
  567. pr_debug("Setting 8-BIT mode\n");
  568. hwmodectrl |= 0x0010; /*enable the 8 bit bus */
  569. #endif
  570. isp1763_reg_write16(loc_dev, HC_HWMODECTRL_REG, hwmodectrl);
  571. pr_debug("writing 0x%x to hw mode reg\n", hwmodectrl);
  572. hwmodectrl = isp1763_reg_read16(loc_dev, HC_HWMODECTRL_REG, hwmodectrl);
  573. msleep(100);
  574. pr_debug("Mode Ctrl Value after setting buswidth: %x\n", hwmodectrl);
  575. chipid = isp1763_reg_read32(loc_dev, DC_CHIPID, chipid);
  576. pr_debug("after setting HW MODE to 8bit, chipid:%x\n", chipid);
  577. hal_init(("isp1763 DC MEM Base= %lx irq = %d\n",
  578. loc_dev->io_base, loc_dev->irq));
  579. reg_data = isp1763_reg_read16(loc_dev, HC_SCRATCH_REG, reg_data);
  580. pr_debug("Scratch register is 0x%x\n", reg_data);
  581. reg_data = 0xABCD;
  582. isp1763_reg_write16(loc_dev, HC_SCRATCH_REG, reg_data);
  583. reg_data = isp1763_reg_read16(loc_dev, HC_SCRATCH_REG, reg_data);
  584. pr_debug("After write, Scratch register is 0x%x\n", reg_data);
  585. if (reg_data != 0xABCD) {
  586. pr_err("%s: Scratch register write mismatch!!\n", __func__);
  587. status = -ENODEV;
  588. goto free_gpios;
  589. }
  590. memcpy(loc_dev->name, ISP1763_DRIVER_NAME, sizeof(ISP1763_DRIVER_NAME));
  591. loc_dev->name[sizeof(ISP1763_DRIVER_NAME)] = 0;
  592. pr_debug(KERN_NOTICE "-isp1763_pci_probe\n");
  593. hal_entry("%s: Exit\n", __FUNCTION__);
  594. return 0;
  595. free_gpios:
  596. if (pdata->setup_gpio)
  597. pdata->setup_gpio(0);
  598. free_regs:
  599. iounmap(loc_dev->baseaddress);
  600. put_mem_res:
  601. loc_dev->baseaddress = NULL;
  602. hal_entry("%s: Exit\n", __FUNCTION__);
  603. return status;
  604. } /* End of isp1763_probe */
  605. /*--------------------------------------------------------------*
  606. *
  607. * Module details: isp1763_remove
  608. *
  609. * cleanup function of ISP1763
  610. * This functions de-initializes the local variables, frees GPIOs
  611. * and releases memory resource.
  612. *
  613. * Input:
  614. * struct platform_device *dev ----> Platform Device structure
  615. *
  616. * Output void
  617. *
  618. * Called by: system function module_cleanup
  619. *
  620. *
  621. *
  622. --------------------------------------------------------------*/
  623. static int __devexit
  624. isp1763_remove(struct platform_device *pdev)
  625. {
  626. struct isp1763_dev *loc_dev;
  627. struct isp1763_platform_data *pdata = pdev->dev.platform_data;
  628. hal_init(("isp1763_pci_remove(dev=%pK)\n", dev));
  629. loc_dev = &isp1763_loc_dev[ISP1763_HC];
  630. iounmap(loc_dev->baseaddress);
  631. loc_dev->baseaddress = NULL;
  632. if (pdata->setup_gpio)
  633. return pdata->setup_gpio(0);
  634. return 0;
  635. } /* End of isp1763_remove */
  636. MODULE_AUTHOR(DRIVER_AUTHOR);
  637. MODULE_DESCRIPTION(DRIVER_DESC);
  638. MODULE_LICENSE("GPL");
  639. module_init(isp1763_module_init);
  640. module_exit(isp1763_module_cleanup);