ds1wm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*
  2. * 1-wire busmaster driver for DS1WM and ASICs with embedded DS1WMs
  3. * such as HP iPAQs (including h5xxx, h2200, and devices with ASIC3
  4. * like hx4700).
  5. *
  6. * Copyright (c) 2004-2005, Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
  7. * Copyright (c) 2004-2007, Matt Reimer <mreimer@vpop.net>
  8. *
  9. * Use consistent with the GNU GPL is permitted,
  10. * provided that this copyright notice is
  11. * preserved in its entirety in all copies and derived works.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/io.h>
  16. #include <linux/irq.h>
  17. #include <linux/pm.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/err.h>
  20. #include <linux/delay.h>
  21. #include <linux/mfd/core.h>
  22. #include <linux/mfd/ds1wm.h>
  23. #include <linux/slab.h>
  24. #include <asm/io.h>
  25. #include <linux/w1.h>
  26. #define DS1WM_CMD 0x00 /* R/W 4 bits command */
  27. #define DS1WM_DATA 0x01 /* R/W 8 bits, transmit/receive buffer */
  28. #define DS1WM_INT 0x02 /* R/W interrupt status */
  29. #define DS1WM_INT_EN 0x03 /* R/W interrupt enable */
  30. #define DS1WM_CLKDIV 0x04 /* R/W 5 bits of divisor and pre-scale */
  31. #define DS1WM_CNTRL 0x05 /* R/W master control register (not used yet) */
  32. #define DS1WM_CMD_1W_RESET (1 << 0) /* force reset on 1-wire bus */
  33. #define DS1WM_CMD_SRA (1 << 1) /* enable Search ROM accelerator mode */
  34. #define DS1WM_CMD_DQ_OUTPUT (1 << 2) /* write only - forces bus low */
  35. #define DS1WM_CMD_DQ_INPUT (1 << 3) /* read only - reflects state of bus */
  36. #define DS1WM_CMD_RST (1 << 5) /* software reset */
  37. #define DS1WM_CMD_OD (1 << 7) /* overdrive */
  38. #define DS1WM_INT_PD (1 << 0) /* presence detect */
  39. #define DS1WM_INT_PDR (1 << 1) /* presence detect result */
  40. #define DS1WM_INT_TBE (1 << 2) /* tx buffer empty */
  41. #define DS1WM_INT_TSRE (1 << 3) /* tx shift register empty */
  42. #define DS1WM_INT_RBF (1 << 4) /* rx buffer full */
  43. #define DS1WM_INT_RSRF (1 << 5) /* rx shift register full */
  44. #define DS1WM_INTEN_EPD (1 << 0) /* enable presence detect int */
  45. #define DS1WM_INTEN_IAS (1 << 1) /* INTR active state */
  46. #define DS1WM_INTEN_ETBE (1 << 2) /* enable tx buffer empty int */
  47. #define DS1WM_INTEN_ETMT (1 << 3) /* enable tx shift register empty int */
  48. #define DS1WM_INTEN_ERBF (1 << 4) /* enable rx buffer full int */
  49. #define DS1WM_INTEN_ERSRF (1 << 5) /* enable rx shift register full int */
  50. #define DS1WM_INTEN_DQO (1 << 6) /* enable direct bus driving ops */
  51. #define DS1WM_INTEN_NOT_IAS (~DS1WM_INTEN_IAS) /* all but INTR active state */
  52. #define DS1WM_TIMEOUT (HZ * 5)
  53. static struct {
  54. unsigned long freq;
  55. unsigned long divisor;
  56. } freq[] = {
  57. { 1000000, 0x80 },
  58. { 2000000, 0x84 },
  59. { 3000000, 0x81 },
  60. { 4000000, 0x88 },
  61. { 5000000, 0x82 },
  62. { 6000000, 0x85 },
  63. { 7000000, 0x83 },
  64. { 8000000, 0x8c },
  65. { 10000000, 0x86 },
  66. { 12000000, 0x89 },
  67. { 14000000, 0x87 },
  68. { 16000000, 0x90 },
  69. { 20000000, 0x8a },
  70. { 24000000, 0x8d },
  71. { 28000000, 0x8b },
  72. { 32000000, 0x94 },
  73. { 40000000, 0x8e },
  74. { 48000000, 0x91 },
  75. { 56000000, 0x8f },
  76. { 64000000, 0x98 },
  77. { 80000000, 0x92 },
  78. { 96000000, 0x95 },
  79. { 112000000, 0x93 },
  80. { 128000000, 0x9c },
  81. /* you can continue this table, consult the OPERATION - CLOCK DIVISOR
  82. section of the ds1wm spec sheet. */
  83. };
  84. struct ds1wm_data {
  85. void __iomem *map;
  86. unsigned int bus_shift; /* # of shifts to calc register offsets */
  87. bool is_hw_big_endian;
  88. struct platform_device *pdev;
  89. const struct mfd_cell *cell;
  90. int irq;
  91. int slave_present;
  92. void *reset_complete;
  93. void *read_complete;
  94. void *write_complete;
  95. int read_error;
  96. /* last byte received */
  97. u8 read_byte;
  98. /* byte to write that makes all intr disabled, */
  99. /* considering active_state (IAS) (optimization) */
  100. u8 int_en_reg_none;
  101. unsigned int reset_recover_delay; /* see ds1wm.h */
  102. };
  103. static inline void ds1wm_write_register(struct ds1wm_data *ds1wm_data, u32 reg,
  104. u8 val)
  105. {
  106. if (ds1wm_data->is_hw_big_endian) {
  107. switch (ds1wm_data->bus_shift) {
  108. case 0:
  109. iowrite8(val, ds1wm_data->map + (reg << 0));
  110. break;
  111. case 1:
  112. iowrite16be((u16)val, ds1wm_data->map + (reg << 1));
  113. break;
  114. case 2:
  115. iowrite32be((u32)val, ds1wm_data->map + (reg << 2));
  116. break;
  117. }
  118. } else {
  119. switch (ds1wm_data->bus_shift) {
  120. case 0:
  121. iowrite8(val, ds1wm_data->map + (reg << 0));
  122. break;
  123. case 1:
  124. iowrite16((u16)val, ds1wm_data->map + (reg << 1));
  125. break;
  126. case 2:
  127. iowrite32((u32)val, ds1wm_data->map + (reg << 2));
  128. break;
  129. }
  130. }
  131. }
  132. static inline u8 ds1wm_read_register(struct ds1wm_data *ds1wm_data, u32 reg)
  133. {
  134. u32 val = 0;
  135. if (ds1wm_data->is_hw_big_endian) {
  136. switch (ds1wm_data->bus_shift) {
  137. case 0:
  138. val = ioread8(ds1wm_data->map + (reg << 0));
  139. break;
  140. case 1:
  141. val = ioread16be(ds1wm_data->map + (reg << 1));
  142. break;
  143. case 2:
  144. val = ioread32be(ds1wm_data->map + (reg << 2));
  145. break;
  146. }
  147. } else {
  148. switch (ds1wm_data->bus_shift) {
  149. case 0:
  150. val = ioread8(ds1wm_data->map + (reg << 0));
  151. break;
  152. case 1:
  153. val = ioread16(ds1wm_data->map + (reg << 1));
  154. break;
  155. case 2:
  156. val = ioread32(ds1wm_data->map + (reg << 2));
  157. break;
  158. }
  159. }
  160. dev_dbg(&ds1wm_data->pdev->dev,
  161. "ds1wm_read_register reg: %d, 32 bit val:%x\n", reg, val);
  162. return (u8)val;
  163. }
  164. static irqreturn_t ds1wm_isr(int isr, void *data)
  165. {
  166. struct ds1wm_data *ds1wm_data = data;
  167. u8 intr;
  168. u8 inten = ds1wm_read_register(ds1wm_data, DS1WM_INT_EN);
  169. /* if no bits are set in int enable register (except the IAS)
  170. than go no further, reading the regs below has side effects */
  171. if (!(inten & DS1WM_INTEN_NOT_IAS))
  172. return IRQ_NONE;
  173. ds1wm_write_register(ds1wm_data,
  174. DS1WM_INT_EN, ds1wm_data->int_en_reg_none);
  175. /* this read action clears the INTR and certain flags in ds1wm */
  176. intr = ds1wm_read_register(ds1wm_data, DS1WM_INT);
  177. ds1wm_data->slave_present = (intr & DS1WM_INT_PDR) ? 0 : 1;
  178. if ((intr & DS1WM_INT_TSRE) && ds1wm_data->write_complete) {
  179. inten &= ~DS1WM_INTEN_ETMT;
  180. complete(ds1wm_data->write_complete);
  181. }
  182. if (intr & DS1WM_INT_RBF) {
  183. /* this read clears the RBF flag */
  184. ds1wm_data->read_byte = ds1wm_read_register(ds1wm_data,
  185. DS1WM_DATA);
  186. inten &= ~DS1WM_INTEN_ERBF;
  187. if (ds1wm_data->read_complete)
  188. complete(ds1wm_data->read_complete);
  189. }
  190. if ((intr & DS1WM_INT_PD) && ds1wm_data->reset_complete) {
  191. inten &= ~DS1WM_INTEN_EPD;
  192. complete(ds1wm_data->reset_complete);
  193. }
  194. ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, inten);
  195. return IRQ_HANDLED;
  196. }
  197. static int ds1wm_reset(struct ds1wm_data *ds1wm_data)
  198. {
  199. unsigned long timeleft;
  200. DECLARE_COMPLETION_ONSTACK(reset_done);
  201. ds1wm_data->reset_complete = &reset_done;
  202. /* enable Presence detect only */
  203. ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, DS1WM_INTEN_EPD |
  204. ds1wm_data->int_en_reg_none);
  205. ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_1W_RESET);
  206. timeleft = wait_for_completion_timeout(&reset_done, DS1WM_TIMEOUT);
  207. ds1wm_data->reset_complete = NULL;
  208. if (!timeleft) {
  209. dev_err(&ds1wm_data->pdev->dev, "reset failed, timed out\n");
  210. return 1;
  211. }
  212. if (!ds1wm_data->slave_present) {
  213. dev_dbg(&ds1wm_data->pdev->dev, "reset: no devices found\n");
  214. return 1;
  215. }
  216. if (ds1wm_data->reset_recover_delay)
  217. msleep(ds1wm_data->reset_recover_delay);
  218. return 0;
  219. }
  220. static int ds1wm_write(struct ds1wm_data *ds1wm_data, u8 data)
  221. {
  222. unsigned long timeleft;
  223. DECLARE_COMPLETION_ONSTACK(write_done);
  224. ds1wm_data->write_complete = &write_done;
  225. ds1wm_write_register(ds1wm_data, DS1WM_INT_EN,
  226. ds1wm_data->int_en_reg_none | DS1WM_INTEN_ETMT);
  227. ds1wm_write_register(ds1wm_data, DS1WM_DATA, data);
  228. timeleft = wait_for_completion_timeout(&write_done, DS1WM_TIMEOUT);
  229. ds1wm_data->write_complete = NULL;
  230. if (!timeleft) {
  231. dev_err(&ds1wm_data->pdev->dev, "write failed, timed out\n");
  232. return -ETIMEDOUT;
  233. }
  234. return 0;
  235. }
  236. static u8 ds1wm_read(struct ds1wm_data *ds1wm_data, unsigned char write_data)
  237. {
  238. unsigned long timeleft;
  239. u8 intEnable = DS1WM_INTEN_ERBF | ds1wm_data->int_en_reg_none;
  240. DECLARE_COMPLETION_ONSTACK(read_done);
  241. ds1wm_read_register(ds1wm_data, DS1WM_DATA);
  242. ds1wm_data->read_complete = &read_done;
  243. ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, intEnable);
  244. ds1wm_write_register(ds1wm_data, DS1WM_DATA, write_data);
  245. timeleft = wait_for_completion_timeout(&read_done, DS1WM_TIMEOUT);
  246. ds1wm_data->read_complete = NULL;
  247. if (!timeleft) {
  248. dev_err(&ds1wm_data->pdev->dev, "read failed, timed out\n");
  249. ds1wm_data->read_error = -ETIMEDOUT;
  250. return 0xFF;
  251. }
  252. ds1wm_data->read_error = 0;
  253. return ds1wm_data->read_byte;
  254. }
  255. static int ds1wm_find_divisor(int gclk)
  256. {
  257. int i;
  258. for (i = ARRAY_SIZE(freq)-1; i >= 0; --i)
  259. if (gclk >= freq[i].freq)
  260. return freq[i].divisor;
  261. return 0;
  262. }
  263. static void ds1wm_up(struct ds1wm_data *ds1wm_data)
  264. {
  265. int divisor;
  266. struct device *dev = &ds1wm_data->pdev->dev;
  267. struct ds1wm_driver_data *plat = dev_get_platdata(dev);
  268. if (ds1wm_data->cell->enable)
  269. ds1wm_data->cell->enable(ds1wm_data->pdev);
  270. divisor = ds1wm_find_divisor(plat->clock_rate);
  271. dev_dbg(dev, "found divisor 0x%x for clock %d\n",
  272. divisor, plat->clock_rate);
  273. if (divisor == 0) {
  274. dev_err(dev, "no suitable divisor for %dHz clock\n",
  275. plat->clock_rate);
  276. return;
  277. }
  278. ds1wm_write_register(ds1wm_data, DS1WM_CLKDIV, divisor);
  279. /* Let the w1 clock stabilize. */
  280. msleep(1);
  281. ds1wm_reset(ds1wm_data);
  282. }
  283. static void ds1wm_down(struct ds1wm_data *ds1wm_data)
  284. {
  285. ds1wm_reset(ds1wm_data);
  286. /* Disable interrupts. */
  287. ds1wm_write_register(ds1wm_data, DS1WM_INT_EN,
  288. ds1wm_data->int_en_reg_none);
  289. if (ds1wm_data->cell->disable)
  290. ds1wm_data->cell->disable(ds1wm_data->pdev);
  291. }
  292. /* --------------------------------------------------------------------- */
  293. /* w1 methods */
  294. static u8 ds1wm_read_byte(void *data)
  295. {
  296. struct ds1wm_data *ds1wm_data = data;
  297. return ds1wm_read(ds1wm_data, 0xff);
  298. }
  299. static void ds1wm_write_byte(void *data, u8 byte)
  300. {
  301. struct ds1wm_data *ds1wm_data = data;
  302. ds1wm_write(ds1wm_data, byte);
  303. }
  304. static u8 ds1wm_reset_bus(void *data)
  305. {
  306. struct ds1wm_data *ds1wm_data = data;
  307. ds1wm_reset(ds1wm_data);
  308. return 0;
  309. }
  310. static void ds1wm_search(void *data, struct w1_master *master_dev,
  311. u8 search_type, w1_slave_found_callback slave_found)
  312. {
  313. struct ds1wm_data *ds1wm_data = data;
  314. int i;
  315. int ms_discrep_bit = -1;
  316. u64 r = 0; /* holds the progress of the search */
  317. u64 r_prime, d;
  318. unsigned slaves_found = 0;
  319. unsigned int pass = 0;
  320. dev_dbg(&ds1wm_data->pdev->dev, "search begin\n");
  321. while (true) {
  322. ++pass;
  323. if (pass > 100) {
  324. dev_dbg(&ds1wm_data->pdev->dev,
  325. "too many attempts (100), search aborted\n");
  326. return;
  327. }
  328. mutex_lock(&master_dev->bus_mutex);
  329. if (ds1wm_reset(ds1wm_data)) {
  330. mutex_unlock(&master_dev->bus_mutex);
  331. dev_dbg(&ds1wm_data->pdev->dev,
  332. "pass: %d reset error (or no slaves)\n", pass);
  333. break;
  334. }
  335. dev_dbg(&ds1wm_data->pdev->dev,
  336. "pass: %d r : %0#18llx writing SEARCH_ROM\n", pass, r);
  337. ds1wm_write(ds1wm_data, search_type);
  338. dev_dbg(&ds1wm_data->pdev->dev,
  339. "pass: %d entering ASM\n", pass);
  340. ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_SRA);
  341. dev_dbg(&ds1wm_data->pdev->dev,
  342. "pass: %d beginning nibble loop\n", pass);
  343. r_prime = 0;
  344. d = 0;
  345. /* we work one nibble at a time */
  346. /* each nibble is interleaved to form a byte */
  347. for (i = 0; i < 16; i++) {
  348. unsigned char resp, _r, _r_prime, _d;
  349. _r = (r >> (4*i)) & 0xf;
  350. _r = ((_r & 0x1) << 1) |
  351. ((_r & 0x2) << 2) |
  352. ((_r & 0x4) << 3) |
  353. ((_r & 0x8) << 4);
  354. /* writes _r, then reads back: */
  355. resp = ds1wm_read(ds1wm_data, _r);
  356. if (ds1wm_data->read_error) {
  357. dev_err(&ds1wm_data->pdev->dev,
  358. "pass: %d nibble: %d read error\n", pass, i);
  359. break;
  360. }
  361. _r_prime = ((resp & 0x02) >> 1) |
  362. ((resp & 0x08) >> 2) |
  363. ((resp & 0x20) >> 3) |
  364. ((resp & 0x80) >> 4);
  365. _d = ((resp & 0x01) >> 0) |
  366. ((resp & 0x04) >> 1) |
  367. ((resp & 0x10) >> 2) |
  368. ((resp & 0x40) >> 3);
  369. r_prime |= (unsigned long long) _r_prime << (i * 4);
  370. d |= (unsigned long long) _d << (i * 4);
  371. }
  372. if (ds1wm_data->read_error) {
  373. mutex_unlock(&master_dev->bus_mutex);
  374. dev_err(&ds1wm_data->pdev->dev,
  375. "pass: %d read error, retrying\n", pass);
  376. break;
  377. }
  378. dev_dbg(&ds1wm_data->pdev->dev,
  379. "pass: %d r\': %0#18llx d:%0#18llx\n",
  380. pass, r_prime, d);
  381. dev_dbg(&ds1wm_data->pdev->dev,
  382. "pass: %d nibble loop complete, exiting ASM\n", pass);
  383. ds1wm_write_register(ds1wm_data, DS1WM_CMD, ~DS1WM_CMD_SRA);
  384. dev_dbg(&ds1wm_data->pdev->dev,
  385. "pass: %d resetting bus\n", pass);
  386. ds1wm_reset(ds1wm_data);
  387. mutex_unlock(&master_dev->bus_mutex);
  388. if ((r_prime & ((u64)1 << 63)) && (d & ((u64)1 << 63))) {
  389. dev_err(&ds1wm_data->pdev->dev,
  390. "pass: %d bus error, retrying\n", pass);
  391. continue; /* start over */
  392. }
  393. dev_dbg(&ds1wm_data->pdev->dev,
  394. "pass: %d found %0#18llx\n", pass, r_prime);
  395. slave_found(master_dev, r_prime);
  396. ++slaves_found;
  397. dev_dbg(&ds1wm_data->pdev->dev,
  398. "pass: %d complete, preparing next pass\n", pass);
  399. /* any discrepency found which we already choose the
  400. '1' branch is now is now irrelevant we reveal the
  401. next branch with this: */
  402. d &= ~r;
  403. /* find last bit set, i.e. the most signif. bit set */
  404. ms_discrep_bit = fls64(d) - 1;
  405. dev_dbg(&ds1wm_data->pdev->dev,
  406. "pass: %d new d:%0#18llx MS discrep bit:%d\n",
  407. pass, d, ms_discrep_bit);
  408. /* prev_ms_discrep_bit = ms_discrep_bit;
  409. prepare for next ROM search: */
  410. if (ms_discrep_bit == -1)
  411. break;
  412. r = (r & ~(~0ull << (ms_discrep_bit))) | 1 << ms_discrep_bit;
  413. } /* end while true */
  414. dev_dbg(&ds1wm_data->pdev->dev,
  415. "pass: %d total: %d search done ms d bit pos: %d\n", pass,
  416. slaves_found, ms_discrep_bit);
  417. }
  418. /* --------------------------------------------------------------------- */
  419. static struct w1_bus_master ds1wm_master = {
  420. .read_byte = ds1wm_read_byte,
  421. .write_byte = ds1wm_write_byte,
  422. .reset_bus = ds1wm_reset_bus,
  423. .search = ds1wm_search,
  424. };
  425. static int ds1wm_probe(struct platform_device *pdev)
  426. {
  427. struct ds1wm_data *ds1wm_data;
  428. struct ds1wm_driver_data *plat;
  429. struct resource *res;
  430. int ret;
  431. u8 inten;
  432. if (!pdev)
  433. return -ENODEV;
  434. ds1wm_data = devm_kzalloc(&pdev->dev, sizeof(*ds1wm_data), GFP_KERNEL);
  435. if (!ds1wm_data)
  436. return -ENOMEM;
  437. platform_set_drvdata(pdev, ds1wm_data);
  438. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  439. if (!res)
  440. return -ENXIO;
  441. ds1wm_data->map = devm_ioremap(&pdev->dev, res->start,
  442. resource_size(res));
  443. if (!ds1wm_data->map)
  444. return -ENOMEM;
  445. ds1wm_data->pdev = pdev;
  446. ds1wm_data->cell = mfd_get_cell(pdev);
  447. if (!ds1wm_data->cell)
  448. return -ENODEV;
  449. plat = dev_get_platdata(&pdev->dev);
  450. if (!plat)
  451. return -ENODEV;
  452. /* how many bits to shift register number to get register offset */
  453. if (plat->bus_shift > 2) {
  454. dev_err(&ds1wm_data->pdev->dev,
  455. "illegal bus shift %d, not written",
  456. ds1wm_data->bus_shift);
  457. return -EINVAL;
  458. }
  459. ds1wm_data->bus_shift = plat->bus_shift;
  460. /* make sure resource has space for 8 registers */
  461. if ((8 << ds1wm_data->bus_shift) > resource_size(res)) {
  462. dev_err(&ds1wm_data->pdev->dev,
  463. "memory resource size %d to small, should be %d\n",
  464. (int)resource_size(res),
  465. 8 << ds1wm_data->bus_shift);
  466. return -EINVAL;
  467. }
  468. ds1wm_data->is_hw_big_endian = plat->is_hw_big_endian;
  469. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  470. if (!res)
  471. return -ENXIO;
  472. ds1wm_data->irq = res->start;
  473. ds1wm_data->int_en_reg_none = (plat->active_high ? DS1WM_INTEN_IAS : 0);
  474. ds1wm_data->reset_recover_delay = plat->reset_recover_delay;
  475. /* Mask interrupts, set IAS before claiming interrupt */
  476. inten = ds1wm_read_register(ds1wm_data, DS1WM_INT_EN);
  477. ds1wm_write_register(ds1wm_data,
  478. DS1WM_INT_EN, ds1wm_data->int_en_reg_none);
  479. if (res->flags & IORESOURCE_IRQ_HIGHEDGE)
  480. irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_EDGE_RISING);
  481. if (res->flags & IORESOURCE_IRQ_LOWEDGE)
  482. irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_EDGE_FALLING);
  483. if (res->flags & IORESOURCE_IRQ_HIGHLEVEL)
  484. irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_LEVEL_HIGH);
  485. if (res->flags & IORESOURCE_IRQ_LOWLEVEL)
  486. irq_set_irq_type(ds1wm_data->irq, IRQ_TYPE_LEVEL_LOW);
  487. ret = devm_request_irq(&pdev->dev, ds1wm_data->irq, ds1wm_isr,
  488. IRQF_SHARED, "ds1wm", ds1wm_data);
  489. if (ret) {
  490. dev_err(&ds1wm_data->pdev->dev,
  491. "devm_request_irq %d failed with errno %d\n",
  492. ds1wm_data->irq,
  493. ret);
  494. return ret;
  495. }
  496. ds1wm_up(ds1wm_data);
  497. ds1wm_master.data = (void *)ds1wm_data;
  498. ret = w1_add_master_device(&ds1wm_master);
  499. if (ret)
  500. goto err;
  501. dev_dbg(&ds1wm_data->pdev->dev,
  502. "ds1wm: probe successful, IAS: %d, rec.delay: %d, clockrate: %d, bus-shift: %d, is Hw Big Endian: %d\n",
  503. plat->active_high,
  504. plat->reset_recover_delay,
  505. plat->clock_rate,
  506. ds1wm_data->bus_shift,
  507. ds1wm_data->is_hw_big_endian);
  508. return 0;
  509. err:
  510. ds1wm_down(ds1wm_data);
  511. return ret;
  512. }
  513. #ifdef CONFIG_PM
  514. static int ds1wm_suspend(struct platform_device *pdev, pm_message_t state)
  515. {
  516. struct ds1wm_data *ds1wm_data = platform_get_drvdata(pdev);
  517. ds1wm_down(ds1wm_data);
  518. return 0;
  519. }
  520. static int ds1wm_resume(struct platform_device *pdev)
  521. {
  522. struct ds1wm_data *ds1wm_data = platform_get_drvdata(pdev);
  523. ds1wm_up(ds1wm_data);
  524. return 0;
  525. }
  526. #else
  527. #define ds1wm_suspend NULL
  528. #define ds1wm_resume NULL
  529. #endif
  530. static int ds1wm_remove(struct platform_device *pdev)
  531. {
  532. struct ds1wm_data *ds1wm_data = platform_get_drvdata(pdev);
  533. w1_remove_master_device(&ds1wm_master);
  534. ds1wm_down(ds1wm_data);
  535. return 0;
  536. }
  537. static struct platform_driver ds1wm_driver = {
  538. .driver = {
  539. .name = "ds1wm",
  540. },
  541. .probe = ds1wm_probe,
  542. .remove = ds1wm_remove,
  543. .suspend = ds1wm_suspend,
  544. .resume = ds1wm_resume
  545. };
  546. static int __init ds1wm_init(void)
  547. {
  548. pr_info("DS1WM w1 busmaster driver - (c) 2004 Szabolcs Gyurko\n");
  549. return platform_driver_register(&ds1wm_driver);
  550. }
  551. static void __exit ds1wm_exit(void)
  552. {
  553. platform_driver_unregister(&ds1wm_driver);
  554. }
  555. module_init(ds1wm_init);
  556. module_exit(ds1wm_exit);
  557. MODULE_LICENSE("GPL");
  558. MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>, "
  559. "Matt Reimer <mreimer@vpop.net>,"
  560. "Jean-Francois Dagenais <dagenaisj@sonatest.com>");
  561. MODULE_DESCRIPTION("DS1WM w1 busmaster driver");