diff options
author | Andrew McRae <amcrae@google.com> | 2021-12-22 13:08:23 +1100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-12-22 07:44:42 +0000 |
commit | 7b93b64122ee3d73689eb5f8621d173ea92936ea (patch) | |
tree | dbec1b62ca749507276a90e68936372bc1474c1d | |
parent | 5656dcd4891cd2388066c6dcd81319c20cbfdbd1 (diff) | |
download | chrome-ec-7b93b64122ee3d73689eb5f8621d173ea92936ea.tar.gz |
pinmap: Fix PWM generation
Add PWM_INVERT for inverted PWM signals.
Add channel number to pwm config.
BUG=b:211697223
TEST=zmake configure -b nivviks; go test ./...
BRANCH=none
Signed-off-by: Andrew McRae <amcrae@google.com>
Change-Id: I31d8d2305a7b6144f1b84eede688e4118b5d7870
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3353044
Reviewed-by: Eizan Miyamoto <eizan@chromium.org>
-rw-r--r-- | util/pinmap/chips/it81302.go | 2 | ||||
-rw-r--r-- | util/pinmap/chips/npcx993.go | 6 | ||||
-rw-r--r-- | util/pinmap/chips/npcx993_test.go | 4 | ||||
-rw-r--r-- | util/pinmap/pm/generate.go | 10 | ||||
-rw-r--r-- | util/pinmap/pm/generate_test.go | 8 | ||||
-rw-r--r-- | util/pinmap/pm/pins.go | 1 | ||||
-rw-r--r-- | util/pinmap/readers/csv/csv.go | 3 | ||||
-rw-r--r-- | util/pinmap/readers/csv/csv_test.go | 1 | ||||
-rw-r--r-- | util/pinmap/readers/csv/testdata/data.csv | 1 |
9 files changed, 27 insertions, 9 deletions
diff --git a/util/pinmap/chips/it81302.go b/util/pinmap/chips/it81302.go index 1a2d530ad5..fef82df49b 100644 --- a/util/pinmap/chips/it81302.go +++ b/util/pinmap/chips/it81302.go @@ -233,7 +233,7 @@ func (c *It81302) Pwm(p string) string { if strings.HasPrefix(ss, "PWM") && len(ss) > 3 { pwm := fmt.Sprintf("pwm%s", ss[3:]) c.okay = append(c.okay, pwm) - return fmt.Sprintf("%s %s 0", pwm, ss[3:]) + return fmt.Sprintf("%s %s", pwm, ss[3:]) } } return "" diff --git a/util/pinmap/chips/npcx993.go b/util/pinmap/chips/npcx993.go index 60d1487b5e..88639232dc 100644 --- a/util/pinmap/chips/npcx993.go +++ b/util/pinmap/chips/npcx993.go @@ -227,9 +227,9 @@ func (c *Npcx993) Pwm(p string) string { // Found the pin, now find the PWM name. for _, ss := range strings.Split(s, ",") { if strings.HasPrefix(ss, "PWM") && len(ss) > 3 { - pwm := fmt.Sprintf("pwm%s 0 0", ss[3:]) - c.okay = append(c.okay, pwm) - return pwm + ch := ss[3:] + c.okay = append(c.okay, fmt.Sprintf("pwm%s", ch)) + return fmt.Sprintf("pwm%s %s", ch, ch) } } return "" diff --git a/util/pinmap/chips/npcx993_test.go b/util/pinmap/chips/npcx993_test.go index 13307e4f0b..572e2a0f5a 100644 --- a/util/pinmap/chips/npcx993_test.go +++ b/util/pinmap/chips/npcx993_test.go @@ -57,8 +57,8 @@ func TestMulti(t *testing.T) { t.Errorf("Expected empty string, got %s for I2c()", n.I2c(pin)) } pin = "L9" - if n.Pwm(pin) != "pwm4 0 0" { - t.Errorf("Expected \"pwm4 0 0\", got %s for Pwm()", n.Pwm(pin)) + if n.Pwm(pin) != "pwm4 4" { + t.Errorf("Expected \"pwm4 4\", got %s for Pwm()", n.Pwm(pin)) } pin = "F8" if n.I2c(pin) != "i2c3_0" { diff --git a/util/pinmap/pm/generate.go b/util/pinmap/pm/generate.go index 8931b199f8..1ee4050b56 100644 --- a/util/pinmap/pm/generate.go +++ b/util/pinmap/pm/generate.go @@ -143,9 +143,15 @@ func i2cConfig(out io.Writer, pin *Pin, chip Chip) { // pwmConfig is the handler for PWM pins. func pwmConfig(out io.Writer, pin *Pin, chip Chip) { - if pin.PinType != PWM { + var inv string + switch pin.PinType { + default: fmt.Printf("Unknown PWM type (%d) for pin %s, ignored\n", pin.PinType, pin.Pin) return + case PWM: + inv = "0" + case PWM_INVERT: + inv = "1" } c := chip.Pwm(pin.Pin) if len(c) == 0 { @@ -154,7 +160,7 @@ func pwmConfig(out io.Writer, pin *Pin, chip Chip) { } lc := strings.ToLower(pin.Signal) fmt.Fprintf(out, "\t\tpwm_%s: %s {\n", lc, lc) - fmt.Fprintf(out, "\t\t\tpwms = <&%s>;\n", c) + fmt.Fprintf(out, "\t\t\tpwms = <&%s %s>;\n", c, inv) fmt.Fprintf(out, "\t\t\tlabel = \"%s\";\n", pin.Signal) if len(pin.Enum) > 0 { fmt.Fprintf(out, "\t\t\tenum-name = \"%s\";\n", pin.Enum) diff --git a/util/pinmap/pm/generate_test.go b/util/pinmap/pm/generate_test.go index 06d6dea91a..1e95156d2e 100644 --- a/util/pinmap/pm/generate_test.go +++ b/util/pinmap/pm/generate_test.go @@ -55,6 +55,7 @@ func TestGenerate(t *testing.T) { }, Pwm: []*pm.Pin{ &pm.Pin{pm.PWM, "E5", "EC_LED_1", "ENUM_LED_1"}, + &pm.Pin{pm.PWM_INVERT, "F6", "EC_LED_2", "ENUM_LED_2"}, }, } var out bytes.Buffer @@ -112,10 +113,15 @@ func TestGenerate(t *testing.T) { compatible = "named-pwms"; pwm_ec_led_1: ec_led_1 { - pwms = <&pwm1>; + pwms = <&pwm1 0>; label = "EC_LED_1"; enum-name = "ENUM_LED_1"; }; + pwm_ec_led_2: ec_led_2 { + pwms = <&pwm1 1>; + label = "EC_LED_2"; + enum-name = "ENUM_LED_2"; + }; }; }; diff --git a/util/pinmap/pm/pins.go b/util/pinmap/pm/pins.go index 771d7162b2..9c8b13589d 100644 --- a/util/pinmap/pm/pins.go +++ b/util/pinmap/pm/pins.go @@ -8,6 +8,7 @@ package pm const ( ADC = iota PWM + PWM_INVERT I2C Input Output diff --git a/util/pinmap/readers/csv/csv.go b/util/pinmap/readers/csv/csv.go index 96430d3c9d..47ef73295e 100644 --- a/util/pinmap/readers/csv/csv.go +++ b/util/pinmap/readers/csv/csv.go @@ -80,6 +80,9 @@ func (r *CSVReader) Read(chipName, arg string) (*pm.Pins, error) { case "PWM": p.PinType = pm.PWM pins.Pwm = append(pins.Pwm, p) + case "PWM_INVERT": + p.PinType = pm.PWM_INVERT + pins.Pwm = append(pins.Pwm, p) case "I2C_DATA": // Only the clock pin is used for the config continue diff --git a/util/pinmap/readers/csv/csv_test.go b/util/pinmap/readers/csv/csv_test.go index 266c5274d0..9f204848a3 100644 --- a/util/pinmap/readers/csv/csv_test.go +++ b/util/pinmap/readers/csv/csv_test.go @@ -39,6 +39,7 @@ func TestName(t *testing.T) { }, Pwm: []*pm.Pin{ &pm.Pin{pm.PWM, "C3", "EC_PWM_1", "FAN_1"}, + &pm.Pin{pm.PWM_INVERT, "J9", "EC_PWM_2", "LED_1"}, }, } check(t, "ADc", exp.Adc, pins.Adc) diff --git a/util/pinmap/readers/csv/testdata/data.csv b/util/pinmap/readers/csv/testdata/data.csv index d68006800f..c7200e1431 100644 --- a/util/pinmap/readers/csv/testdata/data.csv +++ b/util/pinmap/readers/csv/testdata/data.csv @@ -2,6 +2,7 @@ Signal Name,MyCHIP,Type,Enum EC_ADC_1,A1,ADC,ENUM_ADC_1 EC_IGNORED_1,B2,OTHER, EC_PWM_1,C3,PWM,FAN_1 +EC_PWM_2,J9,PWM_INVERT,LED_1 EC_GPIO_1,D4,INPUT,GPIO1 EC_GPIO_2,E5,OUTPUT,GPIO2 EC_GPIO_3,F6,OUTPUT_ODL, |