Lines Matching +full:omap2 +full:- +full:onenand

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2005-2006 Nokia Corporation
10 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
33 #include <linux/omap-gpmc.h>
37 #include <linux/platform_data/mtd-nand-omap2.h>
39 #define DEVICE_NAME "omap-gpmc"
60 #define GPMC_ECC_BCH_RESULT_0 0x240 /* not available on OMAP2 */
61 #define GPMC_ECC_BCH_RESULT_1 0x244 /* not available on OMAP2 */
62 #define GPMC_ECC_BCH_RESULT_2 0x248 /* not available on OMAP2 */
63 #define GPMC_ECC_BCH_RESULT_3 0x24c /* not available on OMAP2 */
64 #define GPMC_ECC_BCH_RESULT_4 0x300 /* not available on OMAP2 */
65 #define GPMC_ECC_BCH_RESULT_5 0x304 /* not available on OMAP2 */
66 #define GPMC_ECC_BCH_RESULT_6 0x308 /* not available on OMAP2 */
258 /* Define chip-selects as reserved by default until probe completes */
306 * gpmc_get_clk_period - get period of selected clock domain in ps
343 return (time_ns * 1000 + tick_ps - 1) / tick_ps; in gpmc_ns_to_clk_ticks()
358 return (time_ps + tick_ps - 1) / tick_ps; in gpmc_ps_to_ticks()
400 p->time_para_granularity); in gpmc_cs_bool_timings()
402 GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay); in gpmc_cs_bool_timings()
404 GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay); in gpmc_cs_bool_timings()
406 GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay); in gpmc_cs_bool_timings()
408 GPMC_CONFIG4_WEEXTRADELAY, p->we_extra_delay); in gpmc_cs_bool_timings()
411 p->cycle2cyclesamecsen); in gpmc_cs_bool_timings()
414 p->cycle2cyclediffcsen); in gpmc_cs_bool_timings()
419 * get_gpmc_timing_reg - read a timing parameter and print DTS settings for it.
431 * tick format: gpmc,name = <value> /&zwj;* x ns -- y ns; x ticks *&zwj;/
432 * Where x ns -- y ns result in the same tick value.
453 nr_bits = end_bit - st_bit + 1; in get_gpmc_timing_reg()
454 mask = (1 << nr_bits) - 1; in get_gpmc_timing_reg()
469 time_ns_min = gpmc_clk_ticks_to_ns(l - 1, cs, cd) + 1; in get_gpmc_timing_reg()
471 pr_info("gpmc,%s = <%u>; /* %u ns - %u ns; %i ticks%s*/\n", in get_gpmc_timing_reg()
513 * Note that gpmc,wait-pin handing wrongly assumes bit 8 is available,
521 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 4, 4, "time-para-granularity"); in gpmc_cs_show_timings()
522 GPMC_GET_RAW(GPMC_CS_CONFIG1, 8, 9, "mux-add-data"); in gpmc_cs_show_timings()
524 GPMC_CONFIG1_DEVICESIZE_MAX, "device-width"); in gpmc_cs_show_timings()
525 GPMC_GET_RAW(GPMC_CS_CONFIG1, 16, 17, "wait-pin"); in gpmc_cs_show_timings()
526 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 21, 21, "wait-on-write"); in gpmc_cs_show_timings()
527 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 22, 22, "wait-on-read"); in gpmc_cs_show_timings()
530 "burst-length"); in gpmc_cs_show_timings()
531 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 27, 27, "sync-write"); in gpmc_cs_show_timings()
532 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 28, 28, "burst-write"); in gpmc_cs_show_timings()
533 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 29, 29, "gpmc,sync-read"); in gpmc_cs_show_timings()
534 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 30, 30, "burst-read"); in gpmc_cs_show_timings()
535 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 31, 31, "burst-wrap"); in gpmc_cs_show_timings()
537 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG2, 7, 7, "cs-extra-delay"); in gpmc_cs_show_timings()
539 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG3, 7, 7, "adv-extra-delay"); in gpmc_cs_show_timings()
541 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 23, 23, "we-extra-delay"); in gpmc_cs_show_timings()
542 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 7, 7, "oe-extra-delay"); in gpmc_cs_show_timings()
544 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 7, 7, "cycle2cycle-samecsen"); in gpmc_cs_show_timings()
545 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 6, 6, "cycle2cycle-diffcsen"); in gpmc_cs_show_timings()
548 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 0, 3, "cs-on-ns"); in gpmc_cs_show_timings()
549 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 8, 12, "cs-rd-off-ns"); in gpmc_cs_show_timings()
550 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 16, 20, "cs-wr-off-ns"); in gpmc_cs_show_timings()
552 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 0, 3, "adv-on-ns"); in gpmc_cs_show_timings()
553 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 8, 12, "adv-rd-off-ns"); in gpmc_cs_show_timings()
554 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 16, 20, "adv-wr-off-ns"); in gpmc_cs_show_timings()
556 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 4, 6, "adv-aad-mux-on-ns"); in gpmc_cs_show_timings()
558 "adv-aad-mux-rd-off-ns"); in gpmc_cs_show_timings()
560 "adv-aad-mux-wr-off-ns"); in gpmc_cs_show_timings()
563 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 0, 3, "oe-on-ns"); in gpmc_cs_show_timings()
564 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 8, 12, "oe-off-ns"); in gpmc_cs_show_timings()
566 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 4, 6, "oe-aad-mux-on-ns"); in gpmc_cs_show_timings()
567 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 13, 15, "oe-aad-mux-off-ns"); in gpmc_cs_show_timings()
569 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 16, 19, "we-on-ns"); in gpmc_cs_show_timings()
570 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 24, 28, "we-off-ns"); in gpmc_cs_show_timings()
572 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 0, 4, "rd-cycle-ns"); in gpmc_cs_show_timings()
573 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 8, 12, "wr-cycle-ns"); in gpmc_cs_show_timings()
574 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 16, 20, "access-ns"); in gpmc_cs_show_timings()
576 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 24, 27, "page-burst-access-ns"); in gpmc_cs_show_timings()
578 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 0, 3, "bus-turnaround-ns"); in gpmc_cs_show_timings()
579 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 8, 11, "cycle2cycle-delay-ns"); in gpmc_cs_show_timings()
583 "wait-monitoring-ns", GPMC_CD_CLK); in gpmc_cs_show_timings()
586 "clk-activation-ns", GPMC_CD_FCLK); in gpmc_cs_show_timings()
588 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 16, 19, "wr-data-mux-bus-ns"); in gpmc_cs_show_timings()
589 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 24, 28, "wr-access-ns"); in gpmc_cs_show_timings()
598 * set_gpmc_timing_reg - set a single timing parameter for Chip Select Region.
611 * @return: 0 on success, -1 on error.
623 nr_bits = end_bit - st_bit + 1; in set_gpmc_timing_reg()
624 mask = (1 << nr_bits) - 1; in set_gpmc_timing_reg()
633 return -1; in set_gpmc_timing_reg()
638 pr_info("GPMC CS%d: %-17s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n", in set_gpmc_timing_reg()
650 * gpmc_calc_waitmonitoring_divider - calculate proper GPMCFCLKDIVIDER based on WAITMONITORINGTIME
652 * read --> don't sample bus too early
653 * write --> data is longer on bus
662 * @return: -1 on failure to scale, else proper divider > 0.
668 div += GPMC_CONFIG1_WAITMONITORINGTIME_MAX - 1; in gpmc_calc_waitmonitoring_divider()
672 return -1; in gpmc_calc_waitmonitoring_divider()
680 * gpmc_calc_divider - calculate GPMC_FCLK divider for sync_clk GPMC_CLK period.
683 * Else, returns -1.
690 return -1; in gpmc_calc_divider()
698 * gpmc_cs_set_timings - program timing parameters for Chip Select Region.
702 * @return: 0 on success, -1 on error.
710 div = gpmc_calc_divider(t->sync_clk); in gpmc_cs_set_timings()
712 return -EINVAL; in gpmc_cs_set_timings()
717 * Calculate GPMCFCLKDIVIDER independent of gpmc,sync-clk-ps in DT for in gpmc_cs_set_timings()
727 if (!s->sync_read && !s->sync_write && in gpmc_cs_set_timings()
728 (s->wait_on_read || s->wait_on_write) in gpmc_cs_set_timings()
730 div = gpmc_calc_waitmonitoring_divider(t->wait_monitoring); in gpmc_cs_set_timings()
734 t->wait_monitoring in gpmc_cs_set_timings()
736 return -ENXIO; in gpmc_cs_set_timings()
741 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 0, 3, 0, t->cs_on, in gpmc_cs_set_timings()
743 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 8, 12, 0, t->cs_rd_off, in gpmc_cs_set_timings()
745 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 16, 20, 0, t->cs_wr_off, in gpmc_cs_set_timings()
748 return -ENXIO; in gpmc_cs_set_timings()
750 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 0, 3, 0, t->adv_on, in gpmc_cs_set_timings()
752 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 8, 12, 0, t->adv_rd_off, in gpmc_cs_set_timings()
754 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 16, 20, 0, t->adv_wr_off, in gpmc_cs_set_timings()
757 return -ENXIO; in gpmc_cs_set_timings()
761 t->adv_aad_mux_on, GPMC_CD_FCLK, in gpmc_cs_set_timings()
764 t->adv_aad_mux_rd_off, GPMC_CD_FCLK, in gpmc_cs_set_timings()
767 t->adv_aad_mux_wr_off, GPMC_CD_FCLK, in gpmc_cs_set_timings()
770 return -ENXIO; in gpmc_cs_set_timings()
773 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 0, 3, 0, t->oe_on, in gpmc_cs_set_timings()
775 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 8, 12, 0, t->oe_off, in gpmc_cs_set_timings()
779 t->oe_aad_mux_on, GPMC_CD_FCLK, in gpmc_cs_set_timings()
782 t->oe_aad_mux_off, GPMC_CD_FCLK, in gpmc_cs_set_timings()
785 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 16, 19, 0, t->we_on, in gpmc_cs_set_timings()
787 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 24, 28, 0, t->we_off, in gpmc_cs_set_timings()
790 return -ENXIO; in gpmc_cs_set_timings()
792 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 0, 4, 0, t->rd_cycle, in gpmc_cs_set_timings()
794 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 8, 12, 0, t->wr_cycle, in gpmc_cs_set_timings()
796 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 16, 20, 0, t->access, in gpmc_cs_set_timings()
799 t->page_burst_access, GPMC_CD_FCLK, in gpmc_cs_set_timings()
802 return -ENXIO; in gpmc_cs_set_timings()
805 t->bus_turnaround, GPMC_CD_FCLK, in gpmc_cs_set_timings()
808 t->cycle2cycle_delay, GPMC_CD_FCLK, in gpmc_cs_set_timings()
811 return -ENXIO; in gpmc_cs_set_timings()
815 t->wr_data_mux_bus, GPMC_CD_FCLK, in gpmc_cs_set_timings()
818 return -ENXIO; in gpmc_cs_set_timings()
822 t->wr_access, GPMC_CD_FCLK, in gpmc_cs_set_timings()
825 return -ENXIO; in gpmc_cs_set_timings()
830 l |= (div - 1); in gpmc_cs_set_timings()
836 t->wait_monitoring, GPMC_CD_CLK, in gpmc_cs_set_timings()
840 t->clk_activation, GPMC_CD_FCLK, in gpmc_cs_set_timings()
843 return -ENXIO; in gpmc_cs_set_timings()
850 gpmc_cs_bool_timings(cs, &t->bool_timings); in gpmc_cs_set_timings()
865 if (base & (size - 1)) in gpmc_cs_set_memconf()
866 return -EINVAL; in gpmc_cs_set_memconf()
869 mask = (1 << GPMC_SECTION_SHIFT) - size; in gpmc_cs_set_memconf()
909 *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT); in gpmc_cs_get_memconf()
924 gpmc->flags |= GPMC_CS_RESERVED; in gpmc_cs_set_reserved()
931 return gpmc->flags & GPMC_CS_RESERVED; in gpmc_cs_reserved()
938 size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1); in gpmc_mem_align()
939 order = GPMC_CHUNK_SHIFT - 1; in gpmc_mem_align()
951 struct resource *res = &gpmc->mem; in gpmc_cs_insert_mem()
956 res->start = base; in gpmc_cs_insert_mem()
957 res->end = base + size - 1; in gpmc_cs_insert_mem()
967 struct resource *res = &gpmc->mem; in gpmc_cs_delete_mem()
972 res->start = 0; in gpmc_cs_delete_mem()
973 res->end = 0; in gpmc_cs_delete_mem()
982 struct resource *res = &gpmc->mem; in gpmc_cs_request()
983 int r = -1; in gpmc_cs_request()
986 pr_err("%s: requested chip-select is disabled\n", __func__); in gpmc_cs_request()
987 return -ENODEV; in gpmc_cs_request()
991 return -ENOMEM; in gpmc_cs_request()
996 return -EBUSY; in gpmc_cs_request()
999 r = adjust_resource(res, res->start & ~(size - 1), size); in gpmc_cs_request()
1009 r = gpmc_cs_set_memconf(cs, res->start, resource_size(res)); in gpmc_cs_request()
1017 *base = res->start; in gpmc_cs_request()
1031 WARN(1, "Trying to free non-reserved GPMC CS%d\n", cs); in gpmc_cs_free()
1035 res = &gpmc->mem; in gpmc_cs_free()
1038 if (res->flags) in gpmc_cs_free()
1056 if (!gpmc_is_valid_waitpin(p->wait_pin)) in gpmc_alloc_waitpin()
1057 return -EINVAL; in gpmc_alloc_waitpin()
1059 waitpin = &gpmc->waitpins[p->wait_pin]; in gpmc_alloc_waitpin()
1061 if (!waitpin->desc) { in gpmc_alloc_waitpin()
1066 waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip, in gpmc_alloc_waitpin()
1067 p->wait_pin, "WAITPIN", in gpmc_alloc_waitpin()
1072 if (IS_ERR(waitpin_desc) && ret != -EBUSY) in gpmc_alloc_waitpin()
1076 waitpin->desc = waitpin_desc; in gpmc_alloc_waitpin()
1077 waitpin->pin = p->wait_pin; in gpmc_alloc_waitpin()
1078 waitpin->polarity = p->wait_pin_polarity; in gpmc_alloc_waitpin()
1081 if (p->wait_pin_polarity != waitpin->polarity || in gpmc_alloc_waitpin()
1082 p->wait_pin != waitpin->pin) { in gpmc_alloc_waitpin()
1083 dev_err(gpmc->dev, in gpmc_alloc_waitpin()
1084 "shared-wait-pin: invalid configuration\n"); in gpmc_alloc_waitpin()
1085 return -EINVAL; in gpmc_alloc_waitpin()
1087 dev_info(gpmc->dev, "shared wait-pin: %d\n", waitpin->pin); in gpmc_alloc_waitpin()
1097 gpiochip_free_own_desc(gpmc->waitpins[wait_pin].desc); in gpmc_free_waitpin()
1101 * gpmc_configure - write request to configure gpmc
1122 return -EINVAL; in gpmc_configure()
1142 * gpmc_omap_get_nand_ops - Get the GPMC NAND interface
1156 reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET + in gpmc_omap_get_nand_ops()
1158 reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET + in gpmc_omap_get_nand_ops()
1160 reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET + in gpmc_omap_get_nand_ops()
1162 reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1; in gpmc_omap_get_nand_ops()
1163 reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2; in gpmc_omap_get_nand_ops()
1164 reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL; in gpmc_omap_get_nand_ops()
1165 reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS; in gpmc_omap_get_nand_ops()
1166 reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG; in gpmc_omap_get_nand_ops()
1167 reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL; in gpmc_omap_get_nand_ops()
1168 reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG; in gpmc_omap_get_nand_ops()
1169 reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT; in gpmc_omap_get_nand_ops()
1172 reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 + in gpmc_omap_get_nand_ops()
1174 reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 + in gpmc_omap_get_nand_ops()
1176 reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 + in gpmc_omap_get_nand_ops()
1178 reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 + in gpmc_omap_get_nand_ops()
1180 reg->gpmc_bch_result4[i] = gpmc_base + GPMC_ECC_BCH_RESULT_4 + in gpmc_omap_get_nand_ops()
1182 reg->gpmc_bch_result5[i] = gpmc_base + GPMC_ECC_BCH_RESULT_5 + in gpmc_omap_get_nand_ops()
1184 reg->gpmc_bch_result6[i] = gpmc_base + GPMC_ECC_BCH_RESULT_6 + in gpmc_omap_get_nand_ops()
1246 if (!s->sync_write) { in gpmc_omap_onenand_calc_sync_timings()
1279 gpmc_read_settings_dt(dev->of_node, &gpmc_s); in gpmc_omap_onenand_set_timings()
1281 info->sync_read = gpmc_s.sync_read; in gpmc_omap_onenand_set_timings()
1282 info->sync_write = gpmc_s.sync_write; in gpmc_omap_onenand_set_timings()
1283 info->burst_len = gpmc_s.burst_len; in gpmc_omap_onenand_set_timings()
1319 hwirq += 8 - GPMC_NR_NAND_IRQS; in gpmc_irq_endis()
1333 gpmc_irq_endis(p->hwirq, false); in gpmc_irq_disable()
1338 gpmc_irq_endis(p->hwirq, true); in gpmc_irq_enable()
1343 gpmc_irq_endis(d->hwirq, false); in gpmc_irq_mask()
1348 gpmc_irq_endis(d->hwirq, true); in gpmc_irq_unmask()
1360 hwirq += 8 - GPMC_NR_NAND_IRQS; in gpmc_irq_edge_config()
1373 unsigned int hwirq = d->hwirq; in gpmc_irq_ack()
1377 hwirq += 8 - GPMC_NR_NAND_IRQS; in gpmc_irq_ack()
1386 if (d->hwirq < GPMC_NR_NAND_IRQS) in gpmc_irq_set_type()
1387 return -EINVAL; in gpmc_irq_set_type()
1391 gpmc_irq_edge_config(d->hwirq, false); in gpmc_irq_set_type()
1393 gpmc_irq_edge_config(d->hwirq, true); in gpmc_irq_set_type()
1395 return -EINVAL; in gpmc_irq_set_type()
1403 struct gpmc_device *gpmc = d->host_data; in gpmc_irq_map()
1408 irq_set_chip_and_handler(virq, &gpmc->irq_chip, in gpmc_irq_map()
1411 irq_set_chip_and_handler(virq, &gpmc->irq_chip, in gpmc_irq_map()
1435 for (hwirq = 0; hwirq < gpmc->nirqs; hwirq++) { in gpmc_handle_irq()
1438 regvalx >>= 8 - GPMC_NR_NAND_IRQS; in gpmc_handle_irq()
1443 dev_warn(gpmc->dev, in gpmc_handle_irq()
1469 gpmc->irq_chip.name = "gpmc"; in gpmc_setup_irq()
1470 gpmc->irq_chip.irq_enable = gpmc_irq_enable; in gpmc_setup_irq()
1471 gpmc->irq_chip.irq_disable = gpmc_irq_disable; in gpmc_setup_irq()
1472 gpmc->irq_chip.irq_ack = gpmc_irq_ack; in gpmc_setup_irq()
1473 gpmc->irq_chip.irq_mask = gpmc_irq_mask; in gpmc_setup_irq()
1474 gpmc->irq_chip.irq_unmask = gpmc_irq_unmask; in gpmc_setup_irq()
1475 gpmc->irq_chip.irq_set_type = gpmc_irq_set_type; in gpmc_setup_irq()
1477 gpmc_irq_domain = irq_domain_add_linear(gpmc->dev->of_node, in gpmc_setup_irq()
1478 gpmc->nirqs, in gpmc_setup_irq()
1482 dev_err(gpmc->dev, "IRQ domain add failed\n"); in gpmc_setup_irq()
1483 return -ENODEV; in gpmc_setup_irq()
1486 rc = request_irq(gpmc->irq, gpmc_handle_irq, 0, "gpmc", gpmc); in gpmc_setup_irq()
1488 dev_err(gpmc->dev, "failed to request irq %d: %d\n", in gpmc_setup_irq()
1489 gpmc->irq, rc); in gpmc_setup_irq()
1501 free_irq(gpmc->irq, gpmc); in gpmc_free_irq()
1503 for (hwirq = 0; hwirq < gpmc->nirqs; hwirq++) in gpmc_free_irq()
1527 if (!gpmc->data) { in gpmc_mem_init()
1532 gpmc_mem_root.start = gpmc->data->start; in gpmc_mem_init()
1533 gpmc_mem_root.end = gpmc->data->end; in gpmc_mem_init()
1544 pr_warn("%s: disabling cs %d mapped at 0x%x-0x%x\n", in gpmc_mem_init()
1558 temp = (temp + div - 1) / div; in gpmc_round_ps_to_sync_clk()
1570 temp = dev_t->t_avdp_r; in gpmc_calc_sync_read_timings()
1577 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh); in gpmc_calc_sync_read_timings()
1578 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); in gpmc_calc_sync_read_timings()
1580 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_read_timings()
1583 temp = dev_t->t_oeasu; /* XXX: remove this ? */ in gpmc_calc_sync_read_timings()
1585 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach); in gpmc_calc_sync_read_timings()
1586 temp = max_t(u32, temp, gpmc_t->adv_rd_off + in gpmc_calc_sync_read_timings()
1587 gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe)); in gpmc_calc_sync_read_timings()
1589 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_read_timings()
1596 temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk); in gpmc_calc_sync_read_timings()
1597 temp += gpmc_t->clk_activation; in gpmc_calc_sync_read_timings()
1598 if (dev_t->cyc_oe) in gpmc_calc_sync_read_timings()
1599 temp = max_t(u32, temp, gpmc_t->oe_on + in gpmc_calc_sync_read_timings()
1600 gpmc_ticks_to_ps(dev_t->cyc_oe)); in gpmc_calc_sync_read_timings()
1601 gpmc_t->access = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_read_timings()
1603 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); in gpmc_calc_sync_read_timings()
1604 gpmc_t->cs_rd_off = gpmc_t->oe_off; in gpmc_calc_sync_read_timings()
1607 temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez); in gpmc_calc_sync_read_timings()
1608 temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) + in gpmc_calc_sync_read_timings()
1609 gpmc_t->access; in gpmc_calc_sync_read_timings()
1611 if (dev_t->t_ce_rdyz) in gpmc_calc_sync_read_timings()
1612 temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz); in gpmc_calc_sync_read_timings()
1613 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_read_timings()
1625 temp = dev_t->t_avdp_w; in gpmc_calc_sync_write_timings()
1628 gpmc_t->clk_activation + dev_t->t_avdh); in gpmc_calc_sync_write_timings()
1629 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); in gpmc_calc_sync_write_timings()
1631 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_write_timings()
1634 temp = max_t(u32, dev_t->t_weasu, in gpmc_calc_sync_write_timings()
1635 gpmc_t->clk_activation + dev_t->t_rdyo); in gpmc_calc_sync_write_timings()
1641 gpmc_t->adv_wr_off + dev_t->t_aavdh); in gpmc_calc_sync_write_timings()
1642 temp = max_t(u32, temp, gpmc_t->adv_wr_off + in gpmc_calc_sync_write_timings()
1643 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); in gpmc_calc_sync_write_timings()
1645 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_write_timings()
1649 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); in gpmc_calc_sync_write_timings()
1651 gpmc_t->we_on = gpmc_t->wr_data_mux_bus; in gpmc_calc_sync_write_timings()
1655 gpmc_t->wr_access = gpmc_t->access; in gpmc_calc_sync_write_timings()
1658 temp = gpmc_t->we_on + dev_t->t_wpl; in gpmc_calc_sync_write_timings()
1660 gpmc_t->wr_access + gpmc_ticks_to_ps(1)); in gpmc_calc_sync_write_timings()
1662 gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl)); in gpmc_calc_sync_write_timings()
1663 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_write_timings()
1665 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + in gpmc_calc_sync_write_timings()
1666 dev_t->t_wph); in gpmc_calc_sync_write_timings()
1669 temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk); in gpmc_calc_sync_write_timings()
1670 temp += gpmc_t->wr_access; in gpmc_calc_sync_write_timings()
1672 if (dev_t->t_ce_rdyz) in gpmc_calc_sync_write_timings()
1674 gpmc_t->cs_wr_off + dev_t->t_ce_rdyz); in gpmc_calc_sync_write_timings()
1675 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_write_timings()
1687 temp = dev_t->t_avdp_r; in gpmc_calc_async_read_timings()
1689 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); in gpmc_calc_async_read_timings()
1690 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_read_timings()
1693 temp = dev_t->t_oeasu; in gpmc_calc_async_read_timings()
1695 temp = max_t(u32, temp, gpmc_t->adv_rd_off + dev_t->t_aavdh); in gpmc_calc_async_read_timings()
1696 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_read_timings()
1699 temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */ in gpmc_calc_async_read_timings()
1700 gpmc_t->oe_on + dev_t->t_oe); in gpmc_calc_async_read_timings()
1701 temp = max_t(u32, temp, gpmc_t->cs_on + dev_t->t_ce); in gpmc_calc_async_read_timings()
1702 temp = max_t(u32, temp, gpmc_t->adv_on + dev_t->t_aa); in gpmc_calc_async_read_timings()
1703 gpmc_t->access = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_read_timings()
1705 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); in gpmc_calc_async_read_timings()
1706 gpmc_t->cs_rd_off = gpmc_t->oe_off; in gpmc_calc_async_read_timings()
1709 temp = max_t(u32, dev_t->t_rd_cycle, in gpmc_calc_async_read_timings()
1710 gpmc_t->cs_rd_off + dev_t->t_cez_r); in gpmc_calc_async_read_timings()
1711 temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez); in gpmc_calc_async_read_timings()
1712 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_read_timings()
1724 temp = dev_t->t_avdp_w; in gpmc_calc_async_write_timings()
1726 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); in gpmc_calc_async_write_timings()
1727 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_write_timings()
1730 temp = dev_t->t_weasu; in gpmc_calc_async_write_timings()
1732 temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh); in gpmc_calc_async_write_timings()
1733 temp = max_t(u32, temp, gpmc_t->adv_wr_off + in gpmc_calc_async_write_timings()
1734 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); in gpmc_calc_async_write_timings()
1736 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_write_timings()
1740 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); in gpmc_calc_async_write_timings()
1742 gpmc_t->we_on = gpmc_t->wr_data_mux_bus; in gpmc_calc_async_write_timings()
1745 temp = gpmc_t->we_on + dev_t->t_wpl; in gpmc_calc_async_write_timings()
1746 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_write_timings()
1748 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + in gpmc_calc_async_write_timings()
1749 dev_t->t_wph); in gpmc_calc_async_write_timings()
1752 temp = max_t(u32, dev_t->t_wr_cycle, in gpmc_calc_async_write_timings()
1753 gpmc_t->cs_wr_off + dev_t->t_cez_w); in gpmc_calc_async_write_timings()
1754 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_write_timings()
1764 gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) * in gpmc_calc_sync_common_timings()
1767 gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk( in gpmc_calc_sync_common_timings()
1768 dev_t->t_bacc, in gpmc_calc_sync_common_timings()
1769 gpmc_t->sync_clk); in gpmc_calc_sync_common_timings()
1771 temp = max_t(u32, dev_t->t_ces, dev_t->t_avds); in gpmc_calc_sync_common_timings()
1772 gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_common_timings()
1774 if (gpmc_calc_divider(gpmc_t->sync_clk) != 1) in gpmc_calc_sync_common_timings()
1777 if (dev_t->ce_xdelay) in gpmc_calc_sync_common_timings()
1778 gpmc_t->bool_timings.cs_extra_delay = true; in gpmc_calc_sync_common_timings()
1779 if (dev_t->avd_xdelay) in gpmc_calc_sync_common_timings()
1780 gpmc_t->bool_timings.adv_extra_delay = true; in gpmc_calc_sync_common_timings()
1781 if (dev_t->oe_xdelay) in gpmc_calc_sync_common_timings()
1782 gpmc_t->bool_timings.oe_extra_delay = true; in gpmc_calc_sync_common_timings()
1783 if (dev_t->we_xdelay) in gpmc_calc_sync_common_timings()
1784 gpmc_t->bool_timings.we_extra_delay = true; in gpmc_calc_sync_common_timings()
1796 gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu); in gpmc_calc_common_timings()
1799 temp = dev_t->t_avdasu; in gpmc_calc_common_timings()
1800 if (dev_t->t_ce_avd) in gpmc_calc_common_timings()
1802 gpmc_t->cs_on + dev_t->t_ce_avd); in gpmc_calc_common_timings()
1803 gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp); in gpmc_calc_common_timings()
1818 t->cs_on /= 1000; in gpmc_convert_ps_to_ns()
1819 t->cs_rd_off /= 1000; in gpmc_convert_ps_to_ns()
1820 t->cs_wr_off /= 1000; in gpmc_convert_ps_to_ns()
1821 t->adv_on /= 1000; in gpmc_convert_ps_to_ns()
1822 t->adv_rd_off /= 1000; in gpmc_convert_ps_to_ns()
1823 t->adv_wr_off /= 1000; in gpmc_convert_ps_to_ns()
1824 t->we_on /= 1000; in gpmc_convert_ps_to_ns()
1825 t->we_off /= 1000; in gpmc_convert_ps_to_ns()
1826 t->oe_on /= 1000; in gpmc_convert_ps_to_ns()
1827 t->oe_off /= 1000; in gpmc_convert_ps_to_ns()
1828 t->page_burst_access /= 1000; in gpmc_convert_ps_to_ns()
1829 t->access /= 1000; in gpmc_convert_ps_to_ns()
1830 t->rd_cycle /= 1000; in gpmc_convert_ps_to_ns()
1831 t->wr_cycle /= 1000; in gpmc_convert_ps_to_ns()
1832 t->bus_turnaround /= 1000; in gpmc_convert_ps_to_ns()
1833 t->cycle2cycle_delay /= 1000; in gpmc_convert_ps_to_ns()
1834 t->wait_monitoring /= 1000; in gpmc_convert_ps_to_ns()
1835 t->clk_activation /= 1000; in gpmc_convert_ps_to_ns()
1836 t->wr_access /= 1000; in gpmc_convert_ps_to_ns()
1837 t->wr_data_mux_bus /= 1000; in gpmc_convert_ps_to_ns()
1847 mux = gpmc_s->mux_add_data ? true : false; in gpmc_calc_timings()
1848 sync = (gpmc_s->sync_read || gpmc_s->sync_write); in gpmc_calc_timings()
1855 if (gpmc_s && gpmc_s->sync_read) in gpmc_calc_timings()
1860 if (gpmc_s && gpmc_s->sync_write) in gpmc_calc_timings()
1872 * gpmc_cs_program_settings - programs non-timing related settings
1873 * @cs: GPMC chip-select to program
1876 * Programs non-timing related settings for a GPMC chip-select, such as
1877 * bus-width, burst configuration, etc. Function should be called once
1878 * for each chip-select that is being used and must be called before
1887 if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) { in gpmc_cs_program_settings()
1888 pr_err("%s: invalid width %d!", __func__, p->device_width); in gpmc_cs_program_settings()
1889 return -EINVAL; in gpmc_cs_program_settings()
1892 /* Address-data multiplexing not supported for NAND devices */ in gpmc_cs_program_settings()
1893 if (p->device_nand && p->mux_add_data) { in gpmc_cs_program_settings()
1895 return -EINVAL; in gpmc_cs_program_settings()
1898 if ((p->mux_add_data > GPMC_MUX_AD) || in gpmc_cs_program_settings()
1899 ((p->mux_add_data == GPMC_MUX_AAD) && in gpmc_cs_program_settings()
1902 return -EINVAL; in gpmc_cs_program_settings()
1906 if (p->burst_read || p->burst_write) { in gpmc_cs_program_settings()
1907 switch (p->burst_len) { in gpmc_cs_program_settings()
1913 pr_err("%s: invalid page/burst-length (%d)\n", in gpmc_cs_program_settings()
1914 __func__, p->burst_len); in gpmc_cs_program_settings()
1915 return -EINVAL; in gpmc_cs_program_settings()
1919 if (p->wait_pin != GPMC_WAITPIN_INVALID && in gpmc_cs_program_settings()
1920 p->wait_pin > gpmc_nr_waitpins) { in gpmc_cs_program_settings()
1921 pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin); in gpmc_cs_program_settings()
1922 return -EINVAL; in gpmc_cs_program_settings()
1925 config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1)); in gpmc_cs_program_settings()
1927 if (p->sync_read) in gpmc_cs_program_settings()
1929 if (p->sync_write) in gpmc_cs_program_settings()
1931 if (p->wait_on_read) in gpmc_cs_program_settings()
1933 if (p->wait_on_write) in gpmc_cs_program_settings()
1935 if (p->wait_on_read || p->wait_on_write) in gpmc_cs_program_settings()
1936 config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin); in gpmc_cs_program_settings()
1937 if (p->device_nand) in gpmc_cs_program_settings()
1939 if (p->mux_add_data) in gpmc_cs_program_settings()
1940 config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data); in gpmc_cs_program_settings()
1941 if (p->burst_read) in gpmc_cs_program_settings()
1943 if (p->burst_write) in gpmc_cs_program_settings()
1945 if (p->burst_read || p->burst_write) { in gpmc_cs_program_settings()
1946 config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3); in gpmc_cs_program_settings()
1947 config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0; in gpmc_cs_program_settings()
1952 if (p->wait_pin_polarity != GPMC_WAITPINPOLARITY_INVALID) { in gpmc_cs_program_settings()
1955 if (p->wait_pin_polarity == GPMC_WAITPINPOLARITY_ACTIVE_LOW) in gpmc_cs_program_settings()
1956 config1 &= ~GPMC_CONFIG_WAITPINPOLARITY(p->wait_pin); in gpmc_cs_program_settings()
1957 else if (p->wait_pin_polarity == GPMC_WAITPINPOLARITY_ACTIVE_HIGH) in gpmc_cs_program_settings()
1958 config1 |= GPMC_CONFIG_WAITPINPOLARITY(p->wait_pin); in gpmc_cs_program_settings()
1971 gpmc->name = name; in gpmc_cs_set_name()
1978 return gpmc->name; in gpmc_cs_get_name()
1982 * gpmc_cs_remap - remaps a chip-select physical base address
1983 * @cs: chip-select to remap
1984 * @base: physical base address to re-map chip-select to
1986 * Re-maps a chip-select to a new physical base address specified by
1996 pr_err("%s: requested chip-select is disabled\n", __func__); in gpmc_cs_remap()
1997 return -ENODEV; in gpmc_cs_remap()
2005 base &= ~(SZ_16M - 1); in gpmc_cs_remap()
2025 * gpmc_read_settings_dt - read gpmc settings from device-tree
2026 * @np: pointer to device-tree node for a gpmc child device
2029 * Reads the GPMC settings for a GPMC child device from device-tree and
2038 p->sync_read = of_property_read_bool(np, "gpmc,sync-read"); in gpmc_read_settings_dt()
2039 p->sync_write = of_property_read_bool(np, "gpmc,sync-write"); in gpmc_read_settings_dt()
2040 of_property_read_u32(np, "gpmc,device-width", &p->device_width); in gpmc_read_settings_dt()
2041 of_property_read_u32(np, "gpmc,mux-add-data", &p->mux_add_data); in gpmc_read_settings_dt()
2043 if (!of_property_read_u32(np, "gpmc,burst-length", &p->burst_len)) { in gpmc_read_settings_dt()
2044 p->burst_wrap = of_property_read_bool(np, "gpmc,burst-wrap"); in gpmc_read_settings_dt()
2045 p->burst_read = of_property_read_bool(np, "gpmc,burst-read"); in gpmc_read_settings_dt()
2046 p->burst_write = of_property_read_bool(np, "gpmc,burst-write"); in gpmc_read_settings_dt()
2047 if (!p->burst_read && !p->burst_write) in gpmc_read_settings_dt()
2048 pr_warn("%s: page/burst-length set but not used!\n", in gpmc_read_settings_dt()
2052 p->wait_pin = GPMC_WAITPIN_INVALID; in gpmc_read_settings_dt()
2053 p->wait_pin_polarity = GPMC_WAITPINPOLARITY_INVALID; in gpmc_read_settings_dt()
2055 if (!of_property_read_u32(np, "gpmc,wait-pin", &p->wait_pin)) { in gpmc_read_settings_dt()
2056 if (!gpmc_is_valid_waitpin(p->wait_pin)) { in gpmc_read_settings_dt()
2057 pr_err("%s: Invalid wait-pin (%d)\n", __func__, p->wait_pin); in gpmc_read_settings_dt()
2058 p->wait_pin = GPMC_WAITPIN_INVALID; in gpmc_read_settings_dt()
2061 if (!of_property_read_u32(np, "ti,wait-pin-polarity", in gpmc_read_settings_dt()
2062 &p->wait_pin_polarity)) { in gpmc_read_settings_dt()
2063 if (p->wait_pin_polarity != GPMC_WAITPINPOLARITY_ACTIVE_HIGH && in gpmc_read_settings_dt()
2064 p->wait_pin_polarity != GPMC_WAITPINPOLARITY_ACTIVE_LOW) { in gpmc_read_settings_dt()
2065 pr_err("%s: Invalid wait-pin-polarity (%d)\n", in gpmc_read_settings_dt()
2066 __func__, p->wait_pin_polarity); in gpmc_read_settings_dt()
2067 p->wait_pin_polarity = GPMC_WAITPINPOLARITY_INVALID; in gpmc_read_settings_dt()
2071 p->wait_on_read = of_property_read_bool(np, in gpmc_read_settings_dt()
2072 "gpmc,wait-on-read"); in gpmc_read_settings_dt()
2073 p->wait_on_write = of_property_read_bool(np, in gpmc_read_settings_dt()
2074 "gpmc,wait-on-write"); in gpmc_read_settings_dt()
2075 if (!p->wait_on_read && !p->wait_on_write) in gpmc_read_settings_dt()
2092 of_property_read_u32(np, "gpmc,sync-clk-ps", &gpmc_t->sync_clk); in gpmc_read_timings_dt()
2095 of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on); in gpmc_read_timings_dt()
2096 of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off); in gpmc_read_timings_dt()
2097 of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off); in gpmc_read_timings_dt()
2100 of_property_read_u32(np, "gpmc,adv-on-ns", &gpmc_t->adv_on); in gpmc_read_timings_dt()
2101 of_property_read_u32(np, "gpmc,adv-rd-off-ns", &gpmc_t->adv_rd_off); in gpmc_read_timings_dt()
2102 of_property_read_u32(np, "gpmc,adv-wr-off-ns", &gpmc_t->adv_wr_off); in gpmc_read_timings_dt()
2103 of_property_read_u32(np, "gpmc,adv-aad-mux-on-ns", in gpmc_read_timings_dt()
2104 &gpmc_t->adv_aad_mux_on); in gpmc_read_timings_dt()
2105 of_property_read_u32(np, "gpmc,adv-aad-mux-rd-off-ns", in gpmc_read_timings_dt()
2106 &gpmc_t->adv_aad_mux_rd_off); in gpmc_read_timings_dt()
2107 of_property_read_u32(np, "gpmc,adv-aad-mux-wr-off-ns", in gpmc_read_timings_dt()
2108 &gpmc_t->adv_aad_mux_wr_off); in gpmc_read_timings_dt()
2111 of_property_read_u32(np, "gpmc,we-on-ns", &gpmc_t->we_on); in gpmc_read_timings_dt()
2112 of_property_read_u32(np, "gpmc,we-off-ns", &gpmc_t->we_off); in gpmc_read_timings_dt()
2115 of_property_read_u32(np, "gpmc,oe-on-ns", &gpmc_t->oe_on); in gpmc_read_timings_dt()
2116 of_property_read_u32(np, "gpmc,oe-off-ns", &gpmc_t->oe_off); in gpmc_read_timings_dt()
2117 of_property_read_u32(np, "gpmc,oe-aad-mux-on-ns", in gpmc_read_timings_dt()
2118 &gpmc_t->oe_aad_mux_on); in gpmc_read_timings_dt()
2119 of_property_read_u32(np, "gpmc,oe-aad-mux-off-ns", in gpmc_read_timings_dt()
2120 &gpmc_t->oe_aad_mux_off); in gpmc_read_timings_dt()
2123 of_property_read_u32(np, "gpmc,page-burst-access-ns", in gpmc_read_timings_dt()
2124 &gpmc_t->page_burst_access); in gpmc_read_timings_dt()
2125 of_property_read_u32(np, "gpmc,access-ns", &gpmc_t->access); in gpmc_read_timings_dt()
2126 of_property_read_u32(np, "gpmc,rd-cycle-ns", &gpmc_t->rd_cycle); in gpmc_read_timings_dt()
2127 of_property_read_u32(np, "gpmc,wr-cycle-ns", &gpmc_t->wr_cycle); in gpmc_read_timings_dt()
2128 of_property_read_u32(np, "gpmc,bus-turnaround-ns", in gpmc_read_timings_dt()
2129 &gpmc_t->bus_turnaround); in gpmc_read_timings_dt()
2130 of_property_read_u32(np, "gpmc,cycle2cycle-delay-ns", in gpmc_read_timings_dt()
2131 &gpmc_t->cycle2cycle_delay); in gpmc_read_timings_dt()
2132 of_property_read_u32(np, "gpmc,wait-monitoring-ns", in gpmc_read_timings_dt()
2133 &gpmc_t->wait_monitoring); in gpmc_read_timings_dt()
2134 of_property_read_u32(np, "gpmc,clk-activation-ns", in gpmc_read_timings_dt()
2135 &gpmc_t->clk_activation); in gpmc_read_timings_dt()
2138 of_property_read_u32(np, "gpmc,wr-access-ns", &gpmc_t->wr_access); in gpmc_read_timings_dt()
2139 of_property_read_u32(np, "gpmc,wr-data-mux-bus-ns", in gpmc_read_timings_dt()
2140 &gpmc_t->wr_data_mux_bus); in gpmc_read_timings_dt()
2143 p = &gpmc_t->bool_timings; in gpmc_read_timings_dt()
2145 p->cycle2cyclediffcsen = in gpmc_read_timings_dt()
2146 of_property_read_bool(np, "gpmc,cycle2cycle-diffcsen"); in gpmc_read_timings_dt()
2147 p->cycle2cyclesamecsen = in gpmc_read_timings_dt()
2148 of_property_read_bool(np, "gpmc,cycle2cycle-samecsen"); in gpmc_read_timings_dt()
2149 p->we_extra_delay = of_property_read_bool(np, "gpmc,we-extra-delay"); in gpmc_read_timings_dt()
2150 p->oe_extra_delay = of_property_read_bool(np, "gpmc,oe-extra-delay"); in gpmc_read_timings_dt()
2151 p->adv_extra_delay = of_property_read_bool(np, "gpmc,adv-extra-delay"); in gpmc_read_timings_dt()
2152 p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay"); in gpmc_read_timings_dt()
2153 p->time_para_granularity = in gpmc_read_timings_dt()
2154 of_property_read_bool(np, "gpmc,time-para-granularity"); in gpmc_read_timings_dt()
2158 * gpmc_probe_generic_child - configures the gpmc for a child device
2160 * @child: pointer to device-tree node for child device
2162 * Allocates and configures a GPMC chip-select for a child device.
2178 dev_err(&pdev->dev, "%pOF has no 'reg' property\n", in gpmc_probe_generic_child()
2180 return -ENODEV; in gpmc_probe_generic_child()
2184 dev_err(&pdev->dev, "%pOF has malformed 'reg' property\n", in gpmc_probe_generic_child()
2186 return -ENODEV; in gpmc_probe_generic_child()
2200 dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs); in gpmc_probe_generic_child()
2203 gpmc_cs_set_name(cs, child->full_name); in gpmc_probe_generic_child()
2227 * device-tree we want the NOR flash to be mapped to the in gpmc_probe_generic_child()
2228 * location specified in the device-tree blob. So remap the in gpmc_probe_generic_child()
2234 dev_err(&pdev->dev, "cannot remap GPMC CS %d to %pa\n", in gpmc_probe_generic_child()
2237 dev_info(&pdev->dev, in gpmc_probe_generic_child()
2241 dev_info(&pdev->dev, in gpmc_probe_generic_child()
2251 dev_warn(&pdev->dev, in gpmc_probe_generic_child()
2253 ret = -EINVAL; in gpmc_probe_generic_child()
2258 if (of_node_name_eq(child, "onenand")) { in gpmc_probe_generic_child()
2261 dev_warn(&pdev->dev, in gpmc_probe_generic_child()
2262 "Incompatible OneNAND node: missing compatible"); in gpmc_probe_generic_child()
2263 ret = -EINVAL; in gpmc_probe_generic_child()
2271 of_property_read_u32(child, "nand-bus-width", &val); in gpmc_probe_generic_child()
2280 dev_err(&pdev->dev, "%pOFn: invalid 'nand-bus-width'\n", in gpmc_probe_generic_child()
2282 ret = -EINVAL; in gpmc_probe_generic_child()
2290 ret = of_property_read_u32(child, "bank-width", in gpmc_probe_generic_child()
2293 dev_err(&pdev->dev, in gpmc_probe_generic_child()
2294 "%pOF has no 'gpmc,device-width' property\n", in gpmc_probe_generic_child()
2315 dev_err(&pdev->dev, "failed to set gpmc timings for: %pOFn\n", in gpmc_probe_generic_child()
2320 /* Clear limited address i.e. enable A26-A11 */ in gpmc_probe_generic_child()
2331 if (!of_platform_device_create(child, NULL, &pdev->dev)) in gpmc_probe_generic_child()
2335 if (of_platform_default_populate(child, NULL, &pdev->dev)) in gpmc_probe_generic_child()
2342 dev_err(&pdev->dev, "failed to create gpmc child %pOFn\n", child); in gpmc_probe_generic_child()
2343 ret = -ENODEV; in gpmc_probe_generic_child()
2359 of_match_device(gpmc_dt_ids, &pdev->dev); in gpmc_probe_dt()
2364 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-cs", in gpmc_probe_dt()
2367 pr_err("%s: number of chip-selects not defined\n", __func__); in gpmc_probe_dt()
2370 pr_err("%s: all chip-selects are disabled\n", __func__); in gpmc_probe_dt()
2371 return -EINVAL; in gpmc_probe_dt()
2373 pr_err("%s: number of supported chip-selects cannot be > %d\n", in gpmc_probe_dt()
2375 return -EINVAL; in gpmc_probe_dt()
2378 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins", in gpmc_probe_dt()
2393 for_each_available_child_of_node(pdev->dev.of_node, child) { in gpmc_probe_dt_children()
2396 dev_err(&pdev->dev, "failed to probe DT child '%pOFn': %d\n", in gpmc_probe_dt_children()
2430 return -EINVAL; /* we're input only */ in gpmc_gpio_direction_output()
2453 gpmc->gpio_chip.parent = gpmc->dev; in gpmc_gpio_init()
2454 gpmc->gpio_chip.owner = THIS_MODULE; in gpmc_gpio_init()
2455 gpmc->gpio_chip.label = DEVICE_NAME; in gpmc_gpio_init()
2456 gpmc->gpio_chip.ngpio = gpmc_nr_waitpins; in gpmc_gpio_init()
2457 gpmc->gpio_chip.get_direction = gpmc_gpio_get_direction; in gpmc_gpio_init()
2458 gpmc->gpio_chip.direction_input = gpmc_gpio_direction_input; in gpmc_gpio_init()
2459 gpmc->gpio_chip.direction_output = gpmc_gpio_direction_output; in gpmc_gpio_init()
2460 gpmc->gpio_chip.set = gpmc_gpio_set; in gpmc_gpio_init()
2461 gpmc->gpio_chip.get = gpmc_gpio_get; in gpmc_gpio_init()
2462 gpmc->gpio_chip.base = -1; in gpmc_gpio_init()
2464 ret = devm_gpiochip_add_data(gpmc->dev, &gpmc->gpio_chip, NULL); in gpmc_gpio_init()
2466 dev_err(gpmc->dev, "could not register gpio chip: %d\n", ret); in gpmc_gpio_init()
2481 gpmc_context = &gpmc->context; in omap3_gpmc_save_context()
2483 gpmc_context->sysconfig = gpmc_read_reg(GPMC_SYSCONFIG); in omap3_gpmc_save_context()
2484 gpmc_context->irqenable = gpmc_read_reg(GPMC_IRQENABLE); in omap3_gpmc_save_context()
2485 gpmc_context->timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL); in omap3_gpmc_save_context()
2486 gpmc_context->config = gpmc_read_reg(GPMC_CONFIG); in omap3_gpmc_save_context()
2487 gpmc_context->prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1); in omap3_gpmc_save_context()
2488 gpmc_context->prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2); in omap3_gpmc_save_context()
2489 gpmc_context->prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL); in omap3_gpmc_save_context()
2491 gpmc_context->cs_context[i].is_valid = gpmc_cs_mem_enabled(i); in omap3_gpmc_save_context()
2492 if (gpmc_context->cs_context[i].is_valid) { in omap3_gpmc_save_context()
2493 gpmc_context->cs_context[i].config1 = in omap3_gpmc_save_context()
2495 gpmc_context->cs_context[i].config2 = in omap3_gpmc_save_context()
2497 gpmc_context->cs_context[i].config3 = in omap3_gpmc_save_context()
2499 gpmc_context->cs_context[i].config4 = in omap3_gpmc_save_context()
2501 gpmc_context->cs_context[i].config5 = in omap3_gpmc_save_context()
2503 gpmc_context->cs_context[i].config6 = in omap3_gpmc_save_context()
2505 gpmc_context->cs_context[i].config7 = in omap3_gpmc_save_context()
2519 gpmc_context = &gpmc->context; in omap3_gpmc_restore_context()
2521 gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context->sysconfig); in omap3_gpmc_restore_context()
2522 gpmc_write_reg(GPMC_IRQENABLE, gpmc_context->irqenable); in omap3_gpmc_restore_context()
2523 gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context->timeout_ctrl); in omap3_gpmc_restore_context()
2524 gpmc_write_reg(GPMC_CONFIG, gpmc_context->config); in omap3_gpmc_restore_context()
2525 gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context->prefetch_config1); in omap3_gpmc_restore_context()
2526 gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context->prefetch_config2); in omap3_gpmc_restore_context()
2527 gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context->prefetch_control); in omap3_gpmc_restore_context()
2529 if (gpmc_context->cs_context[i].is_valid) { in omap3_gpmc_restore_context()
2531 gpmc_context->cs_context[i].config1); in omap3_gpmc_restore_context()
2533 gpmc_context->cs_context[i].config2); in omap3_gpmc_restore_context()
2535 gpmc_context->cs_context[i].config3); in omap3_gpmc_restore_context()
2537 gpmc_context->cs_context[i].config4); in omap3_gpmc_restore_context()
2539 gpmc_context->cs_context[i].config5); in omap3_gpmc_restore_context()
2541 gpmc_context->cs_context[i].config6); in omap3_gpmc_restore_context()
2543 gpmc_context->cs_context[i].config7); in omap3_gpmc_restore_context()
2556 if (gpmc->is_suspended || pm_runtime_suspended(gpmc->dev)) in omap_gpmc_context_notifier()
2580 gpmc = devm_kzalloc(&pdev->dev, sizeof(*gpmc), GFP_KERNEL); in gpmc_probe()
2582 return -ENOMEM; in gpmc_probe()
2584 gpmc->dev = &pdev->dev; in gpmc_probe()
2594 gpmc_base = devm_ioremap_resource(&pdev->dev, res); in gpmc_probe()
2600 dev_err(&pdev->dev, "couldn't get data reg resource\n"); in gpmc_probe()
2601 return -ENOENT; in gpmc_probe()
2604 gpmc->data = res; in gpmc_probe()
2607 gpmc->irq = platform_get_irq(pdev, 0); in gpmc_probe()
2608 if (gpmc->irq < 0) in gpmc_probe()
2609 return gpmc->irq; in gpmc_probe()
2611 gpmc_l3_clk = devm_clk_get(&pdev->dev, "fck"); in gpmc_probe()
2613 dev_err(&pdev->dev, "Failed to get GPMC fck\n"); in gpmc_probe()
2618 dev_err(&pdev->dev, "Invalid GPMC fck clock rate\n"); in gpmc_probe()
2619 return -EINVAL; in gpmc_probe()
2622 if (pdev->dev.of_node) { in gpmc_probe()
2631 gpmc->waitpins = devm_kzalloc(&pdev->dev, in gpmc_probe()
2634 if (!gpmc->waitpins) in gpmc_probe()
2635 return -ENOMEM; in gpmc_probe()
2638 gpmc->waitpins[i].pin = GPMC_WAITPIN_INVALID; in gpmc_probe()
2640 pm_runtime_enable(&pdev->dev); in gpmc_probe()
2641 pm_runtime_get_sync(&pdev->dev); in gpmc_probe()
2646 * FIXME: Once device-tree migration is complete the below flags in gpmc_probe()
2647 * should be populated based upon the device-tree compatible in gpmc_probe()
2650 * devices support the addr-addr-data multiplex protocol. in gpmc_probe()
2653 * - OMAP24xx = 2.0 in gpmc_probe()
2654 * - OMAP3xxx = 5.0 in gpmc_probe()
2655 * - OMAP44xx/54xx/AM335x = 6.0 in gpmc_probe()
2661 dev_info(gpmc->dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l), in gpmc_probe()
2669 gpmc->nirqs = GPMC_NR_NAND_IRQS + gpmc_nr_waitpins; in gpmc_probe()
2672 dev_err(gpmc->dev, "gpmc_setup_irq failed\n"); in gpmc_probe()
2678 gpmc->nb.notifier_call = omap_gpmc_context_notifier; in gpmc_probe()
2679 cpu_pm_register_notifier(&gpmc->nb); in gpmc_probe()
2685 pm_runtime_put_sync(&pdev->dev); in gpmc_probe()
2686 pm_runtime_disable(&pdev->dev); in gpmc_probe()
2696 cpu_pm_unregister_notifier(&gpmc->nb); in gpmc_remove()
2701 pm_runtime_put_sync(&pdev->dev); in gpmc_remove()
2702 pm_runtime_disable(&pdev->dev); in gpmc_remove()
2712 gpmc->is_suspended = 1; in gpmc_suspend()
2723 gpmc->is_suspended = 0; in gpmc_resume()
2733 { .compatible = "ti,omap2420-gpmc" },
2734 { .compatible = "ti,omap2430-gpmc" },
2735 { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */
2736 { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */
2737 { .compatible = "ti,am3352-gpmc" }, /* am335x devices */
2738 { .compatible = "ti,am64-gpmc" },