summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/sh-pfc/pfc-r8a7791.c
AgeCommit message (Expand)Author
2019-05-21pinctrl: sh-pfc: Rename 2-parameter CPU_ALL_PORT() variantGeert Uytterhoeven
2019-04-02pinctrl: sh-pfc: Absorb enum IDs in PINMUX_CFG_REG_VAR() macroGeert Uytterhoeven
2019-04-02pinctrl: sh-pfc: Absorb enum IDs in PINMUX_CFG_REG() macroGeert Uytterhoeven
2019-04-02pinctrl: sh-pfc: Add missing #include <linux/errno.h>Geert Uytterhoeven
2019-02-11pinctrl: sh-pfc: r8a7791: Fix scifb2_data_c pin groupGeert Uytterhoeven
2019-01-21pinctrl: sh-pfc: r8a7791: Fix VIN1 versioned groupsGeert Uytterhoeven
2018-12-18pinctrl: sh-pfc: r8a7791: Remove bogus marks from vin1_b_data18 groupGeert Uytterhoeven
2018-12-18pinctrl: sh-pfc: r8a7791: Remove bogus ctrl marks from qspi_data4_b groupGeert Uytterhoeven
2018-09-28pinctrl: sh-pfc: rcar: Rename automotive-only arrays to automotiveGeert Uytterhoeven
2018-09-19pinctrl: sh-pfc: r8a7791: Add r8a7744 supportBiju Das
2018-09-11pinctrl: sh-pfc: Convert to SPDX identifiersKuninori Morimoto
2017-12-19pinctrl: sh-pfc: r8a7791: Add tpu groups and functionFabrizio Castro
2017-12-05pinctrl: sh-pfc: r8a7791: Add can_clk functionFabrizio Castro
2017-07-17pinctrl: sh-pfc: r8a7791: Add missing mmc_data8_b pin groupGeert Uytterhoeven
2017-05-16pinctrl: sh-pfc: r8a7791: Add R8A7743 supportSergei Shtylyov
2017-05-15pinctrl: sh-pfc: r8a7791: Grand I2C renameSergei Shtylyov
2017-04-04pinctrl: sh-pfc: r8a7791: Fix IPSR comment typosSergei Shtylyov
2017-04-04pinctrl: sh-pfc: r8a7791: Fix SCIF2 pinmux dataSergei Shtylyov
2017-04-04pinctrl: sh-pfc: r8a7791: Add missing DVC_MUTE signalSergei Shtylyov
2017-04-04pinctrl: sh-pfc: r8a7791: Add missing HSCIF1 pinmux dataSergei Shtylyov
2017-01-20pinctrl: sh-pfc: r8a7791: Add ADI pinconf supportJacopo Mondi
2016-12-27pinctrl: sh-pfc: r8a7793: Implement voltage switching for SDHISimon Horman
2016-09-14pinctrl: sh-pfc: r8a7791: Implement voltage switching for SDHISimon Horman
2016-06-21pinctrl: sh-pfc: Improve core and user API separationGeert Uytterhoeven
2016-02-08pinctrl: sh-pfc: Rename PINMUX_IPSR_DATA() to PINMUX_IPSR_GPSR()Geert Uytterhoeven
2015-12-16pinctrl: sh-pfc: r8a7791: add EtherAVB pin groupsSergei Shtylyov
2015-12-08pinctrl: sh-pfc: r8a7791: Add SCIF_CLK supportGeert Uytterhoeven
2015-11-30pinctrl: sh-pfc: Share/reuse same PORT_GP_x() macrosKuninori Morimoto
2015-11-30pinctrl: sh-pfc: r8a7791: Use PINMUX_SINGLE() instead of raw PINMUX_DATA()Geert Uytterhoeven
2015-10-20pinctrl: sh-pfc: Stop including <linux/platform_data/gpio-rcar.h>Geert Uytterhoeven
2015-10-20pinctrl: sh-pfc: Rename .gpio_data[] to .pinmux_data[]Geert Uytterhoeven
2015-10-20pinctrl: sh-pfc: r8a779[01]: Move 'union vin_data' to shared header fileSergei Shtylyov
2015-10-02pinctrl: sh-pfc: r8a7791: use PINMUX_IPSR_MSEL()Kuninori Morimoto
2015-10-02pinctrl: sh-pfc: r8a7791/r8a7793: Correct SCIFB1_B SCK MOD_SEL valueGeert Uytterhoeven
2015-07-16sh-pfc: r8a7791: remove non-existing GPIO pinsLaurent Pinchart
2015-06-01pinctrl: Spelling s/reseved/reserved/Geert Uytterhoeven
2015-05-19pinctrl: sh-pfc: r8a7791: Add PWM pin groups and functionsYoshihiro Shimoda
2015-05-12pinctrl: sh-pfc: Add r8a7793 supportUlrich Hecht
2015-01-15sh-pfc: r8a7791: add MLB+ pin groupSergei Shtylyov
2015-01-15sh-pfc: r8a7791: fix typo in MLB_CLKSergei Shtylyov
2014-08-17sh-pfc: r8a7791: fix CAN pin groupsSergei Shtylyov
2014-07-11sh-pfc: r8a7791: add CAN pin groupsSergei Shtylyov
2014-07-11pinctrl: sh-pfc: r8a7791: Add HSCIF pin supportNobuhiro Iwamatsu
2014-06-03Merge tag 'pinctrl-v3.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/...Linus Torvalds
2014-04-23sh-pfc: r8a7791: Fix definition of MOD_SEL3Phil Edworthy
2014-04-22sh-pfc: r8a7791: Add Audio pin supportKuninori Morimoto
2014-04-22sh-pfc: r8a7791: Add SSI pin supportKuninori Morimoto
2014-04-22pinctrl: sh-pfc: r8a7791: Split the DU sync and cde/disp groupsLaurent Pinchart
2014-04-01Merge tag 'pinctrl-v3.15-1' of git://git.kernel.org/pub/scm/linux/kernel/git/...Linus Torvalds
2014-03-05pinctrl: sh-pfc: r8a7791: SD1_CLK fixMagnus Damm
href='#n426'>426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * extcon-rt8973a.c - Richtek RT8973A extcon driver to support USB switches
 *
 * Copyright (c) 2014 Samsung Electronics Co., Ltd
 * Author: Chanwoo Choi <cw00.choi@samsung.com>
 */

#include <linux/err.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/irqdomain.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/extcon-provider.h>

#include "extcon-rt8973a.h"

#define	DELAY_MS_DEFAULT		20000	/* unit: millisecond */

struct muic_irq {
	unsigned int irq;
	const char *name;
	unsigned int virq;
};

struct reg_data {
	u8 reg;
	u8 mask;
	u8 val;
	bool invert;
};

struct rt8973a_muic_info {
	struct device *dev;
	struct extcon_dev *edev;

	struct i2c_client *i2c;
	struct regmap *regmap;

	struct regmap_irq_chip_data *irq_data;
	struct muic_irq *muic_irqs;
	unsigned int num_muic_irqs;
	int irq;
	bool irq_attach;
	bool irq_detach;
	bool irq_ovp;
	bool irq_otp;
	struct work_struct irq_work;

	struct reg_data *reg_data;
	unsigned int num_reg_data;
	bool auto_config;

	struct mutex mutex;

	/*
	 * Use delayed workqueue to detect cable state and then
	 * notify cable state to notifiee/platform through uevent.
	 * After completing the booting of platform, the extcon provider
	 * driver should notify cable state to upper layer.
	 */
	struct delayed_work wq_detcable;
};

/* Default value of RT8973A register to bring up MUIC device. */
static struct reg_data rt8973a_reg_data[] = {
	{
		.reg = RT8973A_REG_CONTROL1,
		.mask = RT8973A_REG_CONTROL1_ADC_EN_MASK
			| RT8973A_REG_CONTROL1_USB_CHD_EN_MASK
			| RT8973A_REG_CONTROL1_CHGTYP_MASK
			| RT8973A_REG_CONTROL1_SWITCH_OPEN_MASK
			| RT8973A_REG_CONTROL1_AUTO_CONFIG_MASK
			| RT8973A_REG_CONTROL1_INTM_MASK,
		.val = RT8973A_REG_CONTROL1_ADC_EN_MASK
			| RT8973A_REG_CONTROL1_USB_CHD_EN_MASK
			| RT8973A_REG_CONTROL1_CHGTYP_MASK,
		.invert = false,
	},
	{ /* sentinel */ }
};

/* List of detectable cables */
static const unsigned int rt8973a_extcon_cable[] = {
	EXTCON_USB,
	EXTCON_USB_HOST,
	EXTCON_CHG_USB_SDP,
	EXTCON_CHG_USB_DCP,
	EXTCON_JIG,
	EXTCON_NONE,
};

/* Define OVP (Over Voltage Protection), OTP (Over Temperature Protection) */
enum rt8973a_event_type {
	RT8973A_EVENT_ATTACH = 1,
	RT8973A_EVENT_DETACH,
	RT8973A_EVENT_OVP,
	RT8973A_EVENT_OTP,
};

/* Define supported accessory type */
enum rt8973a_muic_acc_type {
	RT8973A_MUIC_ADC_OTG = 0x0,
	RT8973A_MUIC_ADC_AUDIO_SEND_END_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S1_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S2_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S3_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S4_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S5_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S6_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S7_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S8_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S9_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S10_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S11_BUTTON,
	RT8973A_MUIC_ADC_AUDIO_REMOTE_S12_BUTTON,
	RT8973A_MUIC_ADC_RESERVED_ACC_1,
	RT8973A_MUIC_ADC_RESERVED_ACC_2,
	RT8973A_MUIC_ADC_RESERVED_ACC_3,
	RT8973A_MUIC_ADC_RESERVED_ACC_4,
	RT8973A_MUIC_ADC_RESERVED_ACC_5,
	RT8973A_MUIC_ADC_AUDIO_TYPE2,
	RT8973A_MUIC_ADC_PHONE_POWERED_DEV,
	RT8973A_MUIC_ADC_UNKNOWN_ACC_1,
	RT8973A_MUIC_ADC_UNKNOWN_ACC_2,
	RT8973A_MUIC_ADC_TA,
	RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB,
	RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB,
	RT8973A_MUIC_ADC_UNKNOWN_ACC_3,
	RT8973A_MUIC_ADC_UNKNOWN_ACC_4,
	RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART,
	RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART,
	RT8973A_MUIC_ADC_UNKNOWN_ACC_5,
	RT8973A_MUIC_ADC_OPEN = 0x1f,

	/*
	 * The below accessories has same ADC value (0x1f).
	 * So, Device type1 is used to separate specific accessory.
	 */
					/* |---------|--ADC| */
					/* |    [7:5]|[4:0]| */
	RT8973A_MUIC_ADC_USB = 0x3f,	/* |      001|11111| */
};

/* List of supported interrupt for RT8973A */
static struct muic_irq rt8973a_muic_irqs[] = {
	{ RT8973A_INT1_ATTACH,		"muic-attach" },
	{ RT8973A_INT1_DETACH,		"muic-detach" },
	{ RT8973A_INT1_CHGDET,		"muic-chgdet" },
	{ RT8973A_INT1_DCD_T,		"muic-dcd-t" },
	{ RT8973A_INT1_OVP,		"muic-ovp" },
	{ RT8973A_INT1_CONNECT,		"muic-connect" },
	{ RT8973A_INT1_ADC_CHG,		"muic-adc-chg" },
	{ RT8973A_INT1_OTP,		"muic-otp" },
	{ RT8973A_INT2_UVLO,		"muic-uvlo" },
	{ RT8973A_INT2_POR,		"muic-por" },
	{ RT8973A_INT2_OTP_FET,		"muic-otp-fet" },
	{ RT8973A_INT2_OVP_FET,		"muic-ovp-fet" },
	{ RT8973A_INT2_OCP_LATCH,	"muic-ocp-latch" },
	{ RT8973A_INT2_OCP,		"muic-ocp" },
	{ RT8973A_INT2_OVP_OCP,		"muic-ovp-ocp" },
};

/* Define interrupt list of RT8973A to register regmap_irq */
static const struct regmap_irq rt8973a_irqs[] = {
	/* INT1 interrupts */
	{ .reg_offset = 0, .mask = RT8973A_INT1_ATTACH_MASK, },
	{ .reg_offset = 0, .mask = RT8973A_INT1_DETACH_MASK, },
	{ .reg_offset = 0, .mask = RT8973A_INT1_CHGDET_MASK, },
	{ .reg_offset = 0, .mask = RT8973A_INT1_DCD_T_MASK, },
	{ .reg_offset = 0, .mask = RT8973A_INT1_OVP_MASK, },
	{ .reg_offset = 0, .mask = RT8973A_INT1_CONNECT_MASK, },
	{ .reg_offset = 0, .mask = RT8973A_INT1_ADC_CHG_MASK, },
	{ .reg_offset = 0, .mask = RT8973A_INT1_OTP_MASK, },

	/* INT2 interrupts */
	{ .reg_offset = 1, .mask = RT8973A_INT2_UVLOT_MASK,},
	{ .reg_offset = 1, .mask = RT8973A_INT2_POR_MASK, },
	{ .reg_offset = 1, .mask = RT8973A_INT2_OTP_FET_MASK, },
	{ .reg_offset = 1, .mask = RT8973A_INT2_OVP_FET_MASK, },
	{ .reg_offset = 1, .mask = RT8973A_INT2_OCP_LATCH_MASK, },
	{ .reg_offset = 1, .mask = RT8973A_INT2_OCP_MASK, },
	{ .reg_offset = 1, .mask = RT8973A_INT2_OVP_OCP_MASK, },
};

static const struct regmap_irq_chip rt8973a_muic_irq_chip = {
	.name			= "rt8973a",
	.status_base		= RT8973A_REG_INT1,
	.mask_base		= RT8973A_REG_INTM1,
	.mask_invert		= false,
	.num_regs		= 2,
	.irqs			= rt8973a_irqs,
	.num_irqs		= ARRAY_SIZE(rt8973a_irqs),
};

/* Define regmap configuration of RT8973A for I2C communication  */
static bool rt8973a_muic_volatile_reg(struct device *dev, unsigned int reg)
{
	switch (reg) {
	case RT8973A_REG_INTM1:
	case RT8973A_REG_INTM2:
		return true;
	default:
		break;
	}
	return false;
}

static const struct regmap_config rt8973a_muic_regmap_config = {
	.reg_bits	= 8,
	.val_bits	= 8,