Blame view
drivers/spi/spi-clps711x.c
4.04 KB
2874c5fd2 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
161b96c38 spi/clps711x: New... |
2 3 4 |
/* * CLPS711X SPI bus driver * |
6acaadc85 spi: clps711x: Dr... |
5 |
* Copyright (C) 2012-2016 Alexander Shiyan <shc_work@mail.ru> |
161b96c38 spi/clps711x: New... |
6 7 8 9 |
*/ #include <linux/io.h> #include <linux/clk.h> |
054320b25 spi: clps711x: Co... |
10 |
#include <linux/gpio/consumer.h> |
161b96c38 spi/clps711x: New... |
11 12 13 |
#include <linux/module.h> #include <linux/interrupt.h> #include <linux/platform_device.h> |
3dc925945 spi: clps711x: Re... |
14 15 16 |
#include <linux/regmap.h> #include <linux/mfd/syscon.h> #include <linux/mfd/syscon/clps711x.h> |
161b96c38 spi/clps711x: New... |
17 |
#include <linux/spi/spi.h> |
161b96c38 spi/clps711x: New... |
18 |
|
6acaadc85 spi: clps711x: Dr... |
19 |
#define DRIVER_NAME "clps711x-spi" |
161b96c38 spi/clps711x: New... |
20 |
|
3dc925945 spi: clps711x: Re... |
21 22 |
#define SYNCIO_FRMLEN(x) ((x) << 8) #define SYNCIO_TXFRMEN (1 << 14) |
161b96c38 spi/clps711x: New... |
23 |
struct spi_clps711x_data { |
3dc925945 spi: clps711x: Re... |
24 25 |
void __iomem *syncio; struct regmap *syscon; |
161b96c38 spi/clps711x: New... |
26 |
struct clk *spi_clk; |
161b96c38 spi/clps711x: New... |
27 28 29 |
u8 *tx_buf; u8 *rx_buf; |
8dda9d9a4 spi: clps711x: Ad... |
30 |
unsigned int bpw; |
161b96c38 spi/clps711x: New... |
31 |
int len; |
161b96c38 spi/clps711x: New... |
32 |
}; |
bf5c2e270 spi: clps711x: Re... |
33 34 |
static int spi_clps711x_prepare_message(struct spi_master *master, struct spi_message *msg) |
161b96c38 spi/clps711x: New... |
35 |
{ |
3dc925945 spi: clps711x: Re... |
36 |
struct spi_clps711x_data *hw = spi_master_get_devdata(master); |
8dda9d9a4 spi: clps711x: Ad... |
37 |
struct spi_device *spi = msg->spi; |
161b96c38 spi/clps711x: New... |
38 |
|
3dc925945 spi: clps711x: Re... |
39 40 41 42 |
/* Setup mode for transfer */ return regmap_update_bits(hw->syscon, SYSCON_OFFSET, SYSCON3_ADCCKNSEN, (spi->mode & SPI_CPHA) ? SYSCON3_ADCCKNSEN : 0); |
bf5c2e270 spi: clps711x: Re... |
43 |
} |
161b96c38 spi/clps711x: New... |
44 |
|
bf5c2e270 spi: clps711x: Re... |
45 46 47 48 49 50 |
static int spi_clps711x_transfer_one(struct spi_master *master, struct spi_device *spi, struct spi_transfer *xfer) { struct spi_clps711x_data *hw = spi_master_get_devdata(master); u8 data; |
161b96c38 spi/clps711x: New... |
51 |
|
a5b4b234e spi: clps711x: Mi... |
52 |
clk_set_rate(hw->spi_clk, xfer->speed_hz ? : spi->max_speed_hz); |
161b96c38 spi/clps711x: New... |
53 |
|
bf5c2e270 spi: clps711x: Re... |
54 |
hw->len = xfer->len; |
bed890b43 spi: clps711x: Re... |
55 |
hw->bpw = xfer->bits_per_word; |
bf5c2e270 spi: clps711x: Re... |
56 57 |
hw->tx_buf = (u8 *)xfer->tx_buf; hw->rx_buf = (u8 *)xfer->rx_buf; |
161b96c38 spi/clps711x: New... |
58 |
|
bf5c2e270 spi: clps711x: Re... |
59 60 |
/* Initiate transfer */ data = hw->tx_buf ? *hw->tx_buf++ : 0; |
3dc925945 spi: clps711x: Re... |
61 |
writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, hw->syncio); |
bf5c2e270 spi: clps711x: Re... |
62 |
return 1; |
161b96c38 spi/clps711x: New... |
63 64 65 66 |
} static irqreturn_t spi_clps711x_isr(int irq, void *dev_id) { |
bf5c2e270 spi: clps711x: Re... |
67 68 |
struct spi_master *master = dev_id; struct spi_clps711x_data *hw = spi_master_get_devdata(master); |
c7a26f121 spi: clps711x: Si... |
69 |
u8 data; |
161b96c38 spi/clps711x: New... |
70 71 |
/* Handle RX */ |
3dc925945 spi: clps711x: Re... |
72 |
data = readb(hw->syncio); |
161b96c38 spi/clps711x: New... |
73 |
if (hw->rx_buf) |
c7a26f121 spi: clps711x: Si... |
74 |
*hw->rx_buf++ = data; |
161b96c38 spi/clps711x: New... |
75 76 |
/* Handle TX */ |
c7a26f121 spi: clps711x: Si... |
77 78 |
if (--hw->len > 0) { data = hw->tx_buf ? *hw->tx_buf++ : 0; |
3dc925945 spi: clps711x: Re... |
79 80 |
writel(data | SYNCIO_FRMLEN(hw->bpw) | SYNCIO_TXFRMEN, hw->syncio); |
161b96c38 spi/clps711x: New... |
81 |
} else |
bf5c2e270 spi: clps711x: Re... |
82 |
spi_finalize_current_transfer(master); |
161b96c38 spi/clps711x: New... |
83 84 85 |
return IRQ_HANDLED; } |
fd4a319bc spi: Remove HOTPL... |
86 |
static int spi_clps711x_probe(struct platform_device *pdev) |
161b96c38 spi/clps711x: New... |
87 |
{ |
161b96c38 spi/clps711x: New... |
88 |
struct spi_clps711x_data *hw; |
3dc925945 spi: clps711x: Re... |
89 |
struct spi_master *master; |
6acaadc85 spi: clps711x: Dr... |
90 |
int irq, ret; |
161b96c38 spi/clps711x: New... |
91 |
|
3dc925945 spi: clps711x: Re... |
92 93 94 |
irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; |
3e9ea4b4d spi: clps711x: Us... |
95 96 |
master = spi_alloc_master(&pdev->dev, sizeof(*hw)); if (!master) |
161b96c38 spi/clps711x: New... |
97 |
return -ENOMEM; |
3e9ea4b4d spi: clps711x: Us... |
98 |
|
054320b25 spi: clps711x: Co... |
99 |
master->use_gpio_descriptors = true; |
6acaadc85 spi: clps711x: Dr... |
100 |
master->bus_num = -1; |
161b96c38 spi/clps711x: New... |
101 |
master->mode_bits = SPI_CPHA | SPI_CS_HIGH; |
8dda9d9a4 spi: clps711x: Ad... |
102 |
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 8); |
6acaadc85 spi: clps711x: Dr... |
103 |
master->dev.of_node = pdev->dev.of_node; |
bf5c2e270 spi: clps711x: Re... |
104 105 |
master->prepare_message = spi_clps711x_prepare_message; master->transfer_one = spi_clps711x_transfer_one; |
161b96c38 spi/clps711x: New... |
106 107 |
hw = spi_master_get_devdata(master); |
a5b4b234e spi: clps711x: Mi... |
108 |
hw->spi_clk = devm_clk_get(&pdev->dev, NULL); |
161b96c38 spi/clps711x: New... |
109 |
if (IS_ERR(hw->spi_clk)) { |
161b96c38 spi/clps711x: New... |
110 111 112 |
ret = PTR_ERR(hw->spi_clk); goto err_out; } |
161b96c38 spi/clps711x: New... |
113 |
|
6acaadc85 spi: clps711x: Dr... |
114 115 |
hw->syscon = syscon_regmap_lookup_by_compatible("cirrus,ep7209-syscon3"); |
3dc925945 spi: clps711x: Re... |
116 117 118 119 |
if (IS_ERR(hw->syscon)) { ret = PTR_ERR(hw->syscon); goto err_out; } |
ae43724d6 spi: clps711x: us... |
120 |
hw->syncio = devm_platform_ioremap_resource(pdev, 0); |
3dc925945 spi: clps711x: Re... |
121 122 123 124 |
if (IS_ERR(hw->syncio)) { ret = PTR_ERR(hw->syncio); goto err_out; } |
161b96c38 spi/clps711x: New... |
125 |
/* Disable extended mode due hardware problems */ |
3dc925945 spi: clps711x: Re... |
126 |
regmap_update_bits(hw->syscon, SYSCON_OFFSET, SYSCON3_ADCCON, 0); |
161b96c38 spi/clps711x: New... |
127 128 |
/* Clear possible pending interrupt */ |
3dc925945 spi: clps711x: Re... |
129 |
readl(hw->syncio); |
161b96c38 spi/clps711x: New... |
130 |
|
3dc925945 spi: clps711x: Re... |
131 |
ret = devm_request_irq(&pdev->dev, irq, spi_clps711x_isr, 0, |
bf5c2e270 spi: clps711x: Re... |
132 |
dev_name(&pdev->dev), master); |
3dc925945 spi: clps711x: Re... |
133 |
if (ret) |
c70837908 spi: clps711x: Re... |
134 |
goto err_out; |
161b96c38 spi/clps711x: New... |
135 |
|
c493fc4bb spi: clps711x: us... |
136 |
ret = devm_spi_register_master(&pdev->dev, master); |
6acaadc85 spi: clps711x: Dr... |
137 |
if (!ret) |
161b96c38 spi/clps711x: New... |
138 |
return 0; |
161b96c38 spi/clps711x: New... |
139 |
|
161b96c38 spi/clps711x: New... |
140 |
err_out: |
161b96c38 spi/clps711x: New... |
141 |
spi_master_put(master); |
161b96c38 spi/clps711x: New... |
142 143 144 |
return ret; } |
6acaadc85 spi: clps711x: Dr... |
145 146 147 148 149 |
static const struct of_device_id clps711x_spi_dt_ids[] = { { .compatible = "cirrus,ep7209-spi", }, { } }; MODULE_DEVICE_TABLE(of, clps711x_spi_dt_ids); |
161b96c38 spi/clps711x: New... |
150 151 152 |
static struct platform_driver clps711x_spi_driver = { .driver = { .name = DRIVER_NAME, |
6acaadc85 spi: clps711x: Dr... |
153 |
.of_match_table = clps711x_spi_dt_ids, |
161b96c38 spi/clps711x: New... |
154 155 |
}, .probe = spi_clps711x_probe, |
161b96c38 spi/clps711x: New... |
156 157 158 159 160 161 |
}; module_platform_driver(clps711x_spi_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Alexander Shiyan <shc_work@mail.ru>"); MODULE_DESCRIPTION("CLPS711X SPI bus driver"); |
350a9b330 spi: clps711x: Ad... |
162 |
MODULE_ALIAS("platform:" DRIVER_NAME); |