2 * Driver for the Diolan DLN-2 USB-SPI adapter
4 * Copyright (c) 2014 Intel Corporation
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/mfd/dln2.h>
15 #include <linux/spi/spi.h>
16 #include <linux/pm_runtime.h>
17 #include <asm/unaligned.h>
19 #define DLN2_SPI_MODULE_ID 0x02
20 #define DLN2_SPI_CMD(cmd) DLN2_CMD(cmd, DLN2_SPI_MODULE_ID)
23 #define DLN2_SPI_GET_PORT_COUNT DLN2_SPI_CMD(0x00)
24 #define DLN2_SPI_ENABLE DLN2_SPI_CMD(0x11)
25 #define DLN2_SPI_DISABLE DLN2_SPI_CMD(0x12)
26 #define DLN2_SPI_IS_ENABLED DLN2_SPI_CMD(0x13)
27 #define DLN2_SPI_SET_MODE DLN2_SPI_CMD(0x14)
28 #define DLN2_SPI_GET_MODE DLN2_SPI_CMD(0x15)
29 #define DLN2_SPI_SET_FRAME_SIZE DLN2_SPI_CMD(0x16)
30 #define DLN2_SPI_GET_FRAME_SIZE DLN2_SPI_CMD(0x17)
31 #define DLN2_SPI_SET_FREQUENCY DLN2_SPI_CMD(0x18)
32 #define DLN2_SPI_GET_FREQUENCY DLN2_SPI_CMD(0x19)
33 #define DLN2_SPI_READ_WRITE DLN2_SPI_CMD(0x1A)
34 #define DLN2_SPI_READ DLN2_SPI_CMD(0x1B)
35 #define DLN2_SPI_WRITE DLN2_SPI_CMD(0x1C)
36 #define DLN2_SPI_SET_DELAY_BETWEEN_SS DLN2_SPI_CMD(0x20)
37 #define DLN2_SPI_GET_DELAY_BETWEEN_SS DLN2_SPI_CMD(0x21)
38 #define DLN2_SPI_SET_DELAY_AFTER_SS DLN2_SPI_CMD(0x22)
39 #define DLN2_SPI_GET_DELAY_AFTER_SS DLN2_SPI_CMD(0x23)
40 #define DLN2_SPI_SET_DELAY_BETWEEN_FRAMES DLN2_SPI_CMD(0x24)
41 #define DLN2_SPI_GET_DELAY_BETWEEN_FRAMES DLN2_SPI_CMD(0x25)
42 #define DLN2_SPI_SET_SS DLN2_SPI_CMD(0x26)
43 #define DLN2_SPI_GET_SS DLN2_SPI_CMD(0x27)
44 #define DLN2_SPI_RELEASE_SS DLN2_SPI_CMD(0x28)
45 #define DLN2_SPI_SS_VARIABLE_ENABLE DLN2_SPI_CMD(0x2B)
46 #define DLN2_SPI_SS_VARIABLE_DISABLE DLN2_SPI_CMD(0x2C)
47 #define DLN2_SPI_SS_VARIABLE_IS_ENABLED DLN2_SPI_CMD(0x2D)
48 #define DLN2_SPI_SS_AAT_ENABLE DLN2_SPI_CMD(0x2E)
49 #define DLN2_SPI_SS_AAT_DISABLE DLN2_SPI_CMD(0x2F)
50 #define DLN2_SPI_SS_AAT_IS_ENABLED DLN2_SPI_CMD(0x30)
51 #define DLN2_SPI_SS_BETWEEN_FRAMES_ENABLE DLN2_SPI_CMD(0x31)
52 #define DLN2_SPI_SS_BETWEEN_FRAMES_DISABLE DLN2_SPI_CMD(0x32)
53 #define DLN2_SPI_SS_BETWEEN_FRAMES_IS_ENABLED DLN2_SPI_CMD(0x33)
54 #define DLN2_SPI_SET_CPHA DLN2_SPI_CMD(0x34)
55 #define DLN2_SPI_GET_CPHA DLN2_SPI_CMD(0x35)
56 #define DLN2_SPI_SET_CPOL DLN2_SPI_CMD(0x36)
57 #define DLN2_SPI_GET_CPOL DLN2_SPI_CMD(0x37)
58 #define DLN2_SPI_SS_MULTI_ENABLE DLN2_SPI_CMD(0x38)
59 #define DLN2_SPI_SS_MULTI_DISABLE DLN2_SPI_CMD(0x39)
60 #define DLN2_SPI_SS_MULTI_IS_ENABLED DLN2_SPI_CMD(0x3A)
61 #define DLN2_SPI_GET_SUPPORTED_MODES DLN2_SPI_CMD(0x40)
62 #define DLN2_SPI_GET_SUPPORTED_CPHA_VALUES DLN2_SPI_CMD(0x41)
63 #define DLN2_SPI_GET_SUPPORTED_CPOL_VALUES DLN2_SPI_CMD(0x42)
64 #define DLN2_SPI_GET_SUPPORTED_FRAME_SIZES DLN2_SPI_CMD(0x43)
65 #define DLN2_SPI_GET_SS_COUNT DLN2_SPI_CMD(0x44)
66 #define DLN2_SPI_GET_MIN_FREQUENCY DLN2_SPI_CMD(0x45)
67 #define DLN2_SPI_GET_MAX_FREQUENCY DLN2_SPI_CMD(0x46)
68 #define DLN2_SPI_GET_MIN_DELAY_BETWEEN_SS DLN2_SPI_CMD(0x47)
69 #define DLN2_SPI_GET_MAX_DELAY_BETWEEN_SS DLN2_SPI_CMD(0x48)
70 #define DLN2_SPI_GET_MIN_DELAY_AFTER_SS DLN2_SPI_CMD(0x49)
71 #define DLN2_SPI_GET_MAX_DELAY_AFTER_SS DLN2_SPI_CMD(0x4A)
72 #define DLN2_SPI_GET_MIN_DELAY_BETWEEN_FRAMES DLN2_SPI_CMD(0x4B)
73 #define DLN2_SPI_GET_MAX_DELAY_BETWEEN_FRAMES DLN2_SPI_CMD(0x4C)
75 #define DLN2_SPI_MAX_XFER_SIZE 256
76 #define DLN2_SPI_BUF_SIZE (DLN2_SPI_MAX_XFER_SIZE + 16)
77 #define DLN2_SPI_ATTR_LEAVE_SS_LOW BIT(0)
78 #define DLN2_TRANSFERS_WAIT_COMPLETE 1
79 #define DLN2_TRANSFERS_CANCEL 0
80 #define DLN2_RPM_AUTOSUSPEND_TIMEOUT 2000
83 struct platform_device
*pdev
;
84 struct spi_master
*master
;
88 * This buffer will be used mainly for read/write operations. Since
89 * they're quite large, we cannot use the stack. Protection is not
90 * needed because all SPI communication is serialized by the SPI core.
101 * Enable/Disable SPI module. The disable command will wait for transfers to
104 static int dln2_spi_enable(struct dln2_spi
*dln2
, bool enable
)
109 u8 wait_for_completion
;
111 unsigned len
= sizeof(tx
);
113 tx
.port
= dln2
->port
;
116 cmd
= DLN2_SPI_ENABLE
;
117 len
-= sizeof(tx
.wait_for_completion
);
119 tx
.wait_for_completion
= DLN2_TRANSFERS_WAIT_COMPLETE
;
120 cmd
= DLN2_SPI_DISABLE
;
123 return dln2_transfer_tx(dln2
->pdev
, cmd
, &tx
, len
);
127 * Select/unselect multiple CS lines. The selected lines will be automatically
128 * toggled LOW/HIGH by the board firmware during transfers, provided they're
131 * Ex: cs_mask = 0x03 -> CS0 & CS1 will be selected and the next WR/RD operation
132 * will toggle the lines LOW/HIGH automatically.
134 static int dln2_spi_cs_set(struct dln2_spi
*dln2
, u8 cs_mask
)
141 tx
.port
= dln2
->port
;
144 * According to Diolan docs, "a slave device can be selected by changing
145 * the corresponding bit value to 0". The rest must be set to 1. Hence
146 * the bitwise NOT in front.
150 return dln2_transfer_tx(dln2
->pdev
, DLN2_SPI_SET_SS
, &tx
, sizeof(tx
));
154 * Select one CS line. The other lines will be un-selected.
156 static int dln2_spi_cs_set_one(struct dln2_spi
*dln2
, u8 cs
)
158 return dln2_spi_cs_set(dln2
, BIT(cs
));
162 * Enable/disable CS lines for usage. The module has to be disabled first.
164 static int dln2_spi_cs_enable(struct dln2_spi
*dln2
, u8 cs_mask
, bool enable
)
172 tx
.port
= dln2
->port
;
174 cmd
= enable
? DLN2_SPI_SS_MULTI_ENABLE
: DLN2_SPI_SS_MULTI_DISABLE
;
176 return dln2_transfer_tx(dln2
->pdev
, cmd
, &tx
, sizeof(tx
));
179 static int dln2_spi_cs_enable_all(struct dln2_spi
*dln2
, bool enable
)
181 u8 cs_mask
= GENMASK(dln2
->master
->num_chipselect
- 1, 0);
183 return dln2_spi_cs_enable(dln2
, cs_mask
, enable
);
186 static int dln2_spi_get_cs_num(struct dln2_spi
*dln2
, u16
*cs_num
)
195 unsigned rx_len
= sizeof(rx
);
197 tx
.port
= dln2
->port
;
198 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_GET_SS_COUNT
, &tx
, sizeof(tx
),
202 if (rx_len
< sizeof(rx
))
205 *cs_num
= le16_to_cpu(rx
.cs_count
);
207 dev_dbg(&dln2
->pdev
->dev
, "cs_num = %d\n", *cs_num
);
212 static int dln2_spi_get_speed(struct dln2_spi
*dln2
, u16 cmd
, u32
*freq
)
221 unsigned rx_len
= sizeof(rx
);
223 tx
.port
= dln2
->port
;
225 ret
= dln2_transfer(dln2
->pdev
, cmd
, &tx
, sizeof(tx
), &rx
, &rx_len
);
228 if (rx_len
< sizeof(rx
))
231 *freq
= le32_to_cpu(rx
.speed
);
237 * Get bus min/max frequencies.
239 static int dln2_spi_get_speed_range(struct dln2_spi
*dln2
, u32
*fmin
, u32
*fmax
)
243 ret
= dln2_spi_get_speed(dln2
, DLN2_SPI_GET_MIN_FREQUENCY
, fmin
);
247 ret
= dln2_spi_get_speed(dln2
, DLN2_SPI_GET_MAX_FREQUENCY
, fmax
);
251 dev_dbg(&dln2
->pdev
->dev
, "freq_min = %d, freq_max = %d\n",
258 * Set the bus speed. The module will automatically round down to the closest
259 * available frequency and returns it. The module has to be disabled first.
261 static int dln2_spi_set_speed(struct dln2_spi
*dln2
, u32 speed
)
271 int rx_len
= sizeof(rx
);
273 tx
.port
= dln2
->port
;
274 tx
.speed
= cpu_to_le32(speed
);
276 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_SET_FREQUENCY
, &tx
, sizeof(tx
),
280 if (rx_len
< sizeof(rx
))
287 * Change CPOL & CPHA. The module has to be disabled first.
289 static int dln2_spi_set_mode(struct dln2_spi
*dln2
, u8 mode
)
296 tx
.port
= dln2
->port
;
299 return dln2_transfer_tx(dln2
->pdev
, DLN2_SPI_SET_MODE
, &tx
, sizeof(tx
));
303 * Change frame size. The module has to be disabled first.
305 static int dln2_spi_set_bpw(struct dln2_spi
*dln2
, u8 bpw
)
312 tx
.port
= dln2
->port
;
315 return dln2_transfer_tx(dln2
->pdev
, DLN2_SPI_SET_FRAME_SIZE
,
319 static int dln2_spi_get_supported_frame_sizes(struct dln2_spi
*dln2
,
330 unsigned rx_len
= sizeof(*rx
);
333 tx
.port
= dln2
->port
;
335 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_GET_SUPPORTED_FRAME_SIZES
,
336 &tx
, sizeof(tx
), rx
, &rx_len
);
339 if (rx_len
< sizeof(*rx
))
341 if (rx
->count
> ARRAY_SIZE(rx
->frame_sizes
))
345 for (i
= 0; i
< rx
->count
; i
++)
346 *bpw_mask
|= BIT(rx
->frame_sizes
[i
] - 1);
348 dev_dbg(&dln2
->pdev
->dev
, "bpw_mask = 0x%X\n", *bpw_mask
);
354 * Copy the data to DLN2 buffer and change the byte order to LE, requested by
355 * DLN2 module. SPI core makes sure that the data length is a multiple of word
358 static int dln2_spi_copy_to_buf(u8
*dln2_buf
, const u8
*src
, u16 len
, u8 bpw
)
360 #ifdef __LITTLE_ENDIAN
361 memcpy(dln2_buf
, src
, len
);
364 memcpy(dln2_buf
, src
, len
);
365 } else if (bpw
<= 16) {
366 __le16
*d
= (__le16
*)dln2_buf
;
371 *d
++ = cpu_to_le16p(s
++);
373 __le32
*d
= (__le32
*)dln2_buf
;
378 *d
++ = cpu_to_le32p(s
++);
386 * Copy the data from DLN2 buffer and convert to CPU byte order since the DLN2
387 * buffer is LE ordered. SPI core makes sure that the data length is a multiple
388 * of word size. The RX dln2_buf is 2 byte aligned so, for BE, we have to make
389 * sure we avoid unaligned accesses for 32 bit case.
391 static int dln2_spi_copy_from_buf(u8
*dest
, const u8
*dln2_buf
, u16 len
, u8 bpw
)
393 #ifdef __LITTLE_ENDIAN
394 memcpy(dest
, dln2_buf
, len
);
397 memcpy(dest
, dln2_buf
, len
);
398 } else if (bpw
<= 16) {
399 u16
*d
= (u16
*)dest
;
400 __le16
*s
= (__le16
*)dln2_buf
;
404 *d
++ = le16_to_cpup(s
++);
406 u32
*d
= (u32
*)dest
;
407 __le32
*s
= (__le32
*)dln2_buf
;
411 *d
++ = get_unaligned_le32(s
++);
419 * Perform one write operation.
421 static int dln2_spi_write_one(struct dln2_spi
*dln2
, const u8
*data
,
422 u16 data_len
, u8 attr
)
428 u8 buf
[DLN2_SPI_MAX_XFER_SIZE
];
429 } __packed
*tx
= dln2
->buf
;
432 BUILD_BUG_ON(sizeof(*tx
) > DLN2_SPI_BUF_SIZE
);
434 if (data_len
> DLN2_SPI_MAX_XFER_SIZE
)
437 tx
->port
= dln2
->port
;
438 tx
->size
= cpu_to_le16(data_len
);
441 dln2_spi_copy_to_buf(tx
->buf
, data
, data_len
, dln2
->bpw
);
443 tx_len
= sizeof(*tx
) + data_len
- DLN2_SPI_MAX_XFER_SIZE
;
444 return dln2_transfer_tx(dln2
->pdev
, DLN2_SPI_WRITE
, tx
, tx_len
);
448 * Perform one read operation.
450 static int dln2_spi_read_one(struct dln2_spi
*dln2
, u8
*data
,
451 u16 data_len
, u8 attr
)
461 u8 buf
[DLN2_SPI_MAX_XFER_SIZE
];
462 } __packed
*rx
= dln2
->buf
;
463 unsigned rx_len
= sizeof(*rx
);
465 BUILD_BUG_ON(sizeof(*rx
) > DLN2_SPI_BUF_SIZE
);
467 if (data_len
> DLN2_SPI_MAX_XFER_SIZE
)
470 tx
.port
= dln2
->port
;
471 tx
.size
= cpu_to_le16(data_len
);
474 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_READ
, &tx
, sizeof(tx
),
478 if (rx_len
< sizeof(rx
->size
) + data_len
)
480 if (le16_to_cpu(rx
->size
) != data_len
)
483 dln2_spi_copy_from_buf(data
, rx
->buf
, data_len
, dln2
->bpw
);
489 * Perform one write & read operation.
491 static int dln2_spi_read_write_one(struct dln2_spi
*dln2
, const u8
*tx_data
,
492 u8
*rx_data
, u16 data_len
, u8 attr
)
499 u8 buf
[DLN2_SPI_MAX_XFER_SIZE
];
503 u8 buf
[DLN2_SPI_MAX_XFER_SIZE
];
505 unsigned tx_len
, rx_len
;
507 BUILD_BUG_ON(sizeof(*tx
) > DLN2_SPI_BUF_SIZE
||
508 sizeof(*rx
) > DLN2_SPI_BUF_SIZE
);
510 if (data_len
> DLN2_SPI_MAX_XFER_SIZE
)
514 * Since this is a pseudo full-duplex communication, we're perfectly
515 * safe to use the same buffer for both tx and rx. When DLN2 sends the
516 * response back, with the rx data, we don't need the tx buffer anymore.
521 tx
->port
= dln2
->port
;
522 tx
->size
= cpu_to_le16(data_len
);
525 dln2_spi_copy_to_buf(tx
->buf
, tx_data
, data_len
, dln2
->bpw
);
527 tx_len
= sizeof(*tx
) + data_len
- DLN2_SPI_MAX_XFER_SIZE
;
528 rx_len
= sizeof(*rx
);
530 ret
= dln2_transfer(dln2
->pdev
, DLN2_SPI_READ_WRITE
, tx
, tx_len
,
534 if (rx_len
< sizeof(rx
->size
) + data_len
)
536 if (le16_to_cpu(rx
->size
) != data_len
)
539 dln2_spi_copy_from_buf(rx_data
, rx
->buf
, data_len
, dln2
->bpw
);
545 * Read/Write wrapper. It will automatically split an operation into multiple
546 * single ones due to device buffer constraints.
548 static int dln2_spi_rdwr(struct dln2_spi
*dln2
, const u8
*tx_data
,
549 u8
*rx_data
, u16 data_len
, u8 attr
) {
553 u16 remaining
= data_len
;
557 if (remaining
> DLN2_SPI_MAX_XFER_SIZE
) {
558 len
= DLN2_SPI_MAX_XFER_SIZE
;
559 temp_attr
= DLN2_SPI_ATTR_LEAVE_SS_LOW
;
565 offset
= data_len
- remaining
;
567 if (tx_data
&& rx_data
) {
568 ret
= dln2_spi_read_write_one(dln2
,
572 } else if (tx_data
) {
573 ret
= dln2_spi_write_one(dln2
,
576 } else if (rx_data
) {
577 ret
= dln2_spi_read_one(dln2
,
593 static int dln2_spi_prepare_message(struct spi_master
*master
,
594 struct spi_message
*message
)
597 struct dln2_spi
*dln2
= spi_master_get_devdata(master
);
598 struct spi_device
*spi
= message
->spi
;
600 if (dln2
->cs
!= spi
->chip_select
) {
601 ret
= dln2_spi_cs_set_one(dln2
, spi
->chip_select
);
605 dln2
->cs
= spi
->chip_select
;
611 static int dln2_spi_transfer_setup(struct dln2_spi
*dln2
, u32 speed
,
615 bool bus_setup_change
;
617 bus_setup_change
= dln2
->speed
!= speed
|| dln2
->mode
!= mode
||
620 if (!bus_setup_change
)
623 ret
= dln2_spi_enable(dln2
, false);
627 if (dln2
->speed
!= speed
) {
628 ret
= dln2_spi_set_speed(dln2
, speed
);
635 if (dln2
->mode
!= mode
) {
636 ret
= dln2_spi_set_mode(dln2
, mode
& 0x3);
643 if (dln2
->bpw
!= bpw
) {
644 ret
= dln2_spi_set_bpw(dln2
, bpw
);
651 return dln2_spi_enable(dln2
, true);
654 static int dln2_spi_transfer_one(struct spi_master
*master
,
655 struct spi_device
*spi
,
656 struct spi_transfer
*xfer
)
658 struct dln2_spi
*dln2
= spi_master_get_devdata(master
);
662 status
= dln2_spi_transfer_setup(dln2
, xfer
->speed_hz
,
666 dev_err(&dln2
->pdev
->dev
, "Cannot setup transfer\n");
670 if (!xfer
->cs_change
&& !spi_transfer_is_last(master
, xfer
))
671 attr
= DLN2_SPI_ATTR_LEAVE_SS_LOW
;
673 status
= dln2_spi_rdwr(dln2
, xfer
->tx_buf
, xfer
->rx_buf
,
676 dev_err(&dln2
->pdev
->dev
, "write/read failed!\n");
681 static int dln2_spi_probe(struct platform_device
*pdev
)
683 struct spi_master
*master
;
684 struct dln2_spi
*dln2
;
685 struct dln2_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
688 master
= spi_alloc_master(&pdev
->dev
, sizeof(*dln2
));
692 platform_set_drvdata(pdev
, master
);
694 dln2
= spi_master_get_devdata(master
);
696 dln2
->buf
= devm_kmalloc(&pdev
->dev
, DLN2_SPI_BUF_SIZE
, GFP_KERNEL
);
699 goto exit_free_master
;
702 dln2
->master
= master
;
704 dln2
->port
= pdata
->port
;
705 /* cs/mode can never be 0xff, so the first transfer will set them */
709 /* disable SPI module before continuing with the setup */
710 ret
= dln2_spi_enable(dln2
, false);
712 dev_err(&pdev
->dev
, "Failed to disable SPI module\n");
713 goto exit_free_master
;
716 ret
= dln2_spi_get_cs_num(dln2
, &master
->num_chipselect
);
718 dev_err(&pdev
->dev
, "Failed to get number of CS pins\n");
719 goto exit_free_master
;
722 ret
= dln2_spi_get_speed_range(dln2
,
723 &master
->min_speed_hz
,
724 &master
->max_speed_hz
);
726 dev_err(&pdev
->dev
, "Failed to read bus min/max freqs\n");
727 goto exit_free_master
;
730 ret
= dln2_spi_get_supported_frame_sizes(dln2
,
731 &master
->bits_per_word_mask
);
733 dev_err(&pdev
->dev
, "Failed to read supported frame sizes\n");
734 goto exit_free_master
;
737 ret
= dln2_spi_cs_enable_all(dln2
, true);
739 dev_err(&pdev
->dev
, "Failed to enable CS pins\n");
740 goto exit_free_master
;
743 master
->bus_num
= -1;
744 master
->mode_bits
= SPI_CPOL
| SPI_CPHA
;
745 master
->prepare_message
= dln2_spi_prepare_message
;
746 master
->transfer_one
= dln2_spi_transfer_one
;
747 master
->auto_runtime_pm
= true;
749 /* enable SPI module, we're good to go */
750 ret
= dln2_spi_enable(dln2
, true);
752 dev_err(&pdev
->dev
, "Failed to enable SPI module\n");
753 goto exit_free_master
;
756 pm_runtime_set_autosuspend_delay(&pdev
->dev
,
757 DLN2_RPM_AUTOSUSPEND_TIMEOUT
);
758 pm_runtime_use_autosuspend(&pdev
->dev
);
759 pm_runtime_set_active(&pdev
->dev
);
760 pm_runtime_enable(&pdev
->dev
);
762 ret
= devm_spi_register_master(&pdev
->dev
, master
);
764 dev_err(&pdev
->dev
, "Failed to register master\n");
771 pm_runtime_disable(&pdev
->dev
);
772 pm_runtime_set_suspended(&pdev
->dev
);
774 if (dln2_spi_enable(dln2
, false) < 0)
775 dev_err(&pdev
->dev
, "Failed to disable SPI module\n");
777 spi_master_put(master
);
782 static int dln2_spi_remove(struct platform_device
*pdev
)
784 struct spi_master
*master
= spi_master_get(platform_get_drvdata(pdev
));
785 struct dln2_spi
*dln2
= spi_master_get_devdata(master
);
787 pm_runtime_disable(&pdev
->dev
);
789 if (dln2_spi_enable(dln2
, false) < 0)
790 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_master
*master
= dev_get_drvdata(dev
);
800 struct dln2_spi
*dln2
= spi_master_get_devdata(master
);
802 ret
= spi_master_suspend(master
);
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_master
*master
= dev_get_drvdata(dev
);
828 struct dln2_spi
*dln2
= spi_master_get_devdata(master
);
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_master_resume(master
);
842 #endif /* CONFIG_PM_SLEEP */
845 static int dln2_spi_runtime_suspend(struct device
*dev
)
847 struct spi_master
*master
= dev_get_drvdata(dev
);
848 struct dln2_spi
*dln2
= spi_master_get_devdata(master
);
850 return dln2_spi_enable(dln2
, false);
853 static int dln2_spi_runtime_resume(struct device
*dev
)
855 struct spi_master
*master
= dev_get_drvdata(dev
);
856 struct dln2_spi
*dln2
= spi_master_get_devdata(master
);
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 master interface");
879 MODULE_AUTHOR("Laurentiu Palcu <laurentiu.palcu@intel.com>");
880 MODULE_LICENSE("GPL v2");
881 MODULE_ALIAS("platform:dln2-spi");