Lines Matching +full:am3352 +full:- +full:gpmc
1 // SPDX-License-Identifier: GPL-2.0-only
3 * GPMC support functions
5 * Copyright (C) 2005-2006 Nokia Corporation
10 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
32 #include <linux/omap-gpmc.h>
36 #include <linux/platform_data/mtd-nand-omap2.h>
38 #define DEVICE_NAME "omap-gpmc"
40 /* GPMC register offsets */
67 /* GPMC ECC control settings */
96 * The first 1MB of GPMC address space is typically mapped to
99 * As GPMC minimum partition size is 16MB we can only start from
205 /* Structure to save gpmc cs context */
218 * Structure to save/restore gpmc context
249 /* Define chip-selects as reserved by default until probe completes */
297 * gpmc_get_clk_period - get period of selected clock domain in ps
334 return (time_ns * 1000 + tick_ps - 1) / tick_ps; in gpmc_ns_to_clk_ticks()
349 return (time_ps + tick_ps - 1) / tick_ps; in gpmc_ps_to_ticks()
391 p->time_para_granularity); in gpmc_cs_bool_timings()
393 GPMC_CONFIG2_CSEXTRADELAY, p->cs_extra_delay); in gpmc_cs_bool_timings()
395 GPMC_CONFIG3_ADVEXTRADELAY, p->adv_extra_delay); in gpmc_cs_bool_timings()
397 GPMC_CONFIG4_OEEXTRADELAY, p->oe_extra_delay); in gpmc_cs_bool_timings()
399 GPMC_CONFIG4_WEEXTRADELAY, p->we_extra_delay); in gpmc_cs_bool_timings()
402 p->cycle2cyclesamecsen); in gpmc_cs_bool_timings()
405 p->cycle2cyclediffcsen); in gpmc_cs_bool_timings()
410 * get_gpmc_timing_reg - read a timing parameter and print DTS settings for it.
417 * @name: DTS node name, w/o "gpmc,"
421 * raw format: gpmc,name = <value>
422 * tick format: gpmc,name = <value> /‍* x ns -- y ns; x ticks *‍/
423 * Where x ns -- y ns result in the same tick value.
444 nr_bits = end_bit - st_bit + 1; in get_gpmc_timing_reg()
445 mask = (1 << nr_bits) - 1; in get_gpmc_timing_reg()
460 time_ns_min = gpmc_clk_ticks_to_ns(l - 1, cs, cd) + 1; in get_gpmc_timing_reg()
462 pr_info("gpmc,%s = <%u>; /* %u ns - %u ns; %i ticks%s*/\n", in get_gpmc_timing_reg()
467 pr_info("gpmc,%s = <%u>;%s\n", name, l, in get_gpmc_timing_reg()
494 pr_info("gpmc cs%i %s:\n", cs, desc); in gpmc_show_regs()
504 * Note that gpmc,wait-pin handing wrongly assumes bit 8 is available,
511 pr_info("gpmc cs%i access configuration:\n", cs); in gpmc_cs_show_timings()
512 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 4, 4, "time-para-granularity"); in gpmc_cs_show_timings()
513 GPMC_GET_RAW(GPMC_CS_CONFIG1, 8, 9, "mux-add-data"); in gpmc_cs_show_timings()
515 GPMC_CONFIG1_DEVICESIZE_MAX, "device-width"); in gpmc_cs_show_timings()
516 GPMC_GET_RAW(GPMC_CS_CONFIG1, 16, 17, "wait-pin"); in gpmc_cs_show_timings()
517 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 21, 21, "wait-on-write"); in gpmc_cs_show_timings()
518 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 22, 22, "wait-on-read"); in gpmc_cs_show_timings()
521 "burst-length"); in gpmc_cs_show_timings()
522 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 27, 27, "sync-write"); in gpmc_cs_show_timings()
523 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 28, 28, "burst-write"); in gpmc_cs_show_timings()
524 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 29, 29, "gpmc,sync-read"); in gpmc_cs_show_timings()
525 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 30, 30, "burst-read"); in gpmc_cs_show_timings()
526 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG1, 31, 31, "burst-wrap"); in gpmc_cs_show_timings()
528 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG2, 7, 7, "cs-extra-delay"); in gpmc_cs_show_timings()
530 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG3, 7, 7, "adv-extra-delay"); in gpmc_cs_show_timings()
532 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 23, 23, "we-extra-delay"); in gpmc_cs_show_timings()
533 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG4, 7, 7, "oe-extra-delay"); in gpmc_cs_show_timings()
535 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 7, 7, "cycle2cycle-samecsen"); in gpmc_cs_show_timings()
536 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG6, 6, 6, "cycle2cycle-diffcsen"); in gpmc_cs_show_timings()
538 pr_info("gpmc cs%i timings configuration:\n", cs); in gpmc_cs_show_timings()
539 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 0, 3, "cs-on-ns"); in gpmc_cs_show_timings()
540 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 8, 12, "cs-rd-off-ns"); in gpmc_cs_show_timings()
541 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 16, 20, "cs-wr-off-ns"); in gpmc_cs_show_timings()
543 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 0, 3, "adv-on-ns"); in gpmc_cs_show_timings()
544 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 8, 12, "adv-rd-off-ns"); in gpmc_cs_show_timings()
545 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 16, 20, "adv-wr-off-ns"); in gpmc_cs_show_timings()
547 GPMC_GET_TICKS(GPMC_CS_CONFIG3, 4, 6, "adv-aad-mux-on-ns"); in gpmc_cs_show_timings()
549 "adv-aad-mux-rd-off-ns"); in gpmc_cs_show_timings()
551 "adv-aad-mux-wr-off-ns"); in gpmc_cs_show_timings()
554 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 0, 3, "oe-on-ns"); in gpmc_cs_show_timings()
555 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 8, 12, "oe-off-ns"); in gpmc_cs_show_timings()
557 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 4, 6, "oe-aad-mux-on-ns"); in gpmc_cs_show_timings()
558 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 13, 15, "oe-aad-mux-off-ns"); in gpmc_cs_show_timings()
560 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 16, 19, "we-on-ns"); in gpmc_cs_show_timings()
561 GPMC_GET_TICKS(GPMC_CS_CONFIG4, 24, 28, "we-off-ns"); in gpmc_cs_show_timings()
563 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 0, 4, "rd-cycle-ns"); in gpmc_cs_show_timings()
564 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 8, 12, "wr-cycle-ns"); in gpmc_cs_show_timings()
565 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 16, 20, "access-ns"); in gpmc_cs_show_timings()
567 GPMC_GET_TICKS(GPMC_CS_CONFIG5, 24, 27, "page-burst-access-ns"); in gpmc_cs_show_timings()
569 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 0, 3, "bus-turnaround-ns"); in gpmc_cs_show_timings()
570 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 8, 11, "cycle2cycle-delay-ns"); in gpmc_cs_show_timings()
574 "wait-monitoring-ns", GPMC_CD_CLK); in gpmc_cs_show_timings()
577 "clk-activation-ns", GPMC_CD_FCLK); in gpmc_cs_show_timings()
579 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 16, 19, "wr-data-mux-bus-ns"); in gpmc_cs_show_timings()
580 GPMC_GET_TICKS(GPMC_CS_CONFIG6, 24, 28, "wr-access-ns"); in gpmc_cs_show_timings()
589 * set_gpmc_timing_reg - set a single timing parameter for Chip Select Region.
602 * @return: 0 on success, -1 on error.
614 nr_bits = end_bit - st_bit + 1; in set_gpmc_timing_reg()
615 mask = (1 << nr_bits) - 1; in set_gpmc_timing_reg()
621 pr_err("%s: GPMC CS%d: %s %d ns, %d ticks > %d ticks\n", in set_gpmc_timing_reg()
624 return -1; in set_gpmc_timing_reg()
629 pr_info("GPMC CS%d: %-17s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n", in set_gpmc_timing_reg()
641 * gpmc_calc_waitmonitoring_divider - calculate proper GPMCFCLKDIVIDER based on WAITMONITORINGTIME
643 * read --> don't sample bus too early
644 * write --> data is longer on bus
653 * @return: -1 on failure to scale, else proper divider > 0.
659 div += GPMC_CONFIG1_WAITMONITORINGTIME_MAX - 1; in gpmc_calc_waitmonitoring_divider()
663 return -1; in gpmc_calc_waitmonitoring_divider()
671 * gpmc_calc_divider - calculate GPMC_FCLK divider for sync_clk GPMC_CLK period.
674 * Else, returns -1.
681 return -1; in gpmc_calc_divider()
689 * gpmc_cs_set_timings - program timing parameters for Chip Select Region.
691 * @t: GPMC timing parameters.
692 * @s: GPMC timing settings.
693 * @return: 0 on success, -1 on error.
701 div = gpmc_calc_divider(t->sync_clk); in gpmc_cs_set_timings()
703 return -EINVAL; in gpmc_cs_set_timings()
708 * Calculate GPMCFCLKDIVIDER independent of gpmc,sync-clk-ps in DT for in gpmc_cs_set_timings()
718 if (!s->sync_read && !s->sync_write && in gpmc_cs_set_timings()
719 (s->wait_on_read || s->wait_on_write) in gpmc_cs_set_timings()
721 div = gpmc_calc_waitmonitoring_divider(t->wait_monitoring); in gpmc_cs_set_timings()
725 t->wait_monitoring in gpmc_cs_set_timings()
727 return -ENXIO; in gpmc_cs_set_timings()
732 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 0, 3, 0, t->cs_on, in gpmc_cs_set_timings()
734 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 8, 12, 0, t->cs_rd_off, in gpmc_cs_set_timings()
736 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 16, 20, 0, t->cs_wr_off, in gpmc_cs_set_timings()
739 return -ENXIO; in gpmc_cs_set_timings()
741 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 0, 3, 0, t->adv_on, in gpmc_cs_set_timings()
743 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 8, 12, 0, t->adv_rd_off, in gpmc_cs_set_timings()
745 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 16, 20, 0, t->adv_wr_off, in gpmc_cs_set_timings()
748 return -ENXIO; in gpmc_cs_set_timings()
752 t->adv_aad_mux_on, GPMC_CD_FCLK, in gpmc_cs_set_timings()
755 t->adv_aad_mux_rd_off, GPMC_CD_FCLK, in gpmc_cs_set_timings()
758 t->adv_aad_mux_wr_off, GPMC_CD_FCLK, in gpmc_cs_set_timings()
761 return -ENXIO; in gpmc_cs_set_timings()
764 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 0, 3, 0, t->oe_on, in gpmc_cs_set_timings()
766 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 8, 12, 0, t->oe_off, in gpmc_cs_set_timings()
770 t->oe_aad_mux_on, GPMC_CD_FCLK, in gpmc_cs_set_timings()
773 t->oe_aad_mux_off, GPMC_CD_FCLK, in gpmc_cs_set_timings()
776 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 16, 19, 0, t->we_on, in gpmc_cs_set_timings()
778 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 24, 28, 0, t->we_off, in gpmc_cs_set_timings()
781 return -ENXIO; in gpmc_cs_set_timings()
783 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 0, 4, 0, t->rd_cycle, in gpmc_cs_set_timings()
785 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 8, 12, 0, t->wr_cycle, in gpmc_cs_set_timings()
787 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 16, 20, 0, t->access, in gpmc_cs_set_timings()
790 t->page_burst_access, GPMC_CD_FCLK, in gpmc_cs_set_timings()
793 return -ENXIO; in gpmc_cs_set_timings()
796 t->bus_turnaround, GPMC_CD_FCLK, in gpmc_cs_set_timings()
799 t->cycle2cycle_delay, GPMC_CD_FCLK, in gpmc_cs_set_timings()
802 return -ENXIO; in gpmc_cs_set_timings()
806 t->wr_data_mux_bus, GPMC_CD_FCLK, in gpmc_cs_set_timings()
809 return -ENXIO; in gpmc_cs_set_timings()
813 t->wr_access, GPMC_CD_FCLK, in gpmc_cs_set_timings()
816 return -ENXIO; in gpmc_cs_set_timings()
821 l |= (div - 1); in gpmc_cs_set_timings()
827 t->wait_monitoring, GPMC_CD_CLK, in gpmc_cs_set_timings()
831 t->clk_activation, GPMC_CD_FCLK, in gpmc_cs_set_timings()
834 return -ENXIO; in gpmc_cs_set_timings()
837 pr_info("GPMC CS%d CLK period is %lu ns (div %d)\n", in gpmc_cs_set_timings()
841 gpmc_cs_bool_timings(cs, &t->bool_timings); in gpmc_cs_set_timings()
856 if (base & (size - 1)) in gpmc_cs_set_memconf()
857 return -EINVAL; in gpmc_cs_set_memconf()
860 mask = (1 << GPMC_SECTION_SHIFT) - size; in gpmc_cs_set_memconf()
900 *size = (1 << GPMC_SECTION_SHIFT) - (mask << GPMC_CHUNK_SHIFT); in gpmc_cs_get_memconf()
913 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_set_reserved() local
915 gpmc->flags |= GPMC_CS_RESERVED; in gpmc_cs_set_reserved()
920 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_reserved() local
922 return gpmc->flags & GPMC_CS_RESERVED; in gpmc_cs_reserved()
929 size = (size - 1) >> (GPMC_CHUNK_SHIFT - 1); in gpmc_mem_align()
930 order = GPMC_CHUNK_SHIFT - 1; in gpmc_mem_align()
941 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_insert_mem() local
942 struct resource *res = &gpmc->mem; in gpmc_cs_insert_mem()
947 res->start = base; in gpmc_cs_insert_mem()
948 res->end = base + size - 1; in gpmc_cs_insert_mem()
957 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_delete_mem() local
958 struct resource *res = &gpmc->mem; in gpmc_cs_delete_mem()
963 res->start = 0; in gpmc_cs_delete_mem()
964 res->end = 0; in gpmc_cs_delete_mem()
972 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_request() local
973 struct resource *res = &gpmc->mem; in gpmc_cs_request()
974 int r = -1; in gpmc_cs_request()
977 pr_err("%s: requested chip-select is disabled\n", __func__); in gpmc_cs_request()
978 return -ENODEV; in gpmc_cs_request()
982 return -ENOMEM; in gpmc_cs_request()
986 r = -EBUSY; in gpmc_cs_request()
990 r = adjust_resource(res, res->start & ~(size - 1), size); in gpmc_cs_request()
1000 r = gpmc_cs_set_memconf(cs, res->start, resource_size(res)); in gpmc_cs_request()
1008 *base = res->start; in gpmc_cs_request()
1018 struct gpmc_cs_data *gpmc; in gpmc_cs_free() local
1023 WARN(1, "Trying to free non-reserved GPMC CS%d\n", cs); in gpmc_cs_free()
1027 gpmc = &gpmc_cs[cs]; in gpmc_cs_free()
1028 res = &gpmc->mem; in gpmc_cs_free()
1031 if (res->flags) in gpmc_cs_free()
1039 * gpmc_configure - write request to configure gpmc
1060 return -EINVAL; in gpmc_configure()
1080 * gpmc_omap_get_nand_ops - Get the GPMC NAND interface
1081 * @reg: the GPMC NAND register map exclusive for NAND use.
1082 * @cs: GPMC chip select number on which the NAND sits. The
1094 reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET + in gpmc_omap_get_nand_ops()
1096 reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET + in gpmc_omap_get_nand_ops()
1098 reg->gpmc_nand_data = gpmc_base + GPMC_CS0_OFFSET + in gpmc_omap_get_nand_ops()
1100 reg->gpmc_prefetch_config1 = gpmc_base + GPMC_PREFETCH_CONFIG1; in gpmc_omap_get_nand_ops()
1101 reg->gpmc_prefetch_config2 = gpmc_base + GPMC_PREFETCH_CONFIG2; in gpmc_omap_get_nand_ops()
1102 reg->gpmc_prefetch_control = gpmc_base + GPMC_PREFETCH_CONTROL; in gpmc_omap_get_nand_ops()
1103 reg->gpmc_prefetch_status = gpmc_base + GPMC_PREFETCH_STATUS; in gpmc_omap_get_nand_ops()
1104 reg->gpmc_ecc_config = gpmc_base + GPMC_ECC_CONFIG; in gpmc_omap_get_nand_ops()
1105 reg->gpmc_ecc_control = gpmc_base + GPMC_ECC_CONTROL; in gpmc_omap_get_nand_ops()
1106 reg->gpmc_ecc_size_config = gpmc_base + GPMC_ECC_SIZE_CONFIG; in gpmc_omap_get_nand_ops()
1107 reg->gpmc_ecc1_result = gpmc_base + GPMC_ECC1_RESULT; in gpmc_omap_get_nand_ops()
1110 reg->gpmc_bch_result0[i] = gpmc_base + GPMC_ECC_BCH_RESULT_0 + in gpmc_omap_get_nand_ops()
1112 reg->gpmc_bch_result1[i] = gpmc_base + GPMC_ECC_BCH_RESULT_1 + in gpmc_omap_get_nand_ops()
1114 reg->gpmc_bch_result2[i] = gpmc_base + GPMC_ECC_BCH_RESULT_2 + in gpmc_omap_get_nand_ops()
1116 reg->gpmc_bch_result3[i] = gpmc_base + GPMC_ECC_BCH_RESULT_3 + in gpmc_omap_get_nand_ops()
1118 reg->gpmc_bch_result4[i] = gpmc_base + GPMC_ECC_BCH_RESULT_4 + in gpmc_omap_get_nand_ops()
1120 reg->gpmc_bch_result5[i] = gpmc_base + GPMC_ECC_BCH_RESULT_5 + in gpmc_omap_get_nand_ops()
1122 reg->gpmc_bch_result6[i] = gpmc_base + GPMC_ECC_BCH_RESULT_6 + in gpmc_omap_get_nand_ops()
1184 if (!s->sync_write) { in gpmc_omap_onenand_calc_sync_timings()
1217 gpmc_read_settings_dt(dev->of_node, &gpmc_s); in gpmc_omap_onenand_set_timings()
1219 info->sync_read = gpmc_s.sync_read; in gpmc_omap_onenand_set_timings()
1220 info->sync_write = gpmc_s.sync_write; in gpmc_omap_onenand_set_timings()
1221 info->burst_len = gpmc_s.burst_len; in gpmc_omap_onenand_set_timings()
1239 pr_warn("%s called before GPMC IRQ domain available\n", in gpmc_get_client_irq()
1257 hwirq += 8 - GPMC_NR_NAND_IRQS; in gpmc_irq_endis()
1271 gpmc_irq_endis(p->hwirq, false); in gpmc_irq_disable()
1276 gpmc_irq_endis(p->hwirq, true); in gpmc_irq_enable()
1281 gpmc_irq_endis(d->hwirq, false); in gpmc_irq_mask()
1286 gpmc_irq_endis(d->hwirq, true); in gpmc_irq_unmask()
1298 hwirq += 8 - GPMC_NR_NAND_IRQS; in gpmc_irq_edge_config()
1311 unsigned int hwirq = d->hwirq; in gpmc_irq_ack()
1315 hwirq += 8 - GPMC_NR_NAND_IRQS; in gpmc_irq_ack()
1324 if (d->hwirq < GPMC_NR_NAND_IRQS) in gpmc_irq_set_type()
1325 return -EINVAL; in gpmc_irq_set_type()
1329 gpmc_irq_edge_config(d->hwirq, false); in gpmc_irq_set_type()
1331 gpmc_irq_edge_config(d->hwirq, true); in gpmc_irq_set_type()
1333 return -EINVAL; in gpmc_irq_set_type()
1341 struct gpmc_device *gpmc = d->host_data; in gpmc_irq_map() local
1343 irq_set_chip_data(virq, gpmc); in gpmc_irq_map()
1346 irq_set_chip_and_handler(virq, &gpmc->irq_chip, in gpmc_irq_map()
1349 irq_set_chip_and_handler(virq, &gpmc->irq_chip, in gpmc_irq_map()
1365 struct gpmc_device *gpmc = data; in gpmc_handle_irq() local
1373 for (hwirq = 0; hwirq < gpmc->nirqs; hwirq++) { in gpmc_handle_irq()
1376 regvalx >>= 8 - GPMC_NR_NAND_IRQS; in gpmc_handle_irq()
1381 dev_warn(gpmc->dev, in gpmc_handle_irq()
1395 static int gpmc_setup_irq(struct gpmc_device *gpmc) in gpmc_setup_irq() argument
1407 gpmc->irq_chip.name = "gpmc"; in gpmc_setup_irq()
1408 gpmc->irq_chip.irq_enable = gpmc_irq_enable; in gpmc_setup_irq()
1409 gpmc->irq_chip.irq_disable = gpmc_irq_disable; in gpmc_setup_irq()
1410 gpmc->irq_chip.irq_ack = gpmc_irq_ack; in gpmc_setup_irq()
1411 gpmc->irq_chip.irq_mask = gpmc_irq_mask; in gpmc_setup_irq()
1412 gpmc->irq_chip.irq_unmask = gpmc_irq_unmask; in gpmc_setup_irq()
1413 gpmc->irq_chip.irq_set_type = gpmc_irq_set_type; in gpmc_setup_irq()
1415 gpmc_irq_domain = irq_domain_add_linear(gpmc->dev->of_node, in gpmc_setup_irq()
1416 gpmc->nirqs, in gpmc_setup_irq()
1418 gpmc); in gpmc_setup_irq()
1420 dev_err(gpmc->dev, "IRQ domain add failed\n"); in gpmc_setup_irq()
1421 return -ENODEV; in gpmc_setup_irq()
1424 rc = request_irq(gpmc->irq, gpmc_handle_irq, 0, "gpmc", gpmc); in gpmc_setup_irq()
1426 dev_err(gpmc->dev, "failed to request irq %d: %d\n", in gpmc_setup_irq()
1427 gpmc->irq, rc); in gpmc_setup_irq()
1435 static int gpmc_free_irq(struct gpmc_device *gpmc) in gpmc_free_irq() argument
1439 free_irq(gpmc->irq, gpmc); in gpmc_free_irq()
1441 for (hwirq = 0; hwirq < gpmc->nirqs; hwirq++) in gpmc_free_irq()
1461 static void gpmc_mem_init(struct gpmc_device *gpmc) in gpmc_mem_init() argument
1465 if (!gpmc->data) { in gpmc_mem_init()
1470 gpmc_mem_root.start = gpmc->data->start; in gpmc_mem_init()
1471 gpmc_mem_root.end = gpmc->data->end; in gpmc_mem_init()
1482 pr_warn("%s: disabling cs %d mapped at 0x%x-0x%x\n", in gpmc_mem_init()
1496 temp = (temp + div - 1) / div; in gpmc_round_ps_to_sync_clk()
1508 temp = dev_t->t_avdp_r; in gpmc_calc_sync_read_timings()
1515 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_avdh); in gpmc_calc_sync_read_timings()
1516 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); in gpmc_calc_sync_read_timings()
1518 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_read_timings()
1521 temp = dev_t->t_oeasu; /* XXX: remove this ? */ in gpmc_calc_sync_read_timings()
1523 temp = max_t(u32, temp, gpmc_t->clk_activation + dev_t->t_ach); in gpmc_calc_sync_read_timings()
1524 temp = max_t(u32, temp, gpmc_t->adv_rd_off + in gpmc_calc_sync_read_timings()
1525 gpmc_ticks_to_ps(dev_t->cyc_aavdh_oe)); in gpmc_calc_sync_read_timings()
1527 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_read_timings()
1534 temp = max_t(u32, dev_t->t_iaa, dev_t->cyc_iaa * gpmc_t->sync_clk); in gpmc_calc_sync_read_timings()
1535 temp += gpmc_t->clk_activation; in gpmc_calc_sync_read_timings()
1536 if (dev_t->cyc_oe) in gpmc_calc_sync_read_timings()
1537 temp = max_t(u32, temp, gpmc_t->oe_on + in gpmc_calc_sync_read_timings()
1538 gpmc_ticks_to_ps(dev_t->cyc_oe)); in gpmc_calc_sync_read_timings()
1539 gpmc_t->access = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_read_timings()
1541 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); in gpmc_calc_sync_read_timings()
1542 gpmc_t->cs_rd_off = gpmc_t->oe_off; in gpmc_calc_sync_read_timings()
1545 temp = max_t(u32, dev_t->t_cez_r, dev_t->t_oez); in gpmc_calc_sync_read_timings()
1546 temp = gpmc_round_ps_to_sync_clk(temp, gpmc_t->sync_clk) + in gpmc_calc_sync_read_timings()
1547 gpmc_t->access; in gpmc_calc_sync_read_timings()
1549 if (dev_t->t_ce_rdyz) in gpmc_calc_sync_read_timings()
1550 temp = max_t(u32, temp, gpmc_t->cs_rd_off + dev_t->t_ce_rdyz); in gpmc_calc_sync_read_timings()
1551 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_read_timings()
1563 temp = dev_t->t_avdp_w; in gpmc_calc_sync_write_timings()
1566 gpmc_t->clk_activation + dev_t->t_avdh); in gpmc_calc_sync_write_timings()
1567 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); in gpmc_calc_sync_write_timings()
1569 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_write_timings()
1572 temp = max_t(u32, dev_t->t_weasu, in gpmc_calc_sync_write_timings()
1573 gpmc_t->clk_activation + dev_t->t_rdyo); in gpmc_calc_sync_write_timings()
1579 gpmc_t->adv_wr_off + dev_t->t_aavdh); in gpmc_calc_sync_write_timings()
1580 temp = max_t(u32, temp, gpmc_t->adv_wr_off + in gpmc_calc_sync_write_timings()
1581 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); in gpmc_calc_sync_write_timings()
1583 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_write_timings()
1587 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); in gpmc_calc_sync_write_timings()
1589 gpmc_t->we_on = gpmc_t->wr_data_mux_bus; in gpmc_calc_sync_write_timings()
1593 gpmc_t->wr_access = gpmc_t->access; in gpmc_calc_sync_write_timings()
1596 temp = gpmc_t->we_on + dev_t->t_wpl; in gpmc_calc_sync_write_timings()
1598 gpmc_t->wr_access + gpmc_ticks_to_ps(1)); in gpmc_calc_sync_write_timings()
1600 gpmc_t->we_on + gpmc_ticks_to_ps(dev_t->cyc_wpl)); in gpmc_calc_sync_write_timings()
1601 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_write_timings()
1603 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + in gpmc_calc_sync_write_timings()
1604 dev_t->t_wph); in gpmc_calc_sync_write_timings()
1607 temp = gpmc_round_ps_to_sync_clk(dev_t->t_cez_w, gpmc_t->sync_clk); in gpmc_calc_sync_write_timings()
1608 temp += gpmc_t->wr_access; in gpmc_calc_sync_write_timings()
1610 if (dev_t->t_ce_rdyz) in gpmc_calc_sync_write_timings()
1612 gpmc_t->cs_wr_off + dev_t->t_ce_rdyz); in gpmc_calc_sync_write_timings()
1613 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_write_timings()
1625 temp = dev_t->t_avdp_r; in gpmc_calc_async_read_timings()
1627 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); in gpmc_calc_async_read_timings()
1628 gpmc_t->adv_rd_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_read_timings()
1631 temp = dev_t->t_oeasu; in gpmc_calc_async_read_timings()
1633 temp = max_t(u32, temp, gpmc_t->adv_rd_off + dev_t->t_aavdh); in gpmc_calc_async_read_timings()
1634 gpmc_t->oe_on = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_read_timings()
1637 temp = max_t(u32, dev_t->t_iaa, /* XXX: remove t_iaa in async ? */ in gpmc_calc_async_read_timings()
1638 gpmc_t->oe_on + dev_t->t_oe); in gpmc_calc_async_read_timings()
1639 temp = max_t(u32, temp, gpmc_t->cs_on + dev_t->t_ce); in gpmc_calc_async_read_timings()
1640 temp = max_t(u32, temp, gpmc_t->adv_on + dev_t->t_aa); in gpmc_calc_async_read_timings()
1641 gpmc_t->access = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_read_timings()
1643 gpmc_t->oe_off = gpmc_t->access + gpmc_ticks_to_ps(1); in gpmc_calc_async_read_timings()
1644 gpmc_t->cs_rd_off = gpmc_t->oe_off; in gpmc_calc_async_read_timings()
1647 temp = max_t(u32, dev_t->t_rd_cycle, in gpmc_calc_async_read_timings()
1648 gpmc_t->cs_rd_off + dev_t->t_cez_r); in gpmc_calc_async_read_timings()
1649 temp = max_t(u32, temp, gpmc_t->oe_off + dev_t->t_oez); in gpmc_calc_async_read_timings()
1650 gpmc_t->rd_cycle = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_read_timings()
1662 temp = dev_t->t_avdp_w; in gpmc_calc_async_write_timings()
1664 temp = max_t(u32, gpmc_t->adv_on + gpmc_ticks_to_ps(1), temp); in gpmc_calc_async_write_timings()
1665 gpmc_t->adv_wr_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_write_timings()
1668 temp = dev_t->t_weasu; in gpmc_calc_async_write_timings()
1670 temp = max_t(u32, temp, gpmc_t->adv_wr_off + dev_t->t_aavdh); in gpmc_calc_async_write_timings()
1671 temp = max_t(u32, temp, gpmc_t->adv_wr_off + in gpmc_calc_async_write_timings()
1672 gpmc_ticks_to_ps(dev_t->cyc_aavdh_we)); in gpmc_calc_async_write_timings()
1674 gpmc_t->wr_data_mux_bus = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_write_timings()
1678 gpmc_t->we_on = gpmc_round_ps_to_ticks(dev_t->t_weasu); in gpmc_calc_async_write_timings()
1680 gpmc_t->we_on = gpmc_t->wr_data_mux_bus; in gpmc_calc_async_write_timings()
1683 temp = gpmc_t->we_on + dev_t->t_wpl; in gpmc_calc_async_write_timings()
1684 gpmc_t->we_off = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_write_timings()
1686 gpmc_t->cs_wr_off = gpmc_round_ps_to_ticks(gpmc_t->we_off + in gpmc_calc_async_write_timings()
1687 dev_t->t_wph); in gpmc_calc_async_write_timings()
1690 temp = max_t(u32, dev_t->t_wr_cycle, in gpmc_calc_async_write_timings()
1691 gpmc_t->cs_wr_off + dev_t->t_cez_w); in gpmc_calc_async_write_timings()
1692 gpmc_t->wr_cycle = gpmc_round_ps_to_ticks(temp); in gpmc_calc_async_write_timings()
1702 gpmc_t->sync_clk = gpmc_calc_divider(dev_t->clk) * in gpmc_calc_sync_common_timings()
1705 gpmc_t->page_burst_access = gpmc_round_ps_to_sync_clk( in gpmc_calc_sync_common_timings()
1706 dev_t->t_bacc, in gpmc_calc_sync_common_timings()
1707 gpmc_t->sync_clk); in gpmc_calc_sync_common_timings()
1709 temp = max_t(u32, dev_t->t_ces, dev_t->t_avds); in gpmc_calc_sync_common_timings()
1710 gpmc_t->clk_activation = gpmc_round_ps_to_ticks(temp); in gpmc_calc_sync_common_timings()
1712 if (gpmc_calc_divider(gpmc_t->sync_clk) != 1) in gpmc_calc_sync_common_timings()
1715 if (dev_t->ce_xdelay) in gpmc_calc_sync_common_timings()
1716 gpmc_t->bool_timings.cs_extra_delay = true; in gpmc_calc_sync_common_timings()
1717 if (dev_t->avd_xdelay) in gpmc_calc_sync_common_timings()
1718 gpmc_t->bool_timings.adv_extra_delay = true; in gpmc_calc_sync_common_timings()
1719 if (dev_t->oe_xdelay) in gpmc_calc_sync_common_timings()
1720 gpmc_t->bool_timings.oe_extra_delay = true; in gpmc_calc_sync_common_timings()
1721 if (dev_t->we_xdelay) in gpmc_calc_sync_common_timings()
1722 gpmc_t->bool_timings.we_extra_delay = true; in gpmc_calc_sync_common_timings()
1734 gpmc_t->cs_on = gpmc_round_ps_to_ticks(dev_t->t_ceasu); in gpmc_calc_common_timings()
1737 temp = dev_t->t_avdasu; in gpmc_calc_common_timings()
1738 if (dev_t->t_ce_avd) in gpmc_calc_common_timings()
1740 gpmc_t->cs_on + dev_t->t_ce_avd); in gpmc_calc_common_timings()
1741 gpmc_t->adv_on = gpmc_round_ps_to_ticks(temp); in gpmc_calc_common_timings()
1756 t->cs_on /= 1000; in gpmc_convert_ps_to_ns()
1757 t->cs_rd_off /= 1000; in gpmc_convert_ps_to_ns()
1758 t->cs_wr_off /= 1000; in gpmc_convert_ps_to_ns()
1759 t->adv_on /= 1000; in gpmc_convert_ps_to_ns()
1760 t->adv_rd_off /= 1000; in gpmc_convert_ps_to_ns()
1761 t->adv_wr_off /= 1000; in gpmc_convert_ps_to_ns()
1762 t->we_on /= 1000; in gpmc_convert_ps_to_ns()
1763 t->we_off /= 1000; in gpmc_convert_ps_to_ns()
1764 t->oe_on /= 1000; in gpmc_convert_ps_to_ns()
1765 t->oe_off /= 1000; in gpmc_convert_ps_to_ns()
1766 t->page_burst_access /= 1000; in gpmc_convert_ps_to_ns()
1767 t->access /= 1000; in gpmc_convert_ps_to_ns()
1768 t->rd_cycle /= 1000; in gpmc_convert_ps_to_ns()
1769 t->wr_cycle /= 1000; in gpmc_convert_ps_to_ns()
1770 t->bus_turnaround /= 1000; in gpmc_convert_ps_to_ns()
1771 t->cycle2cycle_delay /= 1000; in gpmc_convert_ps_to_ns()
1772 t->wait_monitoring /= 1000; in gpmc_convert_ps_to_ns()
1773 t->clk_activation /= 1000; in gpmc_convert_ps_to_ns()
1774 t->wr_access /= 1000; in gpmc_convert_ps_to_ns()
1775 t->wr_data_mux_bus /= 1000; in gpmc_convert_ps_to_ns()
1785 mux = gpmc_s->mux_add_data ? true : false; in gpmc_calc_timings()
1786 sync = (gpmc_s->sync_read || gpmc_s->sync_write); in gpmc_calc_timings()
1793 if (gpmc_s && gpmc_s->sync_read) in gpmc_calc_timings()
1798 if (gpmc_s && gpmc_s->sync_write) in gpmc_calc_timings()
1810 * gpmc_cs_program_settings - programs non-timing related settings
1811 * @cs: GPMC chip-select to program
1812 * @p: pointer to GPMC settings structure
1814 * Programs non-timing related settings for a GPMC chip-select, such as
1815 * bus-width, burst configuration, etc. Function should be called once
1816 * for each chip-select that is being used and must be called before
1825 if ((!p->device_width) || (p->device_width > GPMC_DEVWIDTH_16BIT)) { in gpmc_cs_program_settings()
1826 pr_err("%s: invalid width %d!", __func__, p->device_width); in gpmc_cs_program_settings()
1827 return -EINVAL; in gpmc_cs_program_settings()
1830 /* Address-data multiplexing not supported for NAND devices */ in gpmc_cs_program_settings()
1831 if (p->device_nand && p->mux_add_data) { in gpmc_cs_program_settings()
1833 return -EINVAL; in gpmc_cs_program_settings()
1836 if ((p->mux_add_data > GPMC_MUX_AD) || in gpmc_cs_program_settings()
1837 ((p->mux_add_data == GPMC_MUX_AAD) && in gpmc_cs_program_settings()
1840 return -EINVAL; in gpmc_cs_program_settings()
1844 if (p->burst_read || p->burst_write) { in gpmc_cs_program_settings()
1845 switch (p->burst_len) { in gpmc_cs_program_settings()
1851 pr_err("%s: invalid page/burst-length (%d)\n", in gpmc_cs_program_settings()
1852 __func__, p->burst_len); in gpmc_cs_program_settings()
1853 return -EINVAL; in gpmc_cs_program_settings()
1857 if (p->wait_pin > gpmc_nr_waitpins) { in gpmc_cs_program_settings()
1858 pr_err("%s: invalid wait-pin (%d)\n", __func__, p->wait_pin); in gpmc_cs_program_settings()
1859 return -EINVAL; in gpmc_cs_program_settings()
1862 config1 = GPMC_CONFIG1_DEVICESIZE((p->device_width - 1)); in gpmc_cs_program_settings()
1864 if (p->sync_read) in gpmc_cs_program_settings()
1866 if (p->sync_write) in gpmc_cs_program_settings()
1868 if (p->wait_on_read) in gpmc_cs_program_settings()
1870 if (p->wait_on_write) in gpmc_cs_program_settings()
1872 if (p->wait_on_read || p->wait_on_write) in gpmc_cs_program_settings()
1873 config1 |= GPMC_CONFIG1_WAIT_PIN_SEL(p->wait_pin); in gpmc_cs_program_settings()
1874 if (p->device_nand) in gpmc_cs_program_settings()
1876 if (p->mux_add_data) in gpmc_cs_program_settings()
1877 config1 |= GPMC_CONFIG1_MUXTYPE(p->mux_add_data); in gpmc_cs_program_settings()
1878 if (p->burst_read) in gpmc_cs_program_settings()
1880 if (p->burst_write) in gpmc_cs_program_settings()
1882 if (p->burst_read || p->burst_write) { in gpmc_cs_program_settings()
1883 config1 |= GPMC_CONFIG1_PAGE_LEN(p->burst_len >> 3); in gpmc_cs_program_settings()
1884 config1 |= p->burst_wrap ? GPMC_CONFIG1_WRAPBURST_SUPP : 0; in gpmc_cs_program_settings()
1895 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_set_name() local
1897 gpmc->name = name; in gpmc_cs_set_name()
1902 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_get_name() local
1904 return gpmc->name; in gpmc_cs_get_name()
1908 * gpmc_cs_remap - remaps a chip-select physical base address
1909 * @cs: chip-select to remap
1910 * @base: physical base address to re-map chip-select to
1912 * Re-maps a chip-select to a new physical base address specified by
1922 pr_err("%s: requested chip-select is disabled\n", __func__); in gpmc_cs_remap()
1923 return -ENODEV; in gpmc_cs_remap()
1927 * Make sure we ignore any device offsets from the GPMC partition in gpmc_cs_remap()
1929 * to the GPMC 16MB minimum granularity. in gpmc_cs_remap()
1931 base &= ~(SZ_16M - 1); in gpmc_cs_remap()
1951 * gpmc_read_settings_dt - read gpmc settings from device-tree
1952 * @np: pointer to device-tree node for a gpmc child device
1953 * @p: pointer to gpmc settings structure
1955 * Reads the GPMC settings for a GPMC child device from device-tree and
1956 * stores them in the GPMC settings structure passed. The GPMC settings
1964 p->sync_read = of_property_read_bool(np, "gpmc,sync-read"); in gpmc_read_settings_dt()
1965 p->sync_write = of_property_read_bool(np, "gpmc,sync-write"); in gpmc_read_settings_dt()
1966 of_property_read_u32(np, "gpmc,device-width", &p->device_width); in gpmc_read_settings_dt()
1967 of_property_read_u32(np, "gpmc,mux-add-data", &p->mux_add_data); in gpmc_read_settings_dt()
1969 if (!of_property_read_u32(np, "gpmc,burst-length", &p->burst_len)) { in gpmc_read_settings_dt()
1970 p->burst_wrap = of_property_read_bool(np, "gpmc,burst-wrap"); in gpmc_read_settings_dt()
1971 p->burst_read = of_property_read_bool(np, "gpmc,burst-read"); in gpmc_read_settings_dt()
1972 p->burst_write = of_property_read_bool(np, "gpmc,burst-write"); in gpmc_read_settings_dt()
1973 if (!p->burst_read && !p->burst_write) in gpmc_read_settings_dt()
1974 pr_warn("%s: page/burst-length set but not used!\n", in gpmc_read_settings_dt()
1978 if (!of_property_read_u32(np, "gpmc,wait-pin", &p->wait_pin)) { in gpmc_read_settings_dt()
1979 p->wait_on_read = of_property_read_bool(np, in gpmc_read_settings_dt()
1980 "gpmc,wait-on-read"); in gpmc_read_settings_dt()
1981 p->wait_on_write = of_property_read_bool(np, in gpmc_read_settings_dt()
1982 "gpmc,wait-on-write"); in gpmc_read_settings_dt()
1983 if (!p->wait_on_read && !p->wait_on_write) in gpmc_read_settings_dt()
2000 of_property_read_u32(np, "gpmc,sync-clk-ps", &gpmc_t->sync_clk); in gpmc_read_timings_dt()
2003 of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on); in gpmc_read_timings_dt()
2004 of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off); in gpmc_read_timings_dt()
2005 of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off); in gpmc_read_timings_dt()
2008 of_property_read_u32(np, "gpmc,adv-on-ns", &gpmc_t->adv_on); in gpmc_read_timings_dt()
2009 of_property_read_u32(np, "gpmc,adv-rd-off-ns", &gpmc_t->adv_rd_off); in gpmc_read_timings_dt()
2010 of_property_read_u32(np, "gpmc,adv-wr-off-ns", &gpmc_t->adv_wr_off); in gpmc_read_timings_dt()
2011 of_property_read_u32(np, "gpmc,adv-aad-mux-on-ns", in gpmc_read_timings_dt()
2012 &gpmc_t->adv_aad_mux_on); in gpmc_read_timings_dt()
2013 of_property_read_u32(np, "gpmc,adv-aad-mux-rd-off-ns", in gpmc_read_timings_dt()
2014 &gpmc_t->adv_aad_mux_rd_off); in gpmc_read_timings_dt()
2015 of_property_read_u32(np, "gpmc,adv-aad-mux-wr-off-ns", in gpmc_read_timings_dt()
2016 &gpmc_t->adv_aad_mux_wr_off); in gpmc_read_timings_dt()
2019 of_property_read_u32(np, "gpmc,we-on-ns", &gpmc_t->we_on); in gpmc_read_timings_dt()
2020 of_property_read_u32(np, "gpmc,we-off-ns", &gpmc_t->we_off); in gpmc_read_timings_dt()
2023 of_property_read_u32(np, "gpmc,oe-on-ns", &gpmc_t->oe_on); in gpmc_read_timings_dt()
2024 of_property_read_u32(np, "gpmc,oe-off-ns", &gpmc_t->oe_off); in gpmc_read_timings_dt()
2025 of_property_read_u32(np, "gpmc,oe-aad-mux-on-ns", in gpmc_read_timings_dt()
2026 &gpmc_t->oe_aad_mux_on); in gpmc_read_timings_dt()
2027 of_property_read_u32(np, "gpmc,oe-aad-mux-off-ns", in gpmc_read_timings_dt()
2028 &gpmc_t->oe_aad_mux_off); in gpmc_read_timings_dt()
2031 of_property_read_u32(np, "gpmc,page-burst-access-ns", in gpmc_read_timings_dt()
2032 &gpmc_t->page_burst_access); in gpmc_read_timings_dt()
2033 of_property_read_u32(np, "gpmc,access-ns", &gpmc_t->access); in gpmc_read_timings_dt()
2034 of_property_read_u32(np, "gpmc,rd-cycle-ns", &gpmc_t->rd_cycle); in gpmc_read_timings_dt()
2035 of_property_read_u32(np, "gpmc,wr-cycle-ns", &gpmc_t->wr_cycle); in gpmc_read_timings_dt()
2036 of_property_read_u32(np, "gpmc,bus-turnaround-ns", in gpmc_read_timings_dt()
2037 &gpmc_t->bus_turnaround); in gpmc_read_timings_dt()
2038 of_property_read_u32(np, "gpmc,cycle2cycle-delay-ns", in gpmc_read_timings_dt()
2039 &gpmc_t->cycle2cycle_delay); in gpmc_read_timings_dt()
2040 of_property_read_u32(np, "gpmc,wait-monitoring-ns", in gpmc_read_timings_dt()
2041 &gpmc_t->wait_monitoring); in gpmc_read_timings_dt()
2042 of_property_read_u32(np, "gpmc,clk-activation-ns", in gpmc_read_timings_dt()
2043 &gpmc_t->clk_activation); in gpmc_read_timings_dt()
2046 of_property_read_u32(np, "gpmc,wr-access-ns", &gpmc_t->wr_access); in gpmc_read_timings_dt()
2047 of_property_read_u32(np, "gpmc,wr-data-mux-bus-ns", in gpmc_read_timings_dt()
2048 &gpmc_t->wr_data_mux_bus); in gpmc_read_timings_dt()
2051 p = &gpmc_t->bool_timings; in gpmc_read_timings_dt()
2053 p->cycle2cyclediffcsen = in gpmc_read_timings_dt()
2054 of_property_read_bool(np, "gpmc,cycle2cycle-diffcsen"); in gpmc_read_timings_dt()
2055 p->cycle2cyclesamecsen = in gpmc_read_timings_dt()
2056 of_property_read_bool(np, "gpmc,cycle2cycle-samecsen"); in gpmc_read_timings_dt()
2057 p->we_extra_delay = of_property_read_bool(np, "gpmc,we-extra-delay"); in gpmc_read_timings_dt()
2058 p->oe_extra_delay = of_property_read_bool(np, "gpmc,oe-extra-delay"); in gpmc_read_timings_dt()
2059 p->adv_extra_delay = of_property_read_bool(np, "gpmc,adv-extra-delay"); in gpmc_read_timings_dt()
2060 p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay"); in gpmc_read_timings_dt()
2061 p->time_para_granularity = in gpmc_read_timings_dt()
2062 of_property_read_bool(np, "gpmc,time-para-granularity"); in gpmc_read_timings_dt()
2066 * gpmc_probe_generic_child - configures the gpmc for a child device
2067 * @pdev: pointer to gpmc platform device
2068 * @child: pointer to device-tree node for child device
2070 * Allocates and configures a GPMC chip-select for a child device.
2084 struct gpmc_device *gpmc = platform_get_drvdata(pdev); in gpmc_probe_generic_child() local
2087 dev_err(&pdev->dev, "%pOF has no 'reg' property\n", in gpmc_probe_generic_child()
2089 return -ENODEV; in gpmc_probe_generic_child()
2093 dev_err(&pdev->dev, "%pOF has malformed 'reg' property\n", in gpmc_probe_generic_child()
2095 return -ENODEV; in gpmc_probe_generic_child()
2109 dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs); in gpmc_probe_generic_child()
2112 gpmc_cs_set_name(cs, child->full_name); in gpmc_probe_generic_child()
2118 * For some GPMC devices we still need to rely on the bootloader in gpmc_probe_generic_child()
2123 WARN(1, "enable GPMC debug to configure .dts timings for CS%i\n", in gpmc_probe_generic_child()
2126 "please add GPMC bootloader timings to .dts"); in gpmc_probe_generic_child()
2130 /* CS must be disabled while making changes to gpmc configuration */ in gpmc_probe_generic_child()
2135 * location in the gpmc address space. When booting with in gpmc_probe_generic_child()
2136 * device-tree we want the NOR flash to be mapped to the in gpmc_probe_generic_child()
2137 * location specified in the device-tree blob. So remap the in gpmc_probe_generic_child()
2143 dev_err(&pdev->dev, "cannot remap GPMC CS %d to %pa\n", in gpmc_probe_generic_child()
2146 dev_info(&pdev->dev, in gpmc_probe_generic_child()
2147 "GPMC CS %d start cannot be lesser than 0x%x\n", in gpmc_probe_generic_child()
2150 dev_info(&pdev->dev, in gpmc_probe_generic_child()
2151 "GPMC CS %d end cannot be greater than 0x%x\n", in gpmc_probe_generic_child()
2160 dev_warn(&pdev->dev, in gpmc_probe_generic_child()
2162 ret = -EINVAL; in gpmc_probe_generic_child()
2170 dev_warn(&pdev->dev, in gpmc_probe_generic_child()
2172 ret = -EINVAL; in gpmc_probe_generic_child()
2180 of_property_read_u32(child, "nand-bus-width", &val); in gpmc_probe_generic_child()
2189 dev_err(&pdev->dev, "%pOFn: invalid 'nand-bus-width'\n", in gpmc_probe_generic_child()
2191 ret = -EINVAL; in gpmc_probe_generic_child()
2199 ret = of_property_read_u32(child, "bank-width", in gpmc_probe_generic_child()
2202 dev_err(&pdev->dev, in gpmc_probe_generic_child()
2203 "%pOF has no 'gpmc,device-width' property\n", in gpmc_probe_generic_child()
2213 waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip, in gpmc_probe_generic_child()
2218 dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin); in gpmc_probe_generic_child()
2232 dev_err(&pdev->dev, "failed to set gpmc timings for: %pOFn\n", in gpmc_probe_generic_child()
2237 /* Clear limited address i.e. enable A26-A11 */ in gpmc_probe_generic_child()
2248 if (!of_platform_device_create(child, NULL, &pdev->dev)) in gpmc_probe_generic_child()
2252 if (of_platform_default_populate(child, NULL, &pdev->dev)) in gpmc_probe_generic_child()
2259 dev_err(&pdev->dev, "failed to create gpmc child %pOFn\n", child); in gpmc_probe_generic_child()
2260 ret = -ENODEV; in gpmc_probe_generic_child()
2276 of_match_device(gpmc_dt_ids, &pdev->dev); in gpmc_probe_dt()
2281 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-cs", in gpmc_probe_dt()
2284 pr_err("%s: number of chip-selects not defined\n", __func__); in gpmc_probe_dt()
2287 pr_err("%s: all chip-selects are disabled\n", __func__); in gpmc_probe_dt()
2288 return -EINVAL; in gpmc_probe_dt()
2290 pr_err("%s: number of supported chip-selects cannot be > %d\n", in gpmc_probe_dt()
2292 return -EINVAL; in gpmc_probe_dt()
2295 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-waitpins", in gpmc_probe_dt()
2310 for_each_available_child_of_node(pdev->dev.of_node, child) { in gpmc_probe_dt_children()
2313 dev_err(&pdev->dev, "failed to probe DT child '%pOFn': %d\n", in gpmc_probe_dt_children()
2347 return -EINVAL; /* we're input only */ in gpmc_gpio_direction_output()
2366 static int gpmc_gpio_init(struct gpmc_device *gpmc) in gpmc_gpio_init() argument
2370 gpmc->gpio_chip.parent = gpmc->dev; in gpmc_gpio_init()
2371 gpmc->gpio_chip.owner = THIS_MODULE; in gpmc_gpio_init()
2372 gpmc->gpio_chip.label = DEVICE_NAME; in gpmc_gpio_init()
2373 gpmc->gpio_chip.ngpio = gpmc_nr_waitpins; in gpmc_gpio_init()
2374 gpmc->gpio_chip.get_direction = gpmc_gpio_get_direction; in gpmc_gpio_init()
2375 gpmc->gpio_chip.direction_input = gpmc_gpio_direction_input; in gpmc_gpio_init()
2376 gpmc->gpio_chip.direction_output = gpmc_gpio_direction_output; in gpmc_gpio_init()
2377 gpmc->gpio_chip.set = gpmc_gpio_set; in gpmc_gpio_init()
2378 gpmc->gpio_chip.get = gpmc_gpio_get; in gpmc_gpio_init()
2379 gpmc->gpio_chip.base = -1; in gpmc_gpio_init()
2381 ret = devm_gpiochip_add_data(gpmc->dev, &gpmc->gpio_chip, NULL); in gpmc_gpio_init()
2383 dev_err(gpmc->dev, "could not register gpio chip: %d\n", ret); in gpmc_gpio_init()
2390 static void omap3_gpmc_save_context(struct gpmc_device *gpmc) in omap3_gpmc_save_context() argument
2395 if (!gpmc || !gpmc_base) in omap3_gpmc_save_context()
2398 gpmc_context = &gpmc->context; in omap3_gpmc_save_context()
2400 gpmc_context->sysconfig = gpmc_read_reg(GPMC_SYSCONFIG); in omap3_gpmc_save_context()
2401 gpmc_context->irqenable = gpmc_read_reg(GPMC_IRQENABLE); in omap3_gpmc_save_context()
2402 gpmc_context->timeout_ctrl = gpmc_read_reg(GPMC_TIMEOUT_CONTROL); in omap3_gpmc_save_context()
2403 gpmc_context->config = gpmc_read_reg(GPMC_CONFIG); in omap3_gpmc_save_context()
2404 gpmc_context->prefetch_config1 = gpmc_read_reg(GPMC_PREFETCH_CONFIG1); in omap3_gpmc_save_context()
2405 gpmc_context->prefetch_config2 = gpmc_read_reg(GPMC_PREFETCH_CONFIG2); in omap3_gpmc_save_context()
2406 gpmc_context->prefetch_control = gpmc_read_reg(GPMC_PREFETCH_CONTROL); in omap3_gpmc_save_context()
2408 gpmc_context->cs_context[i].is_valid = gpmc_cs_mem_enabled(i); in omap3_gpmc_save_context()
2409 if (gpmc_context->cs_context[i].is_valid) { in omap3_gpmc_save_context()
2410 gpmc_context->cs_context[i].config1 = in omap3_gpmc_save_context()
2412 gpmc_context->cs_context[i].config2 = in omap3_gpmc_save_context()
2414 gpmc_context->cs_context[i].config3 = in omap3_gpmc_save_context()
2416 gpmc_context->cs_context[i].config4 = in omap3_gpmc_save_context()
2418 gpmc_context->cs_context[i].config5 = in omap3_gpmc_save_context()
2420 gpmc_context->cs_context[i].config6 = in omap3_gpmc_save_context()
2422 gpmc_context->cs_context[i].config7 = in omap3_gpmc_save_context()
2428 static void omap3_gpmc_restore_context(struct gpmc_device *gpmc) in omap3_gpmc_restore_context() argument
2433 if (!gpmc || !gpmc_base) in omap3_gpmc_restore_context()
2436 gpmc_context = &gpmc->context; in omap3_gpmc_restore_context()
2438 gpmc_write_reg(GPMC_SYSCONFIG, gpmc_context->sysconfig); in omap3_gpmc_restore_context()
2439 gpmc_write_reg(GPMC_IRQENABLE, gpmc_context->irqenable); in omap3_gpmc_restore_context()
2440 gpmc_write_reg(GPMC_TIMEOUT_CONTROL, gpmc_context->timeout_ctrl); in omap3_gpmc_restore_context()
2441 gpmc_write_reg(GPMC_CONFIG, gpmc_context->config); in omap3_gpmc_restore_context()
2442 gpmc_write_reg(GPMC_PREFETCH_CONFIG1, gpmc_context->prefetch_config1); in omap3_gpmc_restore_context()
2443 gpmc_write_reg(GPMC_PREFETCH_CONFIG2, gpmc_context->prefetch_config2); in omap3_gpmc_restore_context()
2444 gpmc_write_reg(GPMC_PREFETCH_CONTROL, gpmc_context->prefetch_control); in omap3_gpmc_restore_context()
2446 if (gpmc_context->cs_context[i].is_valid) { in omap3_gpmc_restore_context()
2448 gpmc_context->cs_context[i].config1); in omap3_gpmc_restore_context()
2450 gpmc_context->cs_context[i].config2); in omap3_gpmc_restore_context()
2452 gpmc_context->cs_context[i].config3); in omap3_gpmc_restore_context()
2454 gpmc_context->cs_context[i].config4); in omap3_gpmc_restore_context()
2456 gpmc_context->cs_context[i].config5); in omap3_gpmc_restore_context()
2458 gpmc_context->cs_context[i].config6); in omap3_gpmc_restore_context()
2460 gpmc_context->cs_context[i].config7); in omap3_gpmc_restore_context()
2470 struct gpmc_device *gpmc; in omap_gpmc_context_notifier() local
2472 gpmc = container_of(nb, struct gpmc_device, nb); in omap_gpmc_context_notifier()
2473 if (gpmc->is_suspended || pm_runtime_suspended(gpmc->dev)) in omap_gpmc_context_notifier()
2478 omap3_gpmc_save_context(gpmc); in omap_gpmc_context_notifier()
2483 omap3_gpmc_restore_context(gpmc); in omap_gpmc_context_notifier()
2495 struct gpmc_device *gpmc; in gpmc_probe() local
2497 gpmc = devm_kzalloc(&pdev->dev, sizeof(*gpmc), GFP_KERNEL); in gpmc_probe()
2498 if (!gpmc) in gpmc_probe()
2499 return -ENOMEM; in gpmc_probe()
2501 gpmc->dev = &pdev->dev; in gpmc_probe()
2502 platform_set_drvdata(pdev, gpmc); in gpmc_probe()
2511 gpmc_base = devm_ioremap_resource(&pdev->dev, res); in gpmc_probe()
2517 dev_err(&pdev->dev, "couldn't get data reg resource\n"); in gpmc_probe()
2518 return -ENOENT; in gpmc_probe()
2521 gpmc->data = res; in gpmc_probe()
2524 gpmc->irq = platform_get_irq(pdev, 0); in gpmc_probe()
2525 if (gpmc->irq < 0) in gpmc_probe()
2526 return gpmc->irq; in gpmc_probe()
2528 gpmc_l3_clk = devm_clk_get(&pdev->dev, "fck"); in gpmc_probe()
2530 dev_err(&pdev->dev, "Failed to get GPMC fck\n"); in gpmc_probe()
2535 dev_err(&pdev->dev, "Invalid GPMC fck clock rate\n"); in gpmc_probe()
2536 return -EINVAL; in gpmc_probe()
2539 if (pdev->dev.of_node) { in gpmc_probe()
2548 pm_runtime_enable(&pdev->dev); in gpmc_probe()
2549 pm_runtime_get_sync(&pdev->dev); in gpmc_probe()
2554 * FIXME: Once device-tree migration is complete the below flags in gpmc_probe()
2555 * should be populated based upon the device-tree compatible in gpmc_probe()
2558 * devices support the addr-addr-data multiplex protocol. in gpmc_probe()
2560 * GPMC IP revisions: in gpmc_probe()
2561 * - OMAP24xx = 2.0 in gpmc_probe()
2562 * - OMAP3xxx = 5.0 in gpmc_probe()
2563 * - OMAP44xx/54xx/AM335x = 6.0 in gpmc_probe()
2569 dev_info(gpmc->dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l), in gpmc_probe()
2572 gpmc_mem_init(gpmc); in gpmc_probe()
2573 rc = gpmc_gpio_init(gpmc); in gpmc_probe()
2577 gpmc->nirqs = GPMC_NR_NAND_IRQS + gpmc_nr_waitpins; in gpmc_probe()
2578 rc = gpmc_setup_irq(gpmc); in gpmc_probe()
2580 dev_err(gpmc->dev, "gpmc_setup_irq failed\n"); in gpmc_probe()
2586 gpmc->nb.notifier_call = omap_gpmc_context_notifier; in gpmc_probe()
2587 cpu_pm_register_notifier(&gpmc->nb); in gpmc_probe()
2593 pm_runtime_put_sync(&pdev->dev); in gpmc_probe()
2594 pm_runtime_disable(&pdev->dev); in gpmc_probe()
2601 struct gpmc_device *gpmc = platform_get_drvdata(pdev); in gpmc_remove() local
2603 cpu_pm_unregister_notifier(&gpmc->nb); in gpmc_remove()
2604 gpmc_free_irq(gpmc); in gpmc_remove()
2606 pm_runtime_put_sync(&pdev->dev); in gpmc_remove()
2607 pm_runtime_disable(&pdev->dev); in gpmc_remove()
2615 struct gpmc_device *gpmc = dev_get_drvdata(dev); in gpmc_suspend() local
2617 omap3_gpmc_save_context(gpmc); in gpmc_suspend()
2619 gpmc->is_suspended = 1; in gpmc_suspend()
2626 struct gpmc_device *gpmc = dev_get_drvdata(dev); in gpmc_resume() local
2629 omap3_gpmc_restore_context(gpmc); in gpmc_resume()
2630 gpmc->is_suspended = 0; in gpmc_resume()
2640 { .compatible = "ti,omap2420-gpmc" },
2641 { .compatible = "ti,omap2430-gpmc" },
2642 { .compatible = "ti,omap3430-gpmc" }, /* omap3430 & omap3630 */
2643 { .compatible = "ti,omap4430-gpmc" }, /* omap4430 & omap4460 & omap543x */
2644 { .compatible = "ti,am3352-gpmc" }, /* am335x devices */
2645 { .compatible = "ti,am64-gpmc" },
2663 MODULE_DESCRIPTION("Texas Instruments GPMC driver");