Lines Matching +full:ast2400 +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0-or-later
9 #include <linux/gpio/consumer.h>
11 #include <linux/hwmon-sysfs.h>
47 /* ASPEED_PTCR_CTRL : 0x00 - General Control Register */
74 /* ASPEED_PTCR_CLK_CTRL : 0x04 - Clock Control Register */
87 * ASPEED_PTCR_DUTY_CTRL/1/2/3 : 0x08/0x0C/0x48/0x4C - PWM-FAN duty control
97 /* ASPEED_PTCR_TYPEM_CTRL : 0x10/0x18/0x50 - Type M/N/O Ctrl 0 Register */
105 /* ASPEED_PTCR_TACH_SOURCE : 0x20/0x60 - Tach Source Register */
112 /* ASPEED_PTCR_RESULT : 0x2c - Result Register */
116 /* ASPEED_PTCR_CTRL_EXT : 0x40 - General Control Extension #1 Register */
138 /* ASPEED_PTCR_CLK_EXT_CTRL : 0x44 - Clock Control Extension #1 Register */
487 period = priv->type_pwm_clock_unit[priv->pwm_port_type[index]]; in aspeed_set_pwm_port_fan_ctrl()
492 aspeed_set_pwm_port_enable(priv->regmap, index, false); in aspeed_set_pwm_port_fan_ctrl()
497 aspeed_set_pwm_port_duty_rising_falling(priv->regmap, index, 0, in aspeed_set_pwm_port_fan_ctrl()
499 aspeed_set_pwm_port_enable(priv->regmap, index, true); in aspeed_set_pwm_port_fan_ctrl()
510 clk = priv->clk_freq; in aspeed_get_fan_tach_ch_measure_period()
511 clk_unit = priv->type_pwm_clock_unit[type]; in aspeed_get_fan_tach_ch_measure_period()
512 div_h = priv->type_pwm_clock_division_h[type]; in aspeed_get_fan_tach_ch_measure_period()
514 div_l = priv->type_pwm_clock_division_l[type]; in aspeed_get_fan_tach_ch_measure_period()
520 tacho_unit = priv->type_fan_tach_unit[type]; in aspeed_get_fan_tach_ch_measure_period()
521 tacho_div = priv->type_fan_tach_clock_division[type]; in aspeed_get_fan_tach_ch_measure_period()
534 mutex_lock(&priv->tach_lock); in aspeed_get_fan_tach_ch_rpm()
536 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0); in aspeed_get_fan_tach_ch_rpm()
537 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch); in aspeed_get_fan_tach_ch_rpm()
539 fan_tach_ch_source = priv->fan_tach_ch_source[fan_tach_ch]; in aspeed_get_fan_tach_ch_rpm()
540 type = priv->pwm_port_type[fan_tach_ch_source]; in aspeed_get_fan_tach_ch_rpm()
546 priv->regmap, in aspeed_get_fan_tach_ch_rpm()
553 mutex_unlock(&priv->tach_lock); in aspeed_get_fan_tach_ch_rpm()
555 /* return -ETIMEDOUT if we didn't get an answer. */ in aspeed_get_fan_tach_ch_rpm()
560 tach_div = priv->type_fan_tach_clock_division[type]; in aspeed_get_fan_tach_ch_rpm()
565 mode = priv->type_fan_tach_mode[type]; in aspeed_get_fan_tach_ch_rpm()
569 clk_source = priv->clk_freq; in aspeed_get_fan_tach_ch_rpm()
581 int index = sensor_attr->index; in pwm_store()
591 return -EINVAL; in pwm_store()
593 if (priv->pwm_port_fan_ctrl[index] == fan_ctrl) in pwm_store()
596 priv->pwm_port_fan_ctrl[index] = fan_ctrl; in pwm_store()
606 int index = sensor_attr->index; in pwm_show()
609 return sprintf(buf, "%u\n", priv->pwm_port_fan_ctrl[index]); in pwm_show()
616 int index = sensor_attr->index; in rpm_show()
633 if (!priv->pwm_present[index]) in pwm_is_visible()
635 return a->mode; in pwm_is_visible()
644 if (!priv->fan_tach_present[index]) in fan_dev_is_visible()
646 return a->mode; in fan_dev_is_visible()
722 priv->type_pwm_clock_division_h[TYPEM] = M_PWM_DIV_H; in aspeed_create_type()
723 priv->type_pwm_clock_division_l[TYPEM] = M_PWM_DIV_L; in aspeed_create_type()
724 priv->type_pwm_clock_unit[TYPEM] = M_PWM_PERIOD; in aspeed_create_type()
725 aspeed_set_pwm_clock_values(priv->regmap, TYPEM, M_PWM_DIV_H, in aspeed_create_type()
727 aspeed_set_tacho_type_enable(priv->regmap, TYPEM, true); in aspeed_create_type()
728 priv->type_fan_tach_clock_division[TYPEM] = M_TACH_CLK_DIV; in aspeed_create_type()
729 priv->type_fan_tach_unit[TYPEM] = M_TACH_UNIT; in aspeed_create_type()
730 priv->type_fan_tach_mode[TYPEM] = M_TACH_MODE; in aspeed_create_type()
731 aspeed_set_tacho_type_values(priv->regmap, TYPEM, M_TACH_MODE, in aspeed_create_type()
738 aspeed_set_pwm_port_enable(priv->regmap, pwm_port, true); in aspeed_create_pwm_port()
739 priv->pwm_present[pwm_port] = true; in aspeed_create_pwm_port()
741 priv->pwm_port_type[pwm_port] = TYPEM; in aspeed_create_pwm_port()
742 aspeed_set_pwm_port_type(priv->regmap, pwm_port, TYPEM); in aspeed_create_pwm_port()
744 priv->pwm_port_fan_ctrl[pwm_port] = INIT_FAN_CTRL; in aspeed_create_pwm_port()
760 return -EINVAL; in aspeed_create_fan_tach_channel()
762 aspeed_set_fan_tach_ch_enable(priv->regmap, index, true); in aspeed_create_fan_tach_channel()
763 priv->fan_tach_present[index] = true; in aspeed_create_fan_tach_channel()
764 priv->fan_tach_ch_source[index] = pwm_source; in aspeed_create_fan_tach_channel()
765 aspeed_set_fan_tach_ch_source(priv->regmap, index, pwm_source); in aspeed_create_fan_tach_channel()
775 struct aspeed_cooling_device *cdev = tcdev->devdata; in aspeed_pwm_cz_get_max_state()
777 *state = cdev->max_state; in aspeed_pwm_cz_get_max_state()
786 struct aspeed_cooling_device *cdev = tcdev->devdata; in aspeed_pwm_cz_get_cur_state()
788 *state = cdev->cur_state; in aspeed_pwm_cz_get_cur_state()
797 struct aspeed_cooling_device *cdev = tcdev->devdata; in aspeed_pwm_cz_set_cur_state()
799 if (state > cdev->max_state) in aspeed_pwm_cz_set_cur_state()
800 return -EINVAL; in aspeed_pwm_cz_set_cur_state()
802 cdev->cur_state = state; in aspeed_pwm_cz_set_cur_state()
803 cdev->priv->pwm_port_fan_ctrl[cdev->pwm_port] = in aspeed_pwm_cz_set_cur_state()
804 cdev->cooling_levels[cdev->cur_state]; in aspeed_pwm_cz_set_cur_state()
805 aspeed_set_pwm_port_fan_ctrl(cdev->priv, cdev->pwm_port, in aspeed_pwm_cz_set_cur_state()
806 cdev->cooling_levels[cdev->cur_state]); in aspeed_pwm_cz_set_cur_state()
828 return -ENOMEM; in aspeed_create_pwm_cooling()
830 cdev->cooling_levels = devm_kzalloc(dev, num_levels, GFP_KERNEL); in aspeed_create_pwm_cooling()
831 if (!cdev->cooling_levels) in aspeed_create_pwm_cooling()
832 return -ENOMEM; in aspeed_create_pwm_cooling()
834 cdev->max_state = num_levels - 1; in aspeed_create_pwm_cooling()
835 ret = of_property_read_u8_array(child, "cooling-levels", in aspeed_create_pwm_cooling()
836 cdev->cooling_levels, in aspeed_create_pwm_cooling()
839 dev_err(dev, "Property 'cooling-levels' cannot be read.\n"); in aspeed_create_pwm_cooling()
842 snprintf(cdev->name, MAX_CDEV_NAME_LEN, "%pOFn%d", child, pwm_port); in aspeed_create_pwm_cooling()
844 cdev->tcdev = devm_thermal_of_cooling_device_register(dev, child, in aspeed_create_pwm_cooling()
845 cdev->name, cdev, &aspeed_pwm_cool_ops); in aspeed_create_pwm_cooling()
846 if (IS_ERR(cdev->tcdev)) in aspeed_create_pwm_cooling()
847 return PTR_ERR(cdev->tcdev); in aspeed_create_pwm_cooling()
849 cdev->priv = priv; in aspeed_create_pwm_cooling()
850 cdev->pwm_port = pwm_port; in aspeed_create_pwm_cooling()
852 priv->cdev[pwm_port] = cdev; in aspeed_create_pwm_cooling()
869 return -EINVAL; in aspeed_create_fan()
872 ret = of_property_count_u8_elems(child, "cooling-levels"); in aspeed_create_fan()
881 count = of_property_count_u8_elems(child, "aspeed,fan-tach-ch"); in aspeed_create_fan()
883 return -EINVAL; in aspeed_create_fan()
887 return -ENOMEM; in aspeed_create_fan()
888 ret = of_property_read_u8_array(child, "aspeed,fan-tach-ch", in aspeed_create_fan()
904 reset_control_assert(priv->rst); in aspeed_pwm_tacho_remove()
909 struct device *dev = &pdev->dev; in aspeed_pwm_tacho_probe()
917 np = dev->of_node; in aspeed_pwm_tacho_probe()
923 return -ENOMEM; in aspeed_pwm_tacho_probe()
924 mutex_init(&priv->tach_lock); in aspeed_pwm_tacho_probe()
925 priv->regmap = devm_regmap_init(dev, NULL, (__force void *)regs, in aspeed_pwm_tacho_probe()
927 if (IS_ERR(priv->regmap)) in aspeed_pwm_tacho_probe()
928 return PTR_ERR(priv->regmap); in aspeed_pwm_tacho_probe()
930 priv->rst = devm_reset_control_get_exclusive(dev, NULL); in aspeed_pwm_tacho_probe()
931 if (IS_ERR(priv->rst)) { in aspeed_pwm_tacho_probe()
934 return PTR_ERR(priv->rst); in aspeed_pwm_tacho_probe()
936 reset_control_deassert(priv->rst); in aspeed_pwm_tacho_probe()
942 regmap_write(priv->regmap, ASPEED_PTCR_TACH_SOURCE, 0); in aspeed_pwm_tacho_probe()
943 regmap_write(priv->regmap, ASPEED_PTCR_TACH_SOURCE_EXT, 0); in aspeed_pwm_tacho_probe()
947 return -ENODEV; in aspeed_pwm_tacho_probe()
948 priv->clk_freq = clk_get_rate(clk); in aspeed_pwm_tacho_probe()
949 aspeed_set_clock_enable(priv->regmap, true); in aspeed_pwm_tacho_probe()
950 aspeed_set_clock_source(priv->regmap, 0); in aspeed_pwm_tacho_probe()
960 priv->groups[0] = &pwm_dev_group; in aspeed_pwm_tacho_probe()
961 priv->groups[1] = &fan_dev_group; in aspeed_pwm_tacho_probe()
962 priv->groups[2] = NULL; in aspeed_pwm_tacho_probe()
965 priv, priv->groups); in aspeed_pwm_tacho_probe()
970 { .compatible = "aspeed,ast2400-pwm-tacho", },
971 { .compatible = "aspeed,ast2500-pwm-tacho", },