1 // SPDX-License-Identifier: GPL-2.0
4 * Sony CXD2880 DVB-T2/T tuner + demodulator driver
7 * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
10 #include <linux/spi/spi.h>
12 #include "cxd2880_spi_device.h"
14 static int cxd2880_spi_device_write(struct cxd2880_spi
*spi
,
15 const u8
*data
, u32 size
)
17 struct cxd2880_spi_device
*spi_device
= NULL
;
18 struct spi_message msg
;
19 struct spi_transfer tx
;
22 if (!spi
|| !spi
->user
|| !data
|| size
== 0)
25 spi_device
= spi
->user
;
27 memset(&tx
, 0, sizeof(tx
));
31 spi_message_init(&msg
);
32 spi_message_add_tail(&tx
, &msg
);
33 result
= spi_sync(spi_device
->spi
, &msg
);
41 static int cxd2880_spi_device_write_read(struct cxd2880_spi
*spi
,
47 struct cxd2880_spi_device
*spi_device
= NULL
;
50 if (!spi
|| !spi
->user
|| !tx_data
||
51 !tx_size
|| !rx_data
|| !rx_size
)
54 spi_device
= spi
->user
;
56 result
= spi_write_then_read(spi_device
->spi
, tx_data
,
57 tx_size
, rx_data
, rx_size
);
65 cxd2880_spi_device_initialize(struct cxd2880_spi_device
*spi_device
,
66 enum cxd2880_spi_mode mode
,
70 struct spi_device
*spi
= spi_device
->spi
;
73 case CXD2880_SPI_MODE_0
:
74 spi
->mode
= SPI_MODE_0
;
76 case CXD2880_SPI_MODE_1
:
77 spi
->mode
= SPI_MODE_1
;
79 case CXD2880_SPI_MODE_2
:
80 spi
->mode
= SPI_MODE_2
;
82 case CXD2880_SPI_MODE_3
:
83 spi
->mode
= SPI_MODE_3
;
89 spi
->max_speed_hz
= speed_hz
;
90 spi
->bits_per_word
= 8;
91 result
= spi_setup(spi
);
93 pr_err("spi_setup failed %d\n", result
);
100 int cxd2880_spi_device_create_spi(struct cxd2880_spi
*spi
,
101 struct cxd2880_spi_device
*spi_device
)
103 if (!spi
|| !spi_device
)
107 spi
->write
= cxd2880_spi_device_write
;
108 spi
->write_read
= cxd2880_spi_device_write_read
;
110 spi
->user
= spi_device
;