1 // SPDX-License-Identifier: GPL-2.0
4 * Sony CXD2880 DVB-T2/T tuner + demodulator driver
5 * I/O interface via SPI
7 * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
10 #include "cxd2880_devio_spi.h"
12 #define BURST_WRITE_MAX 128
14 static int cxd2880_io_spi_read_reg(struct cxd2880_io
*io
,
15 enum cxd2880_io_tgt tgt
,
16 u8 sub_address
, u8
*data
,
20 struct cxd2880_spi
*spi
= NULL
;
22 u8
*read_data_top
= data
;
24 if (!io
|| !io
->if_object
|| !data
)
27 if (sub_address
+ size
> 0x100)
32 if (tgt
== CXD2880_IO_TGT_SYS
)
42 send_data
[1] = sub_address
;
49 spi
->write_read(spi
, send_data
, sizeof(send_data
),
50 read_data_top
, send_data
[2]);
54 sub_address
+= send_data
[2];
55 read_data_top
+= send_data
[2];
62 static int cxd2880_io_spi_write_reg(struct cxd2880_io
*io
,
63 enum cxd2880_io_tgt tgt
,
65 const u8
*data
, u32 size
)
68 struct cxd2880_spi
*spi
= NULL
;
69 u8 send_data
[BURST_WRITE_MAX
+ 4];
70 const u8
*write_data_top
= data
;
72 if (!io
|| !io
->if_object
|| !data
)
75 if (size
> BURST_WRITE_MAX
)
78 if (sub_address
+ size
> 0x100)
83 if (tgt
== CXD2880_IO_TGT_SYS
)
89 send_data
[1] = sub_address
;
95 memcpy(&send_data
[3], write_data_top
, send_data
[2]);
97 if (tgt
== CXD2880_IO_TGT_SYS
) {
98 send_data
[3 + send_data
[2]] = 0x00;
99 ret
= spi
->write(spi
, send_data
, send_data
[2] + 4);
101 ret
= spi
->write(spi
, send_data
, send_data
[2] + 3);
106 sub_address
+= send_data
[2];
107 write_data_top
+= send_data
[2];
108 size
-= send_data
[2];
114 int cxd2880_io_spi_create(struct cxd2880_io
*io
,
115 struct cxd2880_spi
*spi
, u8 slave_select
)
120 io
->read_regs
= cxd2880_io_spi_read_reg
;
121 io
->write_regs
= cxd2880_io_spi_write_reg
;
122 io
->write_reg
= cxd2880_io_common_write_one_reg
;
124 io
->i2c_address_sys
= 0;
125 io
->i2c_address_demod
= 0;
126 io
->slave_select
= slave_select
;