sata_highbank.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * Calxeda Highbank AHCI SATA platform driver
  3. * Copyright 2012 Calxeda, Inc.
  4. *
  5. * based on the AHCI SATA platform driver by Jeff Garzik and Anton Vorontsov
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/gfp.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/types.h>
  24. #include <linux/err.h>
  25. #include <linux/io.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/device.h>
  28. #include <linux/of_device.h>
  29. #include <linux/of_address.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/libata.h>
  32. #include <linux/ahci_platform.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/delay.h>
  35. #include <linux/export.h>
  36. #include <linux/gpio.h>
  37. #include <linux/of_gpio.h>
  38. #include "ahci.h"
  39. #define CPHY_MAP(dev, addr) ((((dev) & 0x1f) << 7) | (((addr) >> 9) & 0x7f))
  40. #define CPHY_ADDR(addr) (((addr) & 0x1ff) << 2)
  41. #define SERDES_CR_CTL 0x80a0
  42. #define SERDES_CR_ADDR 0x80a1
  43. #define SERDES_CR_DATA 0x80a2
  44. #define CR_BUSY 0x0001
  45. #define CR_START 0x0001
  46. #define CR_WR_RDN 0x0002
  47. #define CPHY_RX_INPUT_STS 0x2002
  48. #define CPHY_SATA_OVERRIDE 0x4000
  49. #define CPHY_OVERRIDE 0x2005
  50. #define SPHY_LANE 0x100
  51. #define SPHY_HALF_RATE 0x0001
  52. #define CPHY_SATA_DPLL_MODE 0x0700
  53. #define CPHY_SATA_DPLL_SHIFT 8
  54. #define CPHY_SATA_DPLL_RESET (1 << 11)
  55. #define CPHY_PHY_COUNT 6
  56. #define CPHY_LANE_COUNT 4
  57. #define CPHY_PORT_COUNT (CPHY_PHY_COUNT * CPHY_LANE_COUNT)
  58. static DEFINE_SPINLOCK(cphy_lock);
  59. /* Each of the 6 phys can have up to 4 sata ports attached to i. Map 0-based
  60. * sata ports to their phys and then to their lanes within the phys
  61. */
  62. struct phy_lane_info {
  63. void __iomem *phy_base;
  64. u8 lane_mapping;
  65. u8 phy_devs;
  66. };
  67. static struct phy_lane_info port_data[CPHY_PORT_COUNT];
  68. static DEFINE_SPINLOCK(sgpio_lock);
  69. #define SCLOCK 0
  70. #define SLOAD 1
  71. #define SDATA 2
  72. #define SGPIO_PINS 3
  73. #define SGPIO_PORTS 8
  74. /* can be cast as an ahci_host_priv for compatibility with most functions */
  75. struct ecx_plat_data {
  76. u32 n_ports;
  77. unsigned sgpio_gpio[SGPIO_PINS];
  78. u32 sgpio_pattern;
  79. u32 port_to_sgpio[SGPIO_PORTS];
  80. };
  81. #define SGPIO_SIGNALS 3
  82. #define ECX_ACTIVITY_BITS 0x300000
  83. #define ECX_ACTIVITY_SHIFT 2
  84. #define ECX_LOCATE_BITS 0x80000
  85. #define ECX_LOCATE_SHIFT 1
  86. #define ECX_FAULT_BITS 0x400000
  87. #define ECX_FAULT_SHIFT 0
  88. static inline int sgpio_bit_shift(struct ecx_plat_data *pdata, u32 port,
  89. u32 shift)
  90. {
  91. return 1 << (3 * pdata->port_to_sgpio[port] + shift);
  92. }
  93. static void ecx_parse_sgpio(struct ecx_plat_data *pdata, u32 port, u32 state)
  94. {
  95. if (state & ECX_ACTIVITY_BITS)
  96. pdata->sgpio_pattern |= sgpio_bit_shift(pdata, port,
  97. ECX_ACTIVITY_SHIFT);
  98. else
  99. pdata->sgpio_pattern &= ~sgpio_bit_shift(pdata, port,
  100. ECX_ACTIVITY_SHIFT);
  101. if (state & ECX_LOCATE_BITS)
  102. pdata->sgpio_pattern |= sgpio_bit_shift(pdata, port,
  103. ECX_LOCATE_SHIFT);
  104. else
  105. pdata->sgpio_pattern &= ~sgpio_bit_shift(pdata, port,
  106. ECX_LOCATE_SHIFT);
  107. if (state & ECX_FAULT_BITS)
  108. pdata->sgpio_pattern |= sgpio_bit_shift(pdata, port,
  109. ECX_FAULT_SHIFT);
  110. else
  111. pdata->sgpio_pattern &= ~sgpio_bit_shift(pdata, port,
  112. ECX_FAULT_SHIFT);
  113. }
  114. /*
  115. * Tell the LED controller that the signal has changed by raising the clock
  116. * line for 50 uS and then lowering it for 50 uS.
  117. */
  118. static void ecx_led_cycle_clock(struct ecx_plat_data *pdata)
  119. {
  120. gpio_set_value(pdata->sgpio_gpio[SCLOCK], 1);
  121. udelay(50);
  122. gpio_set_value(pdata->sgpio_gpio[SCLOCK], 0);
  123. udelay(50);
  124. }
  125. static ssize_t ecx_transmit_led_message(struct ata_port *ap, u32 state,
  126. ssize_t size)
  127. {
  128. struct ahci_host_priv *hpriv = ap->host->private_data;
  129. struct ecx_plat_data *pdata = (struct ecx_plat_data *) hpriv->plat_data;
  130. struct ahci_port_priv *pp = ap->private_data;
  131. unsigned long flags;
  132. int pmp, i;
  133. struct ahci_em_priv *emp;
  134. u32 sgpio_out;
  135. /* get the slot number from the message */
  136. pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
  137. if (pmp < EM_MAX_SLOTS)
  138. emp = &pp->em_priv[pmp];
  139. else
  140. return -EINVAL;
  141. if (!(hpriv->em_msg_type & EM_MSG_TYPE_LED))
  142. return size;
  143. spin_lock_irqsave(&sgpio_lock, flags);
  144. ecx_parse_sgpio(pdata, ap->port_no, state);
  145. sgpio_out = pdata->sgpio_pattern;
  146. gpio_set_value(pdata->sgpio_gpio[SLOAD], 1);
  147. ecx_led_cycle_clock(pdata);
  148. gpio_set_value(pdata->sgpio_gpio[SLOAD], 0);
  149. /*
  150. * bit-bang out the SGPIO pattern, by consuming a bit and then
  151. * clocking it out.
  152. */
  153. for (i = 0; i < (SGPIO_SIGNALS * pdata->n_ports); i++) {
  154. gpio_set_value(pdata->sgpio_gpio[SDATA], sgpio_out & 1);
  155. sgpio_out >>= 1;
  156. ecx_led_cycle_clock(pdata);
  157. }
  158. /* save off new led state for port/slot */
  159. emp->led_state = state;
  160. spin_unlock_irqrestore(&sgpio_lock, flags);
  161. return size;
  162. }
  163. static void highbank_set_em_messages(struct device *dev,
  164. struct ahci_host_priv *hpriv,
  165. struct ata_port_info *pi)
  166. {
  167. struct device_node *np = dev->of_node;
  168. struct ecx_plat_data *pdata = hpriv->plat_data;
  169. int i;
  170. int err;
  171. for (i = 0; i < SGPIO_PINS; i++) {
  172. err = of_get_named_gpio(np, "calxeda,sgpio-gpio", i);
  173. if (IS_ERR_VALUE(err))
  174. return;
  175. pdata->sgpio_gpio[i] = err;
  176. err = gpio_request(pdata->sgpio_gpio[i], "CX SGPIO");
  177. if (err) {
  178. pr_err("sata_highbank gpio_request %d failed: %d\n",
  179. i, err);
  180. return;
  181. }
  182. gpio_direction_output(pdata->sgpio_gpio[i], 1);
  183. }
  184. of_property_read_u32_array(np, "calxeda,led-order",
  185. pdata->port_to_sgpio,
  186. pdata->n_ports);
  187. /* store em_loc */
  188. hpriv->em_loc = 0;
  189. hpriv->em_buf_sz = 4;
  190. hpriv->em_msg_type = EM_MSG_TYPE_LED;
  191. pi->flags |= ATA_FLAG_EM | ATA_FLAG_SW_ACTIVITY;
  192. }
  193. static u32 __combo_phy_reg_read(u8 sata_port, u32 addr)
  194. {
  195. u32 data;
  196. u8 dev = port_data[sata_port].phy_devs;
  197. spin_lock(&cphy_lock);
  198. writel(CPHY_MAP(dev, addr), port_data[sata_port].phy_base + 0x800);
  199. data = readl(port_data[sata_port].phy_base + CPHY_ADDR(addr));
  200. spin_unlock(&cphy_lock);
  201. return data;
  202. }
  203. static void __combo_phy_reg_write(u8 sata_port, u32 addr, u32 data)
  204. {
  205. u8 dev = port_data[sata_port].phy_devs;
  206. spin_lock(&cphy_lock);
  207. writel(CPHY_MAP(dev, addr), port_data[sata_port].phy_base + 0x800);
  208. writel(data, port_data[sata_port].phy_base + CPHY_ADDR(addr));
  209. spin_unlock(&cphy_lock);
  210. }
  211. static void combo_phy_wait_for_ready(u8 sata_port)
  212. {
  213. while (__combo_phy_reg_read(sata_port, SERDES_CR_CTL) & CR_BUSY)
  214. udelay(5);
  215. }
  216. static u32 combo_phy_read(u8 sata_port, u32 addr)
  217. {
  218. combo_phy_wait_for_ready(sata_port);
  219. __combo_phy_reg_write(sata_port, SERDES_CR_ADDR, addr);
  220. __combo_phy_reg_write(sata_port, SERDES_CR_CTL, CR_START);
  221. combo_phy_wait_for_ready(sata_port);
  222. return __combo_phy_reg_read(sata_port, SERDES_CR_DATA);
  223. }
  224. static void combo_phy_write(u8 sata_port, u32 addr, u32 data)
  225. {
  226. combo_phy_wait_for_ready(sata_port);
  227. __combo_phy_reg_write(sata_port, SERDES_CR_ADDR, addr);
  228. __combo_phy_reg_write(sata_port, SERDES_CR_DATA, data);
  229. __combo_phy_reg_write(sata_port, SERDES_CR_CTL, CR_WR_RDN | CR_START);
  230. }
  231. static void highbank_cphy_disable_overrides(u8 sata_port)
  232. {
  233. u8 lane = port_data[sata_port].lane_mapping;
  234. u32 tmp;
  235. if (unlikely(port_data[sata_port].phy_base == NULL))
  236. return;
  237. tmp = combo_phy_read(sata_port, CPHY_RX_INPUT_STS + lane * SPHY_LANE);
  238. tmp &= ~CPHY_SATA_OVERRIDE;
  239. combo_phy_write(sata_port, CPHY_OVERRIDE + lane * SPHY_LANE, tmp);
  240. }
  241. static void cphy_override_rx_mode(u8 sata_port, u32 val)
  242. {
  243. u8 lane = port_data[sata_port].lane_mapping;
  244. u32 tmp;
  245. tmp = combo_phy_read(sata_port, CPHY_RX_INPUT_STS + lane * SPHY_LANE);
  246. tmp &= ~CPHY_SATA_OVERRIDE;
  247. combo_phy_write(sata_port, CPHY_OVERRIDE + lane * SPHY_LANE, tmp);
  248. tmp |= CPHY_SATA_OVERRIDE;
  249. combo_phy_write(sata_port, CPHY_OVERRIDE + lane * SPHY_LANE, tmp);
  250. tmp &= ~CPHY_SATA_DPLL_MODE;
  251. tmp |= val << CPHY_SATA_DPLL_SHIFT;
  252. combo_phy_write(sata_port, CPHY_OVERRIDE + lane * SPHY_LANE, tmp);
  253. tmp |= CPHY_SATA_DPLL_RESET;
  254. combo_phy_write(sata_port, CPHY_OVERRIDE + lane * SPHY_LANE, tmp);
  255. tmp &= ~CPHY_SATA_DPLL_RESET;
  256. combo_phy_write(sata_port, CPHY_OVERRIDE + lane * SPHY_LANE, tmp);
  257. msleep(15);
  258. }
  259. static void highbank_cphy_override_lane(u8 sata_port)
  260. {
  261. u8 lane = port_data[sata_port].lane_mapping;
  262. u32 tmp, k = 0;
  263. if (unlikely(port_data[sata_port].phy_base == NULL))
  264. return;
  265. do {
  266. tmp = combo_phy_read(sata_port, CPHY_RX_INPUT_STS +
  267. lane * SPHY_LANE);
  268. } while ((tmp & SPHY_HALF_RATE) && (k++ < 1000));
  269. cphy_override_rx_mode(sata_port, 3);
  270. }
  271. static int highbank_initialize_phys(struct device *dev, void __iomem *addr)
  272. {
  273. struct device_node *sata_node = dev->of_node;
  274. int phy_count = 0, phy, port = 0;
  275. void __iomem *cphy_base[CPHY_PHY_COUNT];
  276. struct device_node *phy_nodes[CPHY_PHY_COUNT];
  277. memset(port_data, 0, sizeof(struct phy_lane_info) * CPHY_PORT_COUNT);
  278. memset(phy_nodes, 0, sizeof(struct device_node*) * CPHY_PHY_COUNT);
  279. do {
  280. u32 tmp;
  281. struct of_phandle_args phy_data;
  282. if (of_parse_phandle_with_args(sata_node,
  283. "calxeda,port-phys", "#phy-cells",
  284. port, &phy_data))
  285. break;
  286. for (phy = 0; phy < phy_count; phy++) {
  287. if (phy_nodes[phy] == phy_data.np)
  288. break;
  289. }
  290. if (phy_nodes[phy] == NULL) {
  291. phy_nodes[phy] = phy_data.np;
  292. cphy_base[phy] = of_iomap(phy_nodes[phy], 0);
  293. if (cphy_base[phy] == NULL) {
  294. return 0;
  295. }
  296. phy_count += 1;
  297. }
  298. port_data[port].lane_mapping = phy_data.args[0];
  299. of_property_read_u32(phy_nodes[phy], "phydev", &tmp);
  300. port_data[port].phy_devs = tmp;
  301. port_data[port].phy_base = cphy_base[phy];
  302. of_node_put(phy_data.np);
  303. port += 1;
  304. } while (port < CPHY_PORT_COUNT);
  305. return 0;
  306. }
  307. /*
  308. * The Calxeda SATA phy intermittently fails to bring up a link with Gen3
  309. * Retrying the phy hard reset can work around the issue, but the drive
  310. * may fail again. In less than 150 out of 15000 test runs, it took more
  311. * than 10 tries for the link to be established (but never more than 35).
  312. * Triple the maximum observed retry count to provide plenty of margin for
  313. * rare events and to guarantee that the link is established.
  314. *
  315. * Also, the default 2 second time-out on a failed drive is too long in
  316. * this situation. The uboot implementation of the same driver function
  317. * uses a much shorter time-out period and never experiences a time out
  318. * issue. Reducing the time-out to 500ms improves the responsiveness.
  319. * The other timing constants were kept the same as the stock AHCI driver.
  320. * This change was also tested 15000 times on 24 drives and none of them
  321. * experienced a time out.
  322. */
  323. static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
  324. unsigned long deadline)
  325. {
  326. static const unsigned long timing[] = { 5, 100, 500};
  327. struct ata_port *ap = link->ap;
  328. struct ahci_port_priv *pp = ap->private_data;
  329. u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
  330. struct ata_taskfile tf;
  331. bool online;
  332. u32 sstatus;
  333. int rc;
  334. int retry = 100;
  335. ahci_stop_engine(ap);
  336. /* clear D2H reception area to properly wait for D2H FIS */
  337. ata_tf_init(link->device, &tf);
  338. tf.command = ATA_BUSY;
  339. ata_tf_to_fis(&tf, 0, 0, d2h_fis);
  340. do {
  341. highbank_cphy_disable_overrides(link->ap->port_no);
  342. rc = sata_link_hardreset(link, timing, deadline, &online, NULL);
  343. highbank_cphy_override_lane(link->ap->port_no);
  344. /* If the status is 1, we are connected, but the link did not
  345. * come up. So retry resetting the link again.
  346. */
  347. if (sata_scr_read(link, SCR_STATUS, &sstatus))
  348. break;
  349. if (!(sstatus & 0x3))
  350. break;
  351. } while (!online && retry--);
  352. ahci_start_engine(ap);
  353. if (online)
  354. *class = ahci_dev_classify(ap);
  355. return rc;
  356. }
  357. static struct ata_port_operations ahci_highbank_ops = {
  358. .inherits = &ahci_ops,
  359. .hardreset = ahci_highbank_hardreset,
  360. .transmit_led_message = ecx_transmit_led_message,
  361. };
  362. static const struct ata_port_info ahci_highbank_port_info = {
  363. .flags = AHCI_FLAG_COMMON,
  364. .pio_mask = ATA_PIO4,
  365. .udma_mask = ATA_UDMA6,
  366. .port_ops = &ahci_highbank_ops,
  367. };
  368. static struct scsi_host_template ahci_highbank_platform_sht = {
  369. AHCI_SHT("sata_highbank"),
  370. };
  371. static const struct of_device_id ahci_of_match[] = {
  372. { .compatible = "calxeda,hb-ahci" },
  373. {},
  374. };
  375. MODULE_DEVICE_TABLE(of, ahci_of_match);
  376. static int ahci_highbank_probe(struct platform_device *pdev)
  377. {
  378. struct device *dev = &pdev->dev;
  379. struct ahci_host_priv *hpriv;
  380. struct ecx_plat_data *pdata;
  381. struct ata_host *host;
  382. struct resource *mem;
  383. int irq;
  384. int i;
  385. int rc;
  386. u32 n_ports;
  387. struct ata_port_info pi = ahci_highbank_port_info;
  388. const struct ata_port_info *ppi[] = { &pi, NULL };
  389. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  390. if (!mem) {
  391. dev_err(dev, "no mmio space\n");
  392. return -EINVAL;
  393. }
  394. irq = platform_get_irq(pdev, 0);
  395. if (irq <= 0) {
  396. dev_err(dev, "no irq\n");
  397. return -EINVAL;
  398. }
  399. hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
  400. if (!hpriv) {
  401. dev_err(dev, "can't alloc ahci_host_priv\n");
  402. return -ENOMEM;
  403. }
  404. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  405. if (!pdata) {
  406. dev_err(dev, "can't alloc ecx_plat_data\n");
  407. return -ENOMEM;
  408. }
  409. hpriv->flags |= (unsigned long)pi.private_data;
  410. hpriv->mmio = devm_ioremap(dev, mem->start, resource_size(mem));
  411. if (!hpriv->mmio) {
  412. dev_err(dev, "can't map %pR\n", mem);
  413. return -ENOMEM;
  414. }
  415. rc = highbank_initialize_phys(dev, hpriv->mmio);
  416. if (rc)
  417. return rc;
  418. ahci_save_initial_config(dev, hpriv, 0, 0);
  419. /* prepare host */
  420. if (hpriv->cap & HOST_CAP_NCQ)
  421. pi.flags |= ATA_FLAG_NCQ;
  422. if (hpriv->cap & HOST_CAP_PMP)
  423. pi.flags |= ATA_FLAG_PMP;
  424. if (hpriv->cap & HOST_CAP_64)
  425. dma_set_coherent_mask(dev, DMA_BIT_MASK(64));
  426. /* CAP.NP sometimes indicate the index of the last enabled
  427. * port, at other times, that of the last possible port, so
  428. * determining the maximum port number requires looking at
  429. * both CAP.NP and port_map.
  430. */
  431. n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
  432. pdata->n_ports = n_ports;
  433. hpriv->plat_data = pdata;
  434. highbank_set_em_messages(dev, hpriv, &pi);
  435. host = ata_host_alloc_pinfo(dev, ppi, n_ports);
  436. if (!host) {
  437. rc = -ENOMEM;
  438. goto err0;
  439. }
  440. host->private_data = hpriv;
  441. if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
  442. host->flags |= ATA_HOST_PARALLEL_SCAN;
  443. for (i = 0; i < host->n_ports; i++) {
  444. struct ata_port *ap = host->ports[i];
  445. ata_port_desc(ap, "mmio %pR", mem);
  446. ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
  447. /* set enclosure management message type */
  448. if (ap->flags & ATA_FLAG_EM)
  449. ap->em_message_type = hpriv->em_msg_type;
  450. /* disabled/not-implemented port */
  451. if (!(hpriv->port_map & (1 << i)))
  452. ap->ops = &ata_dummy_port_ops;
  453. }
  454. rc = ahci_reset_controller(host);
  455. if (rc)
  456. goto err0;
  457. ahci_init_controller(host);
  458. ahci_print_info(host, "platform");
  459. rc = ata_host_activate(host, irq, ahci_interrupt, 0,
  460. &ahci_highbank_platform_sht);
  461. if (rc)
  462. goto err0;
  463. return 0;
  464. err0:
  465. return rc;
  466. }
  467. #ifdef CONFIG_PM_SLEEP
  468. static int ahci_highbank_suspend(struct device *dev)
  469. {
  470. struct ata_host *host = dev_get_drvdata(dev);
  471. struct ahci_host_priv *hpriv = host->private_data;
  472. void __iomem *mmio = hpriv->mmio;
  473. u32 ctl;
  474. int rc;
  475. if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
  476. dev_err(dev, "firmware update required for suspend/resume\n");
  477. return -EIO;
  478. }
  479. /*
  480. * AHCI spec rev1.1 section 8.3.3:
  481. * Software must disable interrupts prior to requesting a
  482. * transition of the HBA to D3 state.
  483. */
  484. ctl = readl(mmio + HOST_CTL);
  485. ctl &= ~HOST_IRQ_EN;
  486. writel(ctl, mmio + HOST_CTL);
  487. readl(mmio + HOST_CTL); /* flush */
  488. rc = ata_host_suspend(host, PMSG_SUSPEND);
  489. if (rc)
  490. return rc;
  491. return 0;
  492. }
  493. static int ahci_highbank_resume(struct device *dev)
  494. {
  495. struct ata_host *host = dev_get_drvdata(dev);
  496. int rc;
  497. if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
  498. rc = ahci_reset_controller(host);
  499. if (rc)
  500. return rc;
  501. ahci_init_controller(host);
  502. }
  503. ata_host_resume(host);
  504. return 0;
  505. }
  506. #endif
  507. static SIMPLE_DEV_PM_OPS(ahci_highbank_pm_ops,
  508. ahci_highbank_suspend, ahci_highbank_resume);
  509. static struct platform_driver ahci_highbank_driver = {
  510. .remove = ata_platform_remove_one,
  511. .driver = {
  512. .name = "highbank-ahci",
  513. .owner = THIS_MODULE,
  514. .of_match_table = ahci_of_match,
  515. .pm = &ahci_highbank_pm_ops,
  516. },
  517. .probe = ahci_highbank_probe,
  518. };
  519. module_platform_driver(ahci_highbank_driver);
  520. MODULE_DESCRIPTION("Calxeda Highbank AHCI SATA platform driver");
  521. MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@calxeda.com>");
  522. MODULE_LICENSE("GPL");
  523. MODULE_ALIAS("sata:highbank");