1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2911a8882SAlex Smith /*
3911a8882SAlex Smith * JZ4780 NAND/external memory controller (NEMC)
4911a8882SAlex Smith *
5911a8882SAlex Smith * Copyright (c) 2015 Imagination Technologies
6911a8882SAlex Smith * Author: Alex Smith <alex@alex-smith.me.uk>
7911a8882SAlex Smith */
8911a8882SAlex Smith
9911a8882SAlex Smith #include <linux/clk.h>
10911a8882SAlex Smith #include <linux/init.h>
11f046e4a3SPaul Cercueil #include <linux/io.h>
12911a8882SAlex Smith #include <linux/math64.h>
13911a8882SAlex Smith #include <linux/of.h>
14911a8882SAlex Smith #include <linux/of_address.h>
15911a8882SAlex Smith #include <linux/of_platform.h>
16911a8882SAlex Smith #include <linux/platform_device.h>
17911a8882SAlex Smith #include <linux/slab.h>
18911a8882SAlex Smith #include <linux/spinlock.h>
19911a8882SAlex Smith
20911a8882SAlex Smith #include <linux/jz4780-nemc.h>
21911a8882SAlex Smith
22911a8882SAlex Smith #define NEMC_SMCRn(n) (0x14 + (((n) - 1) * 4))
23911a8882SAlex Smith #define NEMC_NFCSR 0x50
24911a8882SAlex Smith
25f046e4a3SPaul Cercueil #define NEMC_REG_LEN 0x54
26f046e4a3SPaul Cercueil
27911a8882SAlex Smith #define NEMC_SMCR_SMT BIT(0)
28911a8882SAlex Smith #define NEMC_SMCR_BW_SHIFT 6
29911a8882SAlex Smith #define NEMC_SMCR_BW_MASK (0x3 << NEMC_SMCR_BW_SHIFT)
30911a8882SAlex Smith #define NEMC_SMCR_BW_8 (0 << 6)
31911a8882SAlex Smith #define NEMC_SMCR_TAS_SHIFT 8
32911a8882SAlex Smith #define NEMC_SMCR_TAS_MASK (0xf << NEMC_SMCR_TAS_SHIFT)
33911a8882SAlex Smith #define NEMC_SMCR_TAH_SHIFT 12
34911a8882SAlex Smith #define NEMC_SMCR_TAH_MASK (0xf << NEMC_SMCR_TAH_SHIFT)
35911a8882SAlex Smith #define NEMC_SMCR_TBP_SHIFT 16
36911a8882SAlex Smith #define NEMC_SMCR_TBP_MASK (0xf << NEMC_SMCR_TBP_SHIFT)
37911a8882SAlex Smith #define NEMC_SMCR_TAW_SHIFT 20
38911a8882SAlex Smith #define NEMC_SMCR_TAW_MASK (0xf << NEMC_SMCR_TAW_SHIFT)
39911a8882SAlex Smith #define NEMC_SMCR_TSTRV_SHIFT 24
40911a8882SAlex Smith #define NEMC_SMCR_TSTRV_MASK (0x3f << NEMC_SMCR_TSTRV_SHIFT)
41911a8882SAlex Smith
42911a8882SAlex Smith #define NEMC_NFCSR_NFEn(n) BIT(((n) - 1) << 1)
43911a8882SAlex Smith #define NEMC_NFCSR_NFCEn(n) BIT((((n) - 1) << 1) + 1)
44911a8882SAlex Smith #define NEMC_NFCSR_TNFEn(n) BIT(16 + (n) - 1)
45911a8882SAlex Smith
46a00b0042SPaul Cercueil struct jz_soc_info {
47a00b0042SPaul Cercueil u8 tas_tah_cycles_max;
48a00b0042SPaul Cercueil };
49a00b0042SPaul Cercueil
50911a8882SAlex Smith struct jz4780_nemc {
51911a8882SAlex Smith spinlock_t lock;
52911a8882SAlex Smith struct device *dev;
53a00b0042SPaul Cercueil const struct jz_soc_info *soc_info;
54911a8882SAlex Smith void __iomem *base;
55911a8882SAlex Smith struct clk *clk;
56911a8882SAlex Smith uint32_t clk_period;
57911a8882SAlex Smith unsigned long banks_present;
58911a8882SAlex Smith };
59911a8882SAlex Smith
60911a8882SAlex Smith /**
61911a8882SAlex Smith * jz4780_nemc_num_banks() - count the number of banks referenced by a device
62911a8882SAlex Smith * @dev: device to count banks for, must be a child of the NEMC.
63911a8882SAlex Smith *
64911a8882SAlex Smith * Return: The number of unique NEMC banks referred to by the specified NEMC
65911a8882SAlex Smith * child device. Unique here means that a device that references the same bank
66d171df6bSGeert Uytterhoeven * multiple times in its "reg" property will only count once.
67911a8882SAlex Smith */
jz4780_nemc_num_banks(struct device * dev)68911a8882SAlex Smith unsigned int jz4780_nemc_num_banks(struct device *dev)
69911a8882SAlex Smith {
70911a8882SAlex Smith const __be32 *prop;
71911a8882SAlex Smith unsigned int bank, count = 0;
72911a8882SAlex Smith unsigned long referenced = 0;
73911a8882SAlex Smith int i = 0;
74911a8882SAlex Smith
75911a8882SAlex Smith while ((prop = of_get_address(dev->of_node, i++, NULL, NULL))) {
76911a8882SAlex Smith bank = of_read_number(prop, 1);
77911a8882SAlex Smith if (!(referenced & BIT(bank))) {
78911a8882SAlex Smith referenced |= BIT(bank);
79911a8882SAlex Smith count++;
80911a8882SAlex Smith }
81911a8882SAlex Smith }
82911a8882SAlex Smith
83911a8882SAlex Smith return count;
84911a8882SAlex Smith }
85911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_num_banks);
86911a8882SAlex Smith
87911a8882SAlex Smith /**
88911a8882SAlex Smith * jz4780_nemc_set_type() - set the type of device connected to a bank
89911a8882SAlex Smith * @dev: child device of the NEMC.
90911a8882SAlex Smith * @bank: bank number to configure.
91911a8882SAlex Smith * @type: type of device connected to the bank.
92911a8882SAlex Smith */
jz4780_nemc_set_type(struct device * dev,unsigned int bank,enum jz4780_nemc_bank_type type)93911a8882SAlex Smith void jz4780_nemc_set_type(struct device *dev, unsigned int bank,
94911a8882SAlex Smith enum jz4780_nemc_bank_type type)
95911a8882SAlex Smith {
96911a8882SAlex Smith struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent);
97911a8882SAlex Smith uint32_t nfcsr;
98911a8882SAlex Smith
99911a8882SAlex Smith nfcsr = readl(nemc->base + NEMC_NFCSR);
100911a8882SAlex Smith
101911a8882SAlex Smith /* TODO: Support toggle NAND devices. */
102911a8882SAlex Smith switch (type) {
103911a8882SAlex Smith case JZ4780_NEMC_BANK_SRAM:
104911a8882SAlex Smith nfcsr &= ~(NEMC_NFCSR_TNFEn(bank) | NEMC_NFCSR_NFEn(bank));
105911a8882SAlex Smith break;
106911a8882SAlex Smith case JZ4780_NEMC_BANK_NAND:
107911a8882SAlex Smith nfcsr &= ~NEMC_NFCSR_TNFEn(bank);
108911a8882SAlex Smith nfcsr |= NEMC_NFCSR_NFEn(bank);
109911a8882SAlex Smith break;
110911a8882SAlex Smith }
111911a8882SAlex Smith
112911a8882SAlex Smith writel(nfcsr, nemc->base + NEMC_NFCSR);
113911a8882SAlex Smith }
114911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_set_type);
115911a8882SAlex Smith
116911a8882SAlex Smith /**
117911a8882SAlex Smith * jz4780_nemc_assert() - (de-)assert a NAND device's chip enable pin
118911a8882SAlex Smith * @dev: child device of the NEMC.
119911a8882SAlex Smith * @bank: bank number of device.
120911a8882SAlex Smith * @assert: whether the chip enable pin should be asserted.
121911a8882SAlex Smith *
122911a8882SAlex Smith * (De-)asserts the chip enable pin for the NAND device connected to the
123911a8882SAlex Smith * specified bank.
124911a8882SAlex Smith */
jz4780_nemc_assert(struct device * dev,unsigned int bank,bool assert)125911a8882SAlex Smith void jz4780_nemc_assert(struct device *dev, unsigned int bank, bool assert)
126911a8882SAlex Smith {
127911a8882SAlex Smith struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent);
128911a8882SAlex Smith uint32_t nfcsr;
129911a8882SAlex Smith
130911a8882SAlex Smith nfcsr = readl(nemc->base + NEMC_NFCSR);
131911a8882SAlex Smith
132911a8882SAlex Smith if (assert)
133911a8882SAlex Smith nfcsr |= NEMC_NFCSR_NFCEn(bank);
134911a8882SAlex Smith else
135911a8882SAlex Smith nfcsr &= ~NEMC_NFCSR_NFCEn(bank);
136911a8882SAlex Smith
137911a8882SAlex Smith writel(nfcsr, nemc->base + NEMC_NFCSR);
138911a8882SAlex Smith }
139911a8882SAlex Smith EXPORT_SYMBOL(jz4780_nemc_assert);
140911a8882SAlex Smith
jz4780_nemc_clk_period(struct jz4780_nemc * nemc)141911a8882SAlex Smith static uint32_t jz4780_nemc_clk_period(struct jz4780_nemc *nemc)
142911a8882SAlex Smith {
143911a8882SAlex Smith unsigned long rate;
144911a8882SAlex Smith
145911a8882SAlex Smith rate = clk_get_rate(nemc->clk);
146911a8882SAlex Smith if (!rate)
147911a8882SAlex Smith return 0;
148911a8882SAlex Smith
149911a8882SAlex Smith /* Return in picoseconds. */
150911a8882SAlex Smith return div64_ul(1000000000000ull, rate);
151911a8882SAlex Smith }
152911a8882SAlex Smith
jz4780_nemc_ns_to_cycles(struct jz4780_nemc * nemc,uint32_t ns)153911a8882SAlex Smith static uint32_t jz4780_nemc_ns_to_cycles(struct jz4780_nemc *nemc, uint32_t ns)
154911a8882SAlex Smith {
155911a8882SAlex Smith return ((ns * 1000) + nemc->clk_period - 1) / nemc->clk_period;
156911a8882SAlex Smith }
157911a8882SAlex Smith
jz4780_nemc_configure_bank(struct jz4780_nemc * nemc,unsigned int bank,struct device_node * node)158911a8882SAlex Smith static bool jz4780_nemc_configure_bank(struct jz4780_nemc *nemc,
159911a8882SAlex Smith unsigned int bank,
160911a8882SAlex Smith struct device_node *node)
161911a8882SAlex Smith {
162911a8882SAlex Smith uint32_t smcr, val, cycles;
163911a8882SAlex Smith
164911a8882SAlex Smith /*
165911a8882SAlex Smith * Conversion of tBP and tAW cycle counts to values supported by the
166911a8882SAlex Smith * hardware (round up to the next supported value).
167911a8882SAlex Smith */
1681a927ad6SPaul Cercueil static const u8 convert_tBP_tAW[] = {
169911a8882SAlex Smith 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
170911a8882SAlex Smith
171911a8882SAlex Smith /* 11 - 12 -> 12 cycles */
172911a8882SAlex Smith 11, 11,
173911a8882SAlex Smith
174911a8882SAlex Smith /* 13 - 15 -> 15 cycles */
175911a8882SAlex Smith 12, 12, 12,
176911a8882SAlex Smith
177911a8882SAlex Smith /* 16 - 20 -> 20 cycles */
178911a8882SAlex Smith 13, 13, 13, 13, 13,
179911a8882SAlex Smith
180911a8882SAlex Smith /* 21 - 25 -> 25 cycles */
181911a8882SAlex Smith 14, 14, 14, 14, 14,
182911a8882SAlex Smith
183911a8882SAlex Smith /* 26 - 31 -> 31 cycles */
184911a8882SAlex Smith 15, 15, 15, 15, 15, 15
185911a8882SAlex Smith };
186911a8882SAlex Smith
187911a8882SAlex Smith smcr = readl(nemc->base + NEMC_SMCRn(bank));
188911a8882SAlex Smith smcr &= ~NEMC_SMCR_SMT;
189911a8882SAlex Smith
190911a8882SAlex Smith if (!of_property_read_u32(node, "ingenic,nemc-bus-width", &val)) {
191911a8882SAlex Smith smcr &= ~NEMC_SMCR_BW_MASK;
192911a8882SAlex Smith switch (val) {
193911a8882SAlex Smith case 8:
194911a8882SAlex Smith smcr |= NEMC_SMCR_BW_8;
195911a8882SAlex Smith break;
196911a8882SAlex Smith default:
197911a8882SAlex Smith /*
198911a8882SAlex Smith * Earlier SoCs support a 16 bit bus width (the 4780
199911a8882SAlex Smith * does not), until those are properly supported, error.
200911a8882SAlex Smith */
201911a8882SAlex Smith dev_err(nemc->dev, "unsupported bus width: %u\n", val);
202911a8882SAlex Smith return false;
203911a8882SAlex Smith }
204911a8882SAlex Smith }
205911a8882SAlex Smith
206911a8882SAlex Smith if (of_property_read_u32(node, "ingenic,nemc-tAS", &val) == 0) {
207911a8882SAlex Smith smcr &= ~NEMC_SMCR_TAS_MASK;
208911a8882SAlex Smith cycles = jz4780_nemc_ns_to_cycles(nemc, val);
209a00b0042SPaul Cercueil if (cycles > nemc->soc_info->tas_tah_cycles_max) {
210911a8882SAlex Smith dev_err(nemc->dev, "tAS %u is too high (%u cycles)\n",
211911a8882SAlex Smith val, cycles);
212911a8882SAlex Smith return false;
213911a8882SAlex Smith }
214911a8882SAlex Smith
215911a8882SAlex Smith smcr |= cycles << NEMC_SMCR_TAS_SHIFT;
216911a8882SAlex Smith }
217911a8882SAlex Smith
218911a8882SAlex Smith if (of_property_read_u32(node, "ingenic,nemc-tAH", &val) == 0) {
219911a8882SAlex Smith smcr &= ~NEMC_SMCR_TAH_MASK;
220911a8882SAlex Smith cycles = jz4780_nemc_ns_to_cycles(nemc, val);
221a00b0042SPaul Cercueil if (cycles > nemc->soc_info->tas_tah_cycles_max) {
222911a8882SAlex Smith dev_err(nemc->dev, "tAH %u is too high (%u cycles)\n",
223911a8882SAlex Smith val, cycles);
224911a8882SAlex Smith return false;
225911a8882SAlex Smith }
226911a8882SAlex Smith
227911a8882SAlex Smith smcr |= cycles << NEMC_SMCR_TAH_SHIFT;
228911a8882SAlex Smith }
229911a8882SAlex Smith
230911a8882SAlex Smith if (of_property_read_u32(node, "ingenic,nemc-tBP", &val) == 0) {
231911a8882SAlex Smith smcr &= ~NEMC_SMCR_TBP_MASK;
232911a8882SAlex Smith cycles = jz4780_nemc_ns_to_cycles(nemc, val);
233911a8882SAlex Smith if (cycles > 31) {
234911a8882SAlex Smith dev_err(nemc->dev, "tBP %u is too high (%u cycles)\n",
235911a8882SAlex Smith val, cycles);
236911a8882SAlex Smith return false;
237911a8882SAlex Smith }
238911a8882SAlex Smith
239911a8882SAlex Smith smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TBP_SHIFT;
240911a8882SAlex Smith }
241911a8882SAlex Smith
242911a8882SAlex Smith if (of_property_read_u32(node, "ingenic,nemc-tAW", &val) == 0) {
243911a8882SAlex Smith smcr &= ~NEMC_SMCR_TAW_MASK;
244911a8882SAlex Smith cycles = jz4780_nemc_ns_to_cycles(nemc, val);
245911a8882SAlex Smith if (cycles > 31) {
246911a8882SAlex Smith dev_err(nemc->dev, "tAW %u is too high (%u cycles)\n",
247911a8882SAlex Smith val, cycles);
248911a8882SAlex Smith return false;
249911a8882SAlex Smith }
250911a8882SAlex Smith
251911a8882SAlex Smith smcr |= convert_tBP_tAW[cycles] << NEMC_SMCR_TAW_SHIFT;
252911a8882SAlex Smith }
253911a8882SAlex Smith
254911a8882SAlex Smith if (of_property_read_u32(node, "ingenic,nemc-tSTRV", &val) == 0) {
255911a8882SAlex Smith smcr &= ~NEMC_SMCR_TSTRV_MASK;
256911a8882SAlex Smith cycles = jz4780_nemc_ns_to_cycles(nemc, val);
257911a8882SAlex Smith if (cycles > 63) {
258911a8882SAlex Smith dev_err(nemc->dev, "tSTRV %u is too high (%u cycles)\n",
259911a8882SAlex Smith val, cycles);
260911a8882SAlex Smith return false;
261911a8882SAlex Smith }
262911a8882SAlex Smith
263911a8882SAlex Smith smcr |= cycles << NEMC_SMCR_TSTRV_SHIFT;
264911a8882SAlex Smith }
265911a8882SAlex Smith
266911a8882SAlex Smith writel(smcr, nemc->base + NEMC_SMCRn(bank));
267911a8882SAlex Smith return true;
268911a8882SAlex Smith }
269911a8882SAlex Smith
jz4780_nemc_probe(struct platform_device * pdev)270911a8882SAlex Smith static int jz4780_nemc_probe(struct platform_device *pdev)
271911a8882SAlex Smith {
272911a8882SAlex Smith struct device *dev = &pdev->dev;
273911a8882SAlex Smith struct jz4780_nemc *nemc;
274911a8882SAlex Smith struct resource *res;
275911a8882SAlex Smith struct device_node *child;
276911a8882SAlex Smith const __be32 *prop;
277911a8882SAlex Smith unsigned int bank;
278911a8882SAlex Smith unsigned long referenced;
279911a8882SAlex Smith int i, ret;
280911a8882SAlex Smith
281911a8882SAlex Smith nemc = devm_kzalloc(dev, sizeof(*nemc), GFP_KERNEL);
282911a8882SAlex Smith if (!nemc)
283911a8882SAlex Smith return -ENOMEM;
284911a8882SAlex Smith
285a00b0042SPaul Cercueil nemc->soc_info = device_get_match_data(dev);
286a00b0042SPaul Cercueil if (!nemc->soc_info)
287a00b0042SPaul Cercueil return -EINVAL;
288a00b0042SPaul Cercueil
289911a8882SAlex Smith spin_lock_init(&nemc->lock);
290911a8882SAlex Smith nemc->dev = dev;
291911a8882SAlex Smith
292911a8882SAlex Smith res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
293*4bfa0730SZhang Changzhong if (!res)
294*4bfa0730SZhang Changzhong return -EINVAL;
295f046e4a3SPaul Cercueil
296f046e4a3SPaul Cercueil /*
297f046e4a3SPaul Cercueil * The driver currently only uses the registers up to offset
298f046e4a3SPaul Cercueil * NEMC_REG_LEN. Since the EFUSE registers are in the middle of the
299f046e4a3SPaul Cercueil * NEMC registers, we only request the registers we will use for now;
300f046e4a3SPaul Cercueil * that way the EFUSE driver can probe too.
301f046e4a3SPaul Cercueil */
302f046e4a3SPaul Cercueil if (!devm_request_mem_region(dev, res->start, NEMC_REG_LEN, dev_name(dev))) {
303f046e4a3SPaul Cercueil dev_err(dev, "unable to request I/O memory region\n");
304f046e4a3SPaul Cercueil return -EBUSY;
305f046e4a3SPaul Cercueil }
306f046e4a3SPaul Cercueil
307f046e4a3SPaul Cercueil nemc->base = devm_ioremap(dev, res->start, NEMC_REG_LEN);
30896999c79SDan Carpenter if (!nemc->base) {
309911a8882SAlex Smith dev_err(dev, "failed to get I/O memory\n");
31096999c79SDan Carpenter return -ENOMEM;
311911a8882SAlex Smith }
312911a8882SAlex Smith
313911a8882SAlex Smith writel(0, nemc->base + NEMC_NFCSR);
314911a8882SAlex Smith
315911a8882SAlex Smith nemc->clk = devm_clk_get(dev, NULL);
316911a8882SAlex Smith if (IS_ERR(nemc->clk)) {
317911a8882SAlex Smith dev_err(dev, "failed to get clock\n");
318911a8882SAlex Smith return PTR_ERR(nemc->clk);
319911a8882SAlex Smith }
320911a8882SAlex Smith
321911a8882SAlex Smith ret = clk_prepare_enable(nemc->clk);
322911a8882SAlex Smith if (ret) {
323911a8882SAlex Smith dev_err(dev, "failed to enable clock: %d\n", ret);
324911a8882SAlex Smith return ret;
325911a8882SAlex Smith }
326911a8882SAlex Smith
327911a8882SAlex Smith nemc->clk_period = jz4780_nemc_clk_period(nemc);
328911a8882SAlex Smith if (!nemc->clk_period) {
329911a8882SAlex Smith dev_err(dev, "failed to calculate clock period\n");
330911a8882SAlex Smith clk_disable_unprepare(nemc->clk);
331911a8882SAlex Smith return -EINVAL;
332911a8882SAlex Smith }
333911a8882SAlex Smith
334911a8882SAlex Smith /*
335911a8882SAlex Smith * Iterate over child devices, check that they do not conflict with
336911a8882SAlex Smith * each other, and register child devices for them. If a child device
337911a8882SAlex Smith * has invalid properties, it is ignored and no platform device is
338911a8882SAlex Smith * registered for it.
339911a8882SAlex Smith */
340911a8882SAlex Smith for_each_child_of_node(nemc->dev->of_node, child) {
341911a8882SAlex Smith referenced = 0;
342911a8882SAlex Smith i = 0;
343911a8882SAlex Smith while ((prop = of_get_address(child, i++, NULL, NULL))) {
344911a8882SAlex Smith bank = of_read_number(prop, 1);
345911a8882SAlex Smith if (bank < 1 || bank >= JZ4780_NEMC_NUM_BANKS) {
346911a8882SAlex Smith dev_err(nemc->dev,
347db749d17SRob Herring "%pOF requests invalid bank %u\n",
348db749d17SRob Herring child, bank);
349911a8882SAlex Smith
350911a8882SAlex Smith /* Will continue the outer loop below. */
351911a8882SAlex Smith referenced = 0;
352911a8882SAlex Smith break;
353911a8882SAlex Smith }
354911a8882SAlex Smith
355911a8882SAlex Smith referenced |= BIT(bank);
356911a8882SAlex Smith }
357911a8882SAlex Smith
358911a8882SAlex Smith if (!referenced) {
359db749d17SRob Herring dev_err(nemc->dev, "%pOF has no addresses\n",
360db749d17SRob Herring child);
361911a8882SAlex Smith continue;
362911a8882SAlex Smith } else if (nemc->banks_present & referenced) {
363db749d17SRob Herring dev_err(nemc->dev, "%pOF conflicts with another node\n",
364db749d17SRob Herring child);
365911a8882SAlex Smith continue;
366911a8882SAlex Smith }
367911a8882SAlex Smith
368911a8882SAlex Smith /* Configure bank parameters. */
369911a8882SAlex Smith for_each_set_bit(bank, &referenced, JZ4780_NEMC_NUM_BANKS) {
370911a8882SAlex Smith if (!jz4780_nemc_configure_bank(nemc, bank, child)) {
371911a8882SAlex Smith referenced = 0;
372911a8882SAlex Smith break;
373911a8882SAlex Smith }
374911a8882SAlex Smith }
375911a8882SAlex Smith
376911a8882SAlex Smith if (referenced) {
377911a8882SAlex Smith if (of_platform_device_create(child, NULL, nemc->dev))
378911a8882SAlex Smith nemc->banks_present |= referenced;
379911a8882SAlex Smith }
380911a8882SAlex Smith }
381911a8882SAlex Smith
382911a8882SAlex Smith platform_set_drvdata(pdev, nemc);
383911a8882SAlex Smith dev_info(dev, "JZ4780 NEMC initialised\n");
384911a8882SAlex Smith return 0;
385911a8882SAlex Smith }
386911a8882SAlex Smith
jz4780_nemc_remove(struct platform_device * pdev)387911a8882SAlex Smith static int jz4780_nemc_remove(struct platform_device *pdev)
388911a8882SAlex Smith {
389911a8882SAlex Smith struct jz4780_nemc *nemc = platform_get_drvdata(pdev);
390911a8882SAlex Smith
391911a8882SAlex Smith clk_disable_unprepare(nemc->clk);
392911a8882SAlex Smith return 0;
393911a8882SAlex Smith }
394911a8882SAlex Smith
395a00b0042SPaul Cercueil static const struct jz_soc_info jz4740_soc_info = {
396a00b0042SPaul Cercueil .tas_tah_cycles_max = 7,
397a00b0042SPaul Cercueil };
398a00b0042SPaul Cercueil
399a00b0042SPaul Cercueil static const struct jz_soc_info jz4780_soc_info = {
400a00b0042SPaul Cercueil .tas_tah_cycles_max = 15,
401a00b0042SPaul Cercueil };
402a00b0042SPaul Cercueil
403911a8882SAlex Smith static const struct of_device_id jz4780_nemc_dt_match[] = {
404a00b0042SPaul Cercueil { .compatible = "ingenic,jz4740-nemc", .data = &jz4740_soc_info, },
405a00b0042SPaul Cercueil { .compatible = "ingenic,jz4780-nemc", .data = &jz4780_soc_info, },
406911a8882SAlex Smith {},
407911a8882SAlex Smith };
408911a8882SAlex Smith
409911a8882SAlex Smith static struct platform_driver jz4780_nemc_driver = {
410911a8882SAlex Smith .probe = jz4780_nemc_probe,
411911a8882SAlex Smith .remove = jz4780_nemc_remove,
412911a8882SAlex Smith .driver = {
413911a8882SAlex Smith .name = "jz4780-nemc",
414911a8882SAlex Smith .of_match_table = of_match_ptr(jz4780_nemc_dt_match),
415911a8882SAlex Smith },
416911a8882SAlex Smith };
417911a8882SAlex Smith
jz4780_nemc_init(void)418911a8882SAlex Smith static int __init jz4780_nemc_init(void)
419911a8882SAlex Smith {
420911a8882SAlex Smith return platform_driver_register(&jz4780_nemc_driver);
421911a8882SAlex Smith }
422911a8882SAlex Smith subsys_initcall(jz4780_nemc_init);
423