1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for the Diolan DLN-2 USB-SPI adapter
5 * Copyright (c) 2014 Intel Corporation
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/property.h>
12 #include <linux/mfd/dln2.h>
13 #include <linux/spi/spi.h>
14 #include <linux/pm_runtime.h>
15 #include <linux/unaligned.h>
17 #define DLN2_SPI_MODULE_ID 0x02
18 #define DLN2_SPI_CMD(cmd) DLN2_CMD(cmd, DLN2_SPI_MODULE_ID)
21 #define DLN2_SPI_GET_PORT_COUNT DLN2_SPI_CMD(0x00)
22 #define DLN2_SPI_ENABLE DLN2_SPI_CMD(0x11)
23 #define DLN2_SPI_DISABLE DLN2_SPI_CMD(0x12)
24 #define DLN2_SPI_IS_ENABLED DLN2_SPI_CMD(0x13)
25 #define DLN2_SPI_SET_MODE DLN2_SPI_CMD(0x14)
26 #define DLN2_SPI_GET_MODE DLN2_SPI_CMD(0x15)
27 #define DLN2_SPI_SET_FRAME_SIZE DLN2_SPI_CMD(0x16)
28 #define DLN2_SPI_GET_FRAME_SIZE DLN2_SPI_CMD(0x17)
29 #define DLN2_SPI_SET_FREQUENCY DLN2_SPI_CMD(0x18)
30 #define DLN2_SPI_GET_FREQUENCY DLN2_SPI_CMD(0x19)
31 #define DLN2_SPI_READ_WRITE DLN2_SPI_CMD(0x1A)
32 #define DLN2_SPI_READ DLN2_SPI_CMD(0x1B)
33 #define DLN2_SPI_WRITE DLN2_SPI_CMD(0x1C)
34 #define DLN2_SPI_SET_DELAY_BETWEEN_SS DLN2_SPI_CMD(0x20)
35 #define DLN2_SPI_GET_DELAY_BETWEEN_SS DLN2_SPI_CMD(0x21)
36 #define DLN2_SPI_SET_DELAY_AFTER_SS DLN2_SPI_CMD(0x22)
37 #define DLN2_SPI_GET_DELAY_AFTER_SS DLN2_SPI_CMD(0x23)
38 #define DLN2_SPI_SET_DELAY_BETWEEN_FRAMES DLN2_SPI_CMD(0x24)
39 #define DLN2_SPI_GET_DELAY_BETWEEN_FRAMES DLN2_SPI_CMD(0x25)
40 #define DLN2_SPI_SET_SS DLN2_SPI_CMD(0x26)
41 #define DLN2_SPI_GET_SS DLN2_SPI_CMD(0x27)
42 #define DLN2_SPI_RELEASE_SS DLN2_SPI_CMD(0x28)
43 #define DLN2_SPI_SS_VARIABLE_ENABLE DLN2_SPI_CMD(0x2B)
44 #define DLN2_SPI_SS_VARIABLE_DISABLE DLN2_SPI_CMD(0x2C)
45 #define DLN2_SPI_SS_VARIABLE_IS_ENABLED DLN2_SPI_CMD(0x2D)
46 #define DLN2_SPI_SS_AAT_ENABLE DLN2_SPI_CMD(0x2E)
47 #define DLN2_SPI_SS_AAT_DISABLE DLN2_SPI_CMD(0x2F)
48 #define DLN2_SPI_SS_AAT_IS_ENABLED DLN2_SPI_CMD(0x30)
49 #define DLN2_SPI_SS_BETWEEN_FRAMES_ENABLE DLN2_SPI_CMD(0x31)
50 #define DLN2_SPI_SS_BETWEEN_FRAMES_DISABLE DLN2_SPI_CMD(0x32)
51 #define DLN2_SPI_SS_BETWEEN_FRAMES_IS_ENABLED DLN2_SPI_CMD(0x33)
52 #define DLN2_SPI_SET_CPHA DLN2_SPI_CMD(0x34)
53 #define DLN2_SPI_GET_CPHA DLN2_SPI_CMD(0x35)
54 #define DLN2_SPI_SET_CPOL DLN2_SPI_CMD(0x36)
55 #define DLN2_SPI_GET_CPOL DLN2_SPI_CMD(0x37)
56 #define DLN2_SPI_SS_MULTI_ENABLE DLN2_SPI_CMD(0x38)
57 #define DLN2_SPI_SS_MULTI_DISABLE DLN2_SPI_CMD(0x39)
58 #define DLN2_SPI_SS_MULTI_IS_ENABLED DLN2_SPI_CMD(0x3A)
59 #define DLN2_SPI_GET_SUPPORTED_MODES DLN2_SPI_CMD(0x40)
60 #define DLN2_SPI_GET_SUPPORTED_CPHA_VALUES DLN2_SPI_CMD(0x41)
61 #define DLN2_SPI_GET_SUPPORTED_CPOL_VALUES DLN2_SPI_CMD(0x42)
62 #define DLN2_SPI_GET_SUPPORTED_FRAME_SIZES DLN2_SPI_CMD(0x43)
63 #define DLN2_SPI_GET_SS_COUNT DLN2_SPI_CMD(0x44)
64 #define DLN2_SPI_GET_MIN_FREQUENCY DLN2_SPI_CMD(0x45)
65 #define DLN2_SPI_GET_MAX_FREQUENCY DLN2_SPI_CMD(0x46)
66 #define DLN2_SPI_GET_MIN_DELAY_BETWEEN_SS DLN2_SPI_CMD(0x47)
67 #define DLN2_SPI_GET_MAX_DELAY_BETWEEN_SS DLN2_SPI_CMD(0x48)
68 #define DLN2_SPI_GET_MIN_DELAY_AFTER_SS DLN2_SPI_CMD(0x49)
69 #define DLN2_SPI_GET_MAX_DELAY_AFTER_SS DLN2_SPI_CMD(0x4A)
70 #define DLN2_SPI_GET_MIN_DELAY_BETWEEN_FRAMES DLN2_SPI_CMD(0x4B)
71 #define DLN2_SPI_GET_MAX_DELAY_BETWEEN_FRAMES DLN2_SPI_CMD(0x4C)
73 #define DLN2_SPI_MAX_XFER_SIZE 256
74 #define DLN2_SPI_BUF_SIZE (DLN2_SPI_MAX_XFER_SIZE + 16)
75 #define DLN2_SPI_ATTR_LEAVE_SS_LOW BIT(0)
76 #define DLN2_TRANSFERS_WAIT_COMPLETE 1
77 #define DLN2_TRANSFERS_CANCEL 0
78 #define DLN2_RPM_AUTOSUSPEND_TIMEOUT 2000
81 struct platform_device
*pdev
;
82 struct spi_controller
*host
;
86 * This buffer will be used mainly for read/write operations. Since
87 * they're quite large, we cannot use the stack. Protection is not
88 * needed because all SPI communication is serialized by the SPI core.
99 * Enable/Disable SPI module. The disable command will wait for transfers to
102 static int dln2_spi_enable(struct dln2_spi
*dln2
, bool enable
)
107 u8 wait_for_completion
;
109 unsigned len
= sizeof(tx
);
111 tx
.port
= dln2
->port
;
114 cmd
= DLN2_SPI_ENABLE
;
115 len
-= sizeof(tx
.wait_for_completion
);
117 tx
.wait_for_completion
= DLN2_TRANSFERS_WAIT_COMPLETE
;
118 cmd
= DLN2_SPI_DISABLE
;
121 return dln2_transfer_tx(dln2
->pdev
, cmd
, &tx
, len
);
125 * Select/unselect multiple CS lines. The selected lines will be automatically
126 * toggled LOW/HIGH by the board firmware during transfers, provided they're
129 * Ex: cs_mask = 0x03 -> CS0 & CS1 will be selected and the next WR/RD operation
130 * will toggle the lines LOW/HIGH automatically.
132 static int dln2_spi_cs_set(struct dln2_spi
*dln2
, u8 cs_mask
)
139 tx
.port
= dln2
->port
;
142 * According to Diolan docs, "a slave device can be selected by changing
143 * the corresponding bit value to 0". The rest must be set to 1. Hence
144 * the bitwise NOT in front.
148 return dln2_transfer_tx(dln2
->pdev
, DLN2_SPI_SET_SS
, &tx
, sizeof(tx
));
152 * Select one CS line. The other lines will be un-selected.
154 static int dln2_spi_cs_set_one(struct dln2_spi
*dln2
, u8 cs
)
156 return dln2_spi_cs_set(dln2
, BIT(cs
));
160 * Enable/disable CS lines for usage. The module has to be disabled first.
162 static int dln2_spi_cs_enable(struct dln2_spi
*dln2
, u8 cs_mask
, bool enable
)
170 tx
.port
= dln2
->port
;
172 cmd
= enable
? DLN2_SPI_SS_MULTI_ENABLE
: DLN2_SPI_SS_MULTI_DISABLE
;
174 return dln2_transfer_tx(dln2
->pdev
, cmd
, &tx
, sizeof(tx
));
177 static int dln2_spi_cs_enable_all(struct dln2_spi
*dln2
, bool enable
)
179 u8 cs_mask
= GENMASK(dln2
->host
->num_chipselect
- 1, 0);
181 return dln2_spi_cs_enable(dln2
, cs_mask
, enable
);
184 static int dln2_spi_get_cs_num(struct dln2_spi
*dln2
, u16
*cs_num
)
193 unsigned rx_len
= sizeof(rx
);
195 tx
.port
= dln2
->port
;
196 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_GET_SS_COUNT
, &tx
, sizeof(tx
),
200 if (rx_len
< sizeof(rx
))
203 *cs_num
= le16_to_cpu(rx
.cs_count
);
205 dev_dbg(&dln2
->pdev
->dev
, "cs_num = %d\n", *cs_num
);
210 static int dln2_spi_get_speed(struct dln2_spi
*dln2
, u16 cmd
, u32
*freq
)
219 unsigned rx_len
= sizeof(rx
);
221 tx
.port
= dln2
->port
;
223 ret
= dln2_transfer(dln2
->pdev
, cmd
, &tx
, sizeof(tx
), &rx
, &rx_len
);
226 if (rx_len
< sizeof(rx
))
229 *freq
= le32_to_cpu(rx
.speed
);
235 * Get bus min/max frequencies.
237 static int dln2_spi_get_speed_range(struct dln2_spi
*dln2
, u32
*fmin
, u32
*fmax
)
241 ret
= dln2_spi_get_speed(dln2
, DLN2_SPI_GET_MIN_FREQUENCY
, fmin
);
245 ret
= dln2_spi_get_speed(dln2
, DLN2_SPI_GET_MAX_FREQUENCY
, fmax
);
249 dev_dbg(&dln2
->pdev
->dev
, "freq_min = %d, freq_max = %d\n",
256 * Set the bus speed. The module will automatically round down to the closest
257 * available frequency and returns it. The module has to be disabled first.
259 static int dln2_spi_set_speed(struct dln2_spi
*dln2
, u32 speed
)
269 int rx_len
= sizeof(rx
);
271 tx
.port
= dln2
->port
;
272 tx
.speed
= cpu_to_le32(speed
);
274 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_SET_FREQUENCY
, &tx
, sizeof(tx
),
278 if (rx_len
< sizeof(rx
))
285 * Change CPOL & CPHA. The module has to be disabled first.
287 static int dln2_spi_set_mode(struct dln2_spi
*dln2
, u8 mode
)
294 tx
.port
= dln2
->port
;
297 return dln2_transfer_tx(dln2
->pdev
, DLN2_SPI_SET_MODE
, &tx
, sizeof(tx
));
301 * Change frame size. The module has to be disabled first.
303 static int dln2_spi_set_bpw(struct dln2_spi
*dln2
, u8 bpw
)
310 tx
.port
= dln2
->port
;
313 return dln2_transfer_tx(dln2
->pdev
, DLN2_SPI_SET_FRAME_SIZE
,
317 static int dln2_spi_get_supported_frame_sizes(struct dln2_spi
*dln2
,
328 unsigned rx_len
= sizeof(*rx
);
331 tx
.port
= dln2
->port
;
333 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_GET_SUPPORTED_FRAME_SIZES
,
334 &tx
, sizeof(tx
), rx
, &rx_len
);
337 if (rx_len
< sizeof(*rx
))
339 if (rx
->count
> ARRAY_SIZE(rx
->frame_sizes
))
343 for (i
= 0; i
< rx
->count
; i
++)
344 *bpw_mask
|= BIT(rx
->frame_sizes
[i
] - 1);
346 dev_dbg(&dln2
->pdev
->dev
, "bpw_mask = 0x%X\n", *bpw_mask
);
352 * Copy the data to DLN2 buffer and change the byte order to LE, requested by
353 * DLN2 module. SPI core makes sure that the data length is a multiple of word
356 static int dln2_spi_copy_to_buf(u8
*dln2_buf
, const u8
*src
, u16 len
, u8 bpw
)
358 #ifdef __LITTLE_ENDIAN
359 memcpy(dln2_buf
, src
, len
);
362 memcpy(dln2_buf
, src
, len
);
363 } else if (bpw
<= 16) {
364 __le16
*d
= (__le16
*)dln2_buf
;
369 *d
++ = cpu_to_le16p(s
++);
371 __le32
*d
= (__le32
*)dln2_buf
;
376 *d
++ = cpu_to_le32p(s
++);
384 * Copy the data from DLN2 buffer and convert to CPU byte order since the DLN2
385 * buffer is LE ordered. SPI core makes sure that the data length is a multiple
386 * of word size. The RX dln2_buf is 2 byte aligned so, for BE, we have to make
387 * sure we avoid unaligned accesses for 32 bit case.
389 static int dln2_spi_copy_from_buf(u8
*dest
, const u8
*dln2_buf
, u16 len
, u8 bpw
)
391 #ifdef __LITTLE_ENDIAN
392 memcpy(dest
, dln2_buf
, len
);
395 memcpy(dest
, dln2_buf
, len
);
396 } else if (bpw
<= 16) {
397 u16
*d
= (u16
*)dest
;
398 __le16
*s
= (__le16
*)dln2_buf
;
402 *d
++ = le16_to_cpup(s
++);
404 u32
*d
= (u32
*)dest
;
405 __le32
*s
= (__le32
*)dln2_buf
;
409 *d
++ = get_unaligned_le32(s
++);
417 * Perform one write operation.
419 static int dln2_spi_write_one(struct dln2_spi
*dln2
, const u8
*data
,
420 u16 data_len
, u8 attr
)
426 u8 buf
[DLN2_SPI_MAX_XFER_SIZE
];
427 } __packed
*tx
= dln2
->buf
;
430 BUILD_BUG_ON(sizeof(*tx
) > DLN2_SPI_BUF_SIZE
);
432 if (data_len
> DLN2_SPI_MAX_XFER_SIZE
)
435 tx
->port
= dln2
->port
;
436 tx
->size
= cpu_to_le16(data_len
);
439 dln2_spi_copy_to_buf(tx
->buf
, data
, data_len
, dln2
->bpw
);
441 tx_len
= sizeof(*tx
) + data_len
- DLN2_SPI_MAX_XFER_SIZE
;
442 return dln2_transfer_tx(dln2
->pdev
, DLN2_SPI_WRITE
, tx
, tx_len
);
446 * Perform one read operation.
448 static int dln2_spi_read_one(struct dln2_spi
*dln2
, u8
*data
,
449 u16 data_len
, u8 attr
)
459 u8 buf
[DLN2_SPI_MAX_XFER_SIZE
];
460 } __packed
*rx
= dln2
->buf
;
461 unsigned rx_len
= sizeof(*rx
);
463 BUILD_BUG_ON(sizeof(*rx
) > DLN2_SPI_BUF_SIZE
);
465 if (data_len
> DLN2_SPI_MAX_XFER_SIZE
)
468 tx
.port
= dln2
->port
;
469 tx
.size
= cpu_to_le16(data_len
);
472 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_READ
, &tx
, sizeof(tx
),
476 if (rx_len
< sizeof(rx
->size
) + data_len
)
478 if (le16_to_cpu(rx
->size
) != data_len
)
481 dln2_spi_copy_from_buf(data
, rx
->buf
, data_len
, dln2
->bpw
);
487 * Perform one write & read operation.
489 static int dln2_spi_read_write_one(struct dln2_spi
*dln2
, const u8
*tx_data
,
490 u8
*rx_data
, u16 data_len
, u8 attr
)
497 u8 buf
[DLN2_SPI_MAX_XFER_SIZE
];
501 u8 buf
[DLN2_SPI_MAX_XFER_SIZE
];
503 unsigned tx_len
, rx_len
;
505 BUILD_BUG_ON(sizeof(*tx
) > DLN2_SPI_BUF_SIZE
||
506 sizeof(*rx
) > DLN2_SPI_BUF_SIZE
);
508 if (data_len
> DLN2_SPI_MAX_XFER_SIZE
)
512 * Since this is a pseudo full-duplex communication, we're perfectly
513 * safe to use the same buffer for both tx and rx. When DLN2 sends the
514 * response back, with the rx data, we don't need the tx buffer anymore.
519 tx
->port
= dln2
->port
;
520 tx
->size
= cpu_to_le16(data_len
);
523 dln2_spi_copy_to_buf(tx
->buf
, tx_data
, data_len
, dln2
->bpw
);
525 tx_len
= sizeof(*tx
) + data_len
- DLN2_SPI_MAX_XFER_SIZE
;
526 rx_len
= sizeof(*rx
);
528 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_READ_WRITE
, tx
, tx_len
,
532 if (rx_len
< sizeof(rx
->size
) + data_len
)
534 if (le16_to_cpu(rx
->size
) != data_len
)
537 dln2_spi_copy_from_buf(rx_data
, rx
->buf
, data_len
, dln2
->bpw
);
543 * Read/Write wrapper. It will automatically split an operation into multiple
544 * single ones due to device buffer constraints.
546 static int dln2_spi_rdwr(struct dln2_spi
*dln2
, const u8
*tx_data
,
547 u8
*rx_data
, u16 data_len
, u8 attr
)
552 u16 remaining
= data_len
;
556 if (remaining
> DLN2_SPI_MAX_XFER_SIZE
) {
557 len
= DLN2_SPI_MAX_XFER_SIZE
;
558 temp_attr
= DLN2_SPI_ATTR_LEAVE_SS_LOW
;
564 offset
= data_len
- remaining
;
566 if (tx_data
&& rx_data
) {
567 ret
= dln2_spi_read_write_one(dln2
,
571 } else if (tx_data
) {
572 ret
= dln2_spi_write_one(dln2
,
575 } else if (rx_data
) {
576 ret
= dln2_spi_read_one(dln2
,
592 static int dln2_spi_prepare_message(struct spi_controller
*host
,
593 struct spi_message
*message
)
596 struct dln2_spi
*dln2
= spi_controller_get_devdata(host
);
597 struct spi_device
*spi
= message
->spi
;
599 if (dln2
->cs
!= spi_get_chipselect(spi
, 0)) {
600 ret
= dln2_spi_cs_set_one(dln2
, spi_get_chipselect(spi
, 0));
604 dln2
->cs
= spi_get_chipselect(spi
, 0);
610 static int dln2_spi_transfer_setup(struct dln2_spi
*dln2
, u32 speed
,
614 bool bus_setup_change
;
616 bus_setup_change
= dln2
->speed
!= speed
|| dln2
->mode
!= mode
||
619 if (!bus_setup_change
)
622 ret
= dln2_spi_enable(dln2
, false);
626 if (dln2
->speed
!= speed
) {
627 ret
= dln2_spi_set_speed(dln2
, speed
);
634 if (dln2
->mode
!= mode
) {
635 ret
= dln2_spi_set_mode(dln2
, mode
& 0x3);
642 if (dln2
->bpw
!= bpw
) {
643 ret
= dln2_spi_set_bpw(dln2
, bpw
);
650 return dln2_spi_enable(dln2
, true);
653 static int dln2_spi_transfer_one(struct spi_controller
*host
,
654 struct spi_device
*spi
,
655 struct spi_transfer
*xfer
)
657 struct dln2_spi
*dln2
= spi_controller_get_devdata(host
);
661 status
= dln2_spi_transfer_setup(dln2
, xfer
->speed_hz
,
665 dev_err(&dln2
->pdev
->dev
, "Cannot setup transfer\n");
669 if (!xfer
->cs_change
&& !spi_transfer_is_last(host
, xfer
))
670 attr
= DLN2_SPI_ATTR_LEAVE_SS_LOW
;
672 status
= dln2_spi_rdwr(dln2
, xfer
->tx_buf
, xfer
->rx_buf
,
675 dev_err(&dln2
->pdev
->dev
, "write/read failed!\n");
680 static int dln2_spi_probe(struct platform_device
*pdev
)
682 struct spi_controller
*host
;
683 struct dln2_spi
*dln2
;
684 struct dln2_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
685 struct device
*dev
= &pdev
->dev
;
688 host
= spi_alloc_host(&pdev
->dev
, sizeof(*dln2
));
692 device_set_node(&host
->dev
, dev_fwnode(dev
));
694 platform_set_drvdata(pdev
, host
);
696 dln2
= spi_controller_get_devdata(host
);
698 dln2
->buf
= devm_kmalloc(&pdev
->dev
, DLN2_SPI_BUF_SIZE
, GFP_KERNEL
);
706 dln2
->port
= pdata
->port
;
707 /* cs/mode can never be 0xff, so the first transfer will set them */
711 /* disable SPI module before continuing with the setup */
712 ret
= dln2_spi_enable(dln2
, false);
714 dev_err(&pdev
->dev
, "Failed to disable SPI module\n");
718 ret
= dln2_spi_get_cs_num(dln2
, &host
->num_chipselect
);
720 dev_err(&pdev
->dev
, "Failed to get number of CS pins\n");
724 ret
= dln2_spi_get_speed_range(dln2
,
726 &host
->max_speed_hz
);
728 dev_err(&pdev
->dev
, "Failed to read bus min/max freqs\n");
732 ret
= dln2_spi_get_supported_frame_sizes(dln2
,
733 &host
->bits_per_word_mask
);
735 dev_err(&pdev
->dev
, "Failed to read supported frame sizes\n");
739 ret
= dln2_spi_cs_enable_all(dln2
, true);
741 dev_err(&pdev
->dev
, "Failed to enable CS pins\n");
746 host
->mode_bits
= SPI_CPOL
| SPI_CPHA
;
747 host
->prepare_message
= dln2_spi_prepare_message
;
748 host
->transfer_one
= dln2_spi_transfer_one
;
749 host
->auto_runtime_pm
= true;
751 /* enable SPI module, we're good to go */
752 ret
= dln2_spi_enable(dln2
, true);
754 dev_err(&pdev
->dev
, "Failed to enable SPI module\n");
758 pm_runtime_set_autosuspend_delay(&pdev
->dev
,
759 DLN2_RPM_AUTOSUSPEND_TIMEOUT
);
760 pm_runtime_use_autosuspend(&pdev
->dev
);
761 pm_runtime_set_active(&pdev
->dev
);
762 pm_runtime_enable(&pdev
->dev
);
764 ret
= devm_spi_register_controller(&pdev
->dev
, host
);
766 dev_err(&pdev
->dev
, "Failed to register host\n");
773 pm_runtime_disable(&pdev
->dev
);
774 pm_runtime_set_suspended(&pdev
->dev
);
776 if (dln2_spi_enable(dln2
, false) < 0)
777 dev_err(&pdev
->dev
, "Failed to disable SPI module\n");
779 spi_controller_put(host
);
784 static void dln2_spi_remove(struct platform_device
*pdev
)
786 struct spi_controller
*host
= platform_get_drvdata(pdev
);
787 struct dln2_spi
*dln2
= spi_controller_get_devdata(host
);
789 pm_runtime_disable(&pdev
->dev
);
791 if (dln2_spi_enable(dln2
, false) < 0)
792 dev_err(&pdev
->dev
, "Failed to disable SPI module\n");
795 #ifdef CONFIG_PM_SLEEP
796 static int dln2_spi_suspend(struct device
*dev
)
799 struct spi_controller
*host
= dev_get_drvdata(dev
);
800 struct dln2_spi
*dln2
= spi_controller_get_devdata(host
);
802 ret
= spi_controller_suspend(host
);
806 if (!pm_runtime_suspended(dev
)) {
807 ret
= dln2_spi_enable(dln2
, false);
813 * USB power may be cut off during sleep. Resetting the following
814 * parameters will force the board to be set up before first transfer.
824 static int dln2_spi_resume(struct device
*dev
)
827 struct spi_controller
*host
= dev_get_drvdata(dev
);
828 struct dln2_spi
*dln2
= spi_controller_get_devdata(host
);
830 if (!pm_runtime_suspended(dev
)) {
831 ret
= dln2_spi_cs_enable_all(dln2
, true);
835 ret
= dln2_spi_enable(dln2
, true);
840 return spi_controller_resume(host
);
842 #endif /* CONFIG_PM_SLEEP */
845 static int dln2_spi_runtime_suspend(struct device
*dev
)
847 struct spi_controller
*host
= dev_get_drvdata(dev
);
848 struct dln2_spi
*dln2
= spi_controller_get_devdata(host
);
850 return dln2_spi_enable(dln2
, false);
853 static int dln2_spi_runtime_resume(struct device
*dev
)
855 struct spi_controller
*host
= dev_get_drvdata(dev
);
856 struct dln2_spi
*dln2
= spi_controller_get_devdata(host
);
858 return dln2_spi_enable(dln2
, true);
860 #endif /* CONFIG_PM */
862 static const struct dev_pm_ops dln2_spi_pm
= {
863 SET_SYSTEM_SLEEP_PM_OPS(dln2_spi_suspend
, dln2_spi_resume
)
864 SET_RUNTIME_PM_OPS(dln2_spi_runtime_suspend
,
865 dln2_spi_runtime_resume
, NULL
)
868 static struct platform_driver spi_dln2_driver
= {
873 .probe
= dln2_spi_probe
,
874 .remove
= dln2_spi_remove
,
876 module_platform_driver(spi_dln2_driver
);
878 MODULE_DESCRIPTION("Driver for the Diolan DLN2 SPI host interface");
879 MODULE_AUTHOR("Laurentiu Palcu <laurentiu.palcu@intel.com>");
880 MODULE_LICENSE("GPL v2");
881 MODULE_ALIAS("platform:dln2-spi");