27 #include <linux/module.h>
28 #include <linux/kernel.h>
31 #include <linux/list.h>
49 #define hspi2info(h) (h->dev->platform_data)
79 if ((mask & hspi_read(hspi,
SPSR)) == val)
92 static int hspi_prepare_transfer(
struct spi_master *master)
94 struct hspi_priv *hspi = spi_master_get_devdata(master);
96 pm_runtime_get_sync(hspi->
dev);
102 struct hspi_priv *hspi = spi_master_get_devdata(master);
104 pm_runtime_put_sync(hspi->
dev);
108 static void hspi_hw_setup(
struct hspi_priv *hspi,
128 for (idiv_clk = 0x00; idiv_clk <= 0x3F; idiv_clk++) {
132 if (idiv_clk & (1 << 5))
138 rate /= (((idiv_clk & 0x1F) + 1) * 2) ;
141 tmp =
abs(target_rate - rate);
154 dev_dbg(dev,
"speed %d/%d\n", target_rate, best_rate);
156 hspi_write(hspi,
SPCR, spcr);
157 hspi_write(hspi,
SPSR, 0x0);
158 hspi_write(hspi,
SPSCR, 0x1);
161 static int hspi_transfer_one_message(
struct spi_master *master,
164 struct hspi_priv *hspi = spi_master_get_devdata(master);
174 hspi_hw_setup(hspi, msg, t);
176 for (i = 0; i < t->
len; i++) {
179 ret = hspi_status_check_timeout(hspi, 0x1, 0);
187 hspi_write(hspi,
SPTBR, tx);
190 ret = hspi_status_check_timeout(hspi, 0x4, 0x4);
194 rx = hspi_read(hspi,
SPRBR);
215 dev_err(dev,
"bits_per_word should be 8\n");
224 static void hspi_cleanup(
struct spi_device *spi)
249 dev_err(&pdev->
dev,
"spi_alloc_master error.\n");
255 dev_err(&pdev->
dev,
"shyway_clk is required\n");
260 hspi = spi_master_get_devdata(master);
268 res->
start, resource_size(res));
277 master->
setup = hspi_setup;
278 master->
cleanup = hspi_cleanup;
285 dev_err(&pdev->
dev,
"spi_register_master error.\n");
298 spi_master_put(master);
307 pm_runtime_disable(&pdev->
dev);