Lines Matching +full:nand +full:- +full:ecc +full:- +full:engine
1 // SPDX-License-Identifier: GPL-2.0
3 * JZ47xx ECC common code
19 * ingenic_ecc_calculate() - calculate ECC for a data buffer
20 * @ecc: ECC device.
21 * @params: ECC parameters.
23 * @ecc_code: output buffer with ECC.
25 * Return: 0 on success, -ETIMEDOUT if timed out while waiting for ECC
28 int ingenic_ecc_calculate(struct ingenic_ecc *ecc, in ingenic_ecc_calculate() argument
32 return ecc->ops->calculate(ecc, params, buf, ecc_code); in ingenic_ecc_calculate()
36 * ingenic_ecc_correct() - detect and correct bit errors
37 * @ecc: ECC device.
38 * @params: ECC parameters.
40 * @ecc_code: ECC read from the chip.
42 * Given the raw data and the ECC read from the NAND device, detects and
45 * Return: the number of bit errors corrected, -EBADMSG if there are too many
46 * errors to correct or -ETIMEDOUT if we timed out waiting for the controller.
48 int ingenic_ecc_correct(struct ingenic_ecc *ecc, in ingenic_ecc_correct() argument
52 return ecc->ops->correct(ecc, params, buf, ecc_code); in ingenic_ecc_correct()
56 * ingenic_ecc_get() - get the ECC controller device
57 * @np: ECC device tree node.
59 * Gets the ECC controller device from the specified device tree node. The
64 * PTR_ERR(-EPROBE_DEFER) if the device hasn't been initialised yet.
69 struct ingenic_ecc *ecc; in ingenic_ecc_get() local
73 return ERR_PTR(-EPROBE_DEFER); in ingenic_ecc_get()
76 put_device(&pdev->dev); in ingenic_ecc_get()
77 return ERR_PTR(-EPROBE_DEFER); in ingenic_ecc_get()
80 ecc = platform_get_drvdata(pdev); in ingenic_ecc_get()
81 clk_prepare_enable(ecc->clk); in ingenic_ecc_get()
83 return ecc; in ingenic_ecc_get()
87 * of_ingenic_ecc_get() - get the ECC controller from a DT node
88 * @of_node: the node that contains an ecc-engine property.
90 * Get the ecc-engine property from the given device tree
94 * PTR_ERR(-EPROBE_DEFER) if the device hasn't been initialised yet.
98 struct ingenic_ecc *ecc = NULL; in of_ingenic_ecc_get() local
101 np = of_parse_phandle(of_node, "ecc-engine", 0); in of_ingenic_ecc_get()
104 * If the ecc-engine property is not found, check for the deprecated in of_ingenic_ecc_get()
105 * ingenic,bch-controller property in of_ingenic_ecc_get()
108 np = of_parse_phandle(of_node, "ingenic,bch-controller", 0); in of_ingenic_ecc_get()
111 ecc = ingenic_ecc_get(np); in of_ingenic_ecc_get()
114 return ecc; in of_ingenic_ecc_get()
118 * ingenic_ecc_release() - release the ECC controller device
119 * @ecc: ECC device.
121 void ingenic_ecc_release(struct ingenic_ecc *ecc) in ingenic_ecc_release() argument
123 clk_disable_unprepare(ecc->clk); in ingenic_ecc_release()
124 put_device(ecc->dev); in ingenic_ecc_release()
129 struct device *dev = &pdev->dev; in ingenic_ecc_probe()
130 struct ingenic_ecc *ecc; in ingenic_ecc_probe() local
132 ecc = devm_kzalloc(dev, sizeof(*ecc), GFP_KERNEL); in ingenic_ecc_probe()
133 if (!ecc) in ingenic_ecc_probe()
134 return -ENOMEM; in ingenic_ecc_probe()
136 ecc->ops = device_get_match_data(dev); in ingenic_ecc_probe()
137 if (!ecc->ops) in ingenic_ecc_probe()
138 return -EINVAL; in ingenic_ecc_probe()
140 ecc->base = devm_platform_ioremap_resource(pdev, 0); in ingenic_ecc_probe()
141 if (IS_ERR(ecc->base)) in ingenic_ecc_probe()
142 return PTR_ERR(ecc->base); in ingenic_ecc_probe()
144 ecc->ops->disable(ecc); in ingenic_ecc_probe()
146 ecc->clk = devm_clk_get(dev, NULL); in ingenic_ecc_probe()
147 if (IS_ERR(ecc->clk)) { in ingenic_ecc_probe()
148 dev_err(dev, "failed to get clock: %ld\n", PTR_ERR(ecc->clk)); in ingenic_ecc_probe()
149 return PTR_ERR(ecc->clk); in ingenic_ecc_probe()
152 mutex_init(&ecc->lock); in ingenic_ecc_probe()
154 ecc->dev = dev; in ingenic_ecc_probe()
155 platform_set_drvdata(pdev, ecc); in ingenic_ecc_probe()