Lines Matching +full:ns +full:- +full:partitions

1 // SPDX-License-Identifier: GPL-2.0
22 #include <linux/mtd/nand-gpio.h>
24 #include <linux/mtd/partitions.h>
52 gpiod_set_value(priv->gpiod_nwe, 1); in gpio_nand_write_commit()
53 ndelay(priv->tWP); in gpio_nand_write_commit()
54 gpiod_set_value(priv->gpiod_nwe, 0); in gpio_nand_write_commit()
59 struct gpio_descs *data_gpiods = priv->data_gpiods; in gpio_nand_io_write()
62 gpiod_set_raw_array_value(data_gpiods->ndescs, data_gpiods->desc, in gpio_nand_io_write()
63 data_gpiods->info, values); in gpio_nand_io_write()
70 struct gpio_descs *data_gpiods = priv->data_gpiods; in gpio_nand_dir_output()
74 for (i = 0; i < data_gpiods->ndescs; i++) in gpio_nand_dir_output()
75 gpiod_direction_output_raw(data_gpiods->desc[i], in gpio_nand_dir_output()
80 priv->data_in = false; in gpio_nand_dir_output()
86 struct gpio_descs *data_gpiods = priv->data_gpiods; in gpio_nand_io_read()
89 gpiod_set_value(priv->gpiod_nre, 1); in gpio_nand_io_read()
90 ndelay(priv->tRP); in gpio_nand_io_read()
92 gpiod_get_raw_array_value(data_gpiods->ndescs, data_gpiods->desc, in gpio_nand_io_read()
93 data_gpiods->info, values); in gpio_nand_io_read()
95 gpiod_set_value(priv->gpiod_nre, 0); in gpio_nand_io_read()
103 struct gpio_descs *data_gpiods = priv->data_gpiods; in gpio_nand_dir_input()
106 for (i = 0; i < data_gpiods->ndescs; i++) in gpio_nand_dir_input()
107 gpiod_direction_input(data_gpiods->desc[i]); in gpio_nand_dir_input()
109 priv->data_in = true; in gpio_nand_dir_input()
116 if (len > 0 && priv->data_in) in gpio_nand_write_buf()
120 priv->io_write(priv, buf[i++]); in gpio_nand_write_buf()
127 if (priv->data_gpiods && !priv->data_in) in gpio_nand_read_buf()
131 buf[i] = priv->io_read(priv); in gpio_nand_read_buf()
136 gpiod_set_value(priv->gpiod_nce, assert); in gpio_nand_ctrl_cs()
151 for (instr = op->instrs; instr < op->instrs + op->ninstrs; instr++) { in gpio_nand_exec_op()
152 switch (instr->type) { in gpio_nand_exec_op()
154 gpiod_set_value(priv->gpiod_cle, 1); in gpio_nand_exec_op()
155 gpio_nand_write_buf(priv, &instr->ctx.cmd.opcode, 1); in gpio_nand_exec_op()
156 gpiod_set_value(priv->gpiod_cle, 0); in gpio_nand_exec_op()
160 gpiod_set_value(priv->gpiod_ale, 1); in gpio_nand_exec_op()
161 gpio_nand_write_buf(priv, instr->ctx.addr.addrs, in gpio_nand_exec_op()
162 instr->ctx.addr.naddrs); in gpio_nand_exec_op()
163 gpiod_set_value(priv->gpiod_ale, 0); in gpio_nand_exec_op()
167 gpio_nand_read_buf(priv, instr->ctx.data.buf.in, in gpio_nand_exec_op()
168 instr->ctx.data.len); in gpio_nand_exec_op()
172 gpio_nand_write_buf(priv, instr->ctx.data.buf.out, in gpio_nand_exec_op()
173 instr->ctx.data.len); in gpio_nand_exec_op()
177 ret = priv->gpiod_rdy ? in gpio_nand_exec_op()
178 nand_gpio_waitrdy(this, priv->gpiod_rdy, in gpio_nand_exec_op()
179 instr->ctx.waitrdy.timeout_ms) : in gpio_nand_exec_op()
181 instr->ctx.waitrdy.timeout_ms); in gpio_nand_exec_op()
199 struct device *dev = &nand_to_mtd(this)->dev; in gpio_nand_setup_interface()
207 if (priv->gpiod_nre) { in gpio_nand_setup_interface()
208 priv->tRP = DIV_ROUND_UP(sdr->tRP_min, 1000); in gpio_nand_setup_interface()
209 dev_dbg(dev, "using %u ns read pulse width\n", priv->tRP); in gpio_nand_setup_interface()
212 priv->tWP = DIV_ROUND_UP(sdr->tWP_min, 1000); in gpio_nand_setup_interface()
213 dev_dbg(dev, "using %u ns write pulse width\n", priv->tWP); in gpio_nand_setup_interface()
220 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT && in gpio_nand_attach_chip()
221 chip->ecc.algo == NAND_ECC_ALGO_UNKNOWN) in gpio_nand_attach_chip()
222 chip->ecc.algo = NAND_ECC_ALGO_HAMMING; in gpio_nand_attach_chip()
238 struct gpio_nand_platdata *pdata = dev_get_platdata(&pdev->dev); in gpio_nand_probe()
239 const struct mtd_partition *partitions = NULL; in gpio_nand_probe() local
248 partitions = pdata->parts; in gpio_nand_probe()
249 num_partitions = pdata->num_parts; in gpio_nand_probe()
253 priv = devm_kzalloc(&pdev->dev, sizeof(struct gpio_nand), in gpio_nand_probe()
256 return -ENOMEM; in gpio_nand_probe()
258 this = &priv->nand_chip; in gpio_nand_probe()
261 mtd->dev.parent = &pdev->dev; in gpio_nand_probe()
264 nand_set_flash_node(this, pdev->dev.of_node); in gpio_nand_probe()
266 priv->gpiod_rdy = devm_gpiod_get_optional(&pdev->dev, "rdy", GPIOD_IN); in gpio_nand_probe()
267 if (IS_ERR(priv->gpiod_rdy)) { in gpio_nand_probe()
268 err = PTR_ERR(priv->gpiod_rdy); in gpio_nand_probe()
269 dev_warn(&pdev->dev, "RDY GPIO request failed (%d)\n", err); in gpio_nand_probe()
276 priv->gpiod_nwp = devm_gpiod_get_optional(&pdev->dev, "nwp", in gpio_nand_probe()
278 if (IS_ERR(priv->gpiod_nwp)) { in gpio_nand_probe()
279 err = PTR_ERR(priv->gpiod_nwp); in gpio_nand_probe()
280 dev_err(&pdev->dev, "NWP GPIO request failed (%d)\n", err); in gpio_nand_probe()
284 priv->gpiod_nce = devm_gpiod_get_optional(&pdev->dev, "nce", in gpio_nand_probe()
286 if (IS_ERR(priv->gpiod_nce)) { in gpio_nand_probe()
287 err = PTR_ERR(priv->gpiod_nce); in gpio_nand_probe()
288 dev_err(&pdev->dev, "NCE GPIO request failed (%d)\n", err); in gpio_nand_probe()
292 priv->gpiod_nre = devm_gpiod_get_optional(&pdev->dev, "nre", in gpio_nand_probe()
294 if (IS_ERR(priv->gpiod_nre)) { in gpio_nand_probe()
295 err = PTR_ERR(priv->gpiod_nre); in gpio_nand_probe()
296 dev_err(&pdev->dev, "NRE GPIO request failed (%d)\n", err); in gpio_nand_probe()
300 priv->gpiod_nwe = devm_gpiod_get_optional(&pdev->dev, "nwe", in gpio_nand_probe()
302 if (IS_ERR(priv->gpiod_nwe)) { in gpio_nand_probe()
303 err = PTR_ERR(priv->gpiod_nwe); in gpio_nand_probe()
304 dev_err(&pdev->dev, "NWE GPIO request failed (%d)\n", err); in gpio_nand_probe()
308 priv->gpiod_ale = devm_gpiod_get(&pdev->dev, "ale", GPIOD_OUT_LOW); in gpio_nand_probe()
309 if (IS_ERR(priv->gpiod_ale)) { in gpio_nand_probe()
310 err = PTR_ERR(priv->gpiod_ale); in gpio_nand_probe()
311 dev_err(&pdev->dev, "ALE GPIO request failed (%d)\n", err); in gpio_nand_probe()
315 priv->gpiod_cle = devm_gpiod_get(&pdev->dev, "cle", GPIOD_OUT_LOW); in gpio_nand_probe()
316 if (IS_ERR(priv->gpiod_cle)) { in gpio_nand_probe()
317 err = PTR_ERR(priv->gpiod_cle); in gpio_nand_probe()
318 dev_err(&pdev->dev, "CLE GPIO request failed (%d)\n", err); in gpio_nand_probe()
323 priv->data_gpiods = devm_gpiod_get_array_optional(&pdev->dev, "data", in gpio_nand_probe()
325 if (IS_ERR(priv->data_gpiods)) { in gpio_nand_probe()
326 err = PTR_ERR(priv->data_gpiods); in gpio_nand_probe()
327 dev_err(&pdev->dev, "data GPIO request failed: %d\n", err); in gpio_nand_probe()
330 if (priv->data_gpiods) { in gpio_nand_probe()
331 if (!priv->gpiod_nwe) { in gpio_nand_probe()
332 dev_err(&pdev->dev, in gpio_nand_probe()
334 return -ENODEV; in gpio_nand_probe()
337 priv->io_read = gpio_nand_io_read; in gpio_nand_probe()
338 priv->io_write = gpio_nand_io_write; in gpio_nand_probe()
339 priv->data_in = true; in gpio_nand_probe()
342 if (pdev->id_entry) in gpio_nand_probe()
343 probe = (void *) pdev->id_entry->driver_data; in gpio_nand_probe()
345 probe = of_device_get_match_data(&pdev->dev); in gpio_nand_probe()
351 if (!priv->io_read || !priv->io_write) { in gpio_nand_probe()
352 dev_err(&pdev->dev, "incomplete device configuration\n"); in gpio_nand_probe()
353 return -ENODEV; in gpio_nand_probe()
357 priv->base.ops = &gpio_nand_ops; in gpio_nand_probe()
358 nand_controller_init(&priv->base); in gpio_nand_probe()
359 this->controller = &priv->base; in gpio_nand_probe()
370 gpiod_set_value(priv->gpiod_nwp, 0); in gpio_nand_probe()
374 * Set ->engine_type before registering the NAND devices in order to in gpio_nand_probe()
377 this->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; in gpio_nand_probe()
384 /* Register the partitions */ in gpio_nand_probe()
385 err = mtd_device_register(mtd, partitions, num_partitions); in gpio_nand_probe()
403 struct mtd_info *mtd = nand_to_mtd(&priv->nand_chip); in gpio_nand_remove()
407 gpiod_set_value(priv->gpiod_nwp, 1); in gpio_nand_remove()
426 .name = "ams-delta-nand",
438 .name = "ams-delta-nand",